Re: Meaning of Double.Epsilon
cody <please_dont.sp am.deutronium@g mx.de> wrote:[color=blue][color=green][color=darkred]
> > > If the result is from a calculation, that's right. I believe that if
> > > it's from a constant, or if it's from a calculation which has an answer
> > > which can be exactly represented in the chosen data size, it's fine.[/color][/color]
>
> But in Jons example the calculation can be left can certainly out without
> altering the meaning the program because it compares the results of two same
> calculations using constants only.[/color]
The calculation *uses* constants, but the result of it isn't
expressable exactly in 64 bits. That's the difference - any constant is
basically defined to be "the 64-bit (or 32-bit in case of float) value
closest to what is literally specified". It would be an error (I
believe) for an enregistered variable to take a more accurate value.
[color=blue][color=green]
> > Constant are ok, but calculation results usually aren't safe:
> > Console.WriteLi ne(Math.Sqrt(2) *Math.Sqrt(2) == 2);
> > prints out false on my machine.[/color]
>
> I wouldn't have expected any other result than a random value from 'true'
> and 'false' :)
>
> I always have been thinking of floating point values as "fuzzy things" where
> the exact representation of the result of a calculation is not foreseeable.
> Maybe there are IEEE standards but who knows where some machines calculates
> floating point in their own way? I do not care as long as the result comes
> very close to the "real" exact result.[/color]
I believe the result of a particular calculation is and can be
foreseeable. The difficulty here isn't with the calculation, or even
*how* the result is truncated to 64 bits - it's *when* the result is
truncated.
[color=blue][color=green][color=darkred]
> > > I suspect it's very, very rarely a good idea to use == for comparisons
> > > with non-constants in the first place though.[/color]
> >
> > I'd definitely agree to that.[/color]
>
> Who wouldn't agree with that (except the microsoft guy who decided that
> operator== for fp do not need a compiler warning).[/color]
I'm in two minds about that, personally. I can see the argument for a
warning, but at the same time it feels odd.
--
Jon Skeet - <skeet@pobox.co m>
If replying to the group, please do not mail me too
cody <please_dont.sp am.deutronium@g mx.de> wrote:[color=blue][color=green][color=darkred]
> > > If the result is from a calculation, that's right. I believe that if
> > > it's from a constant, or if it's from a calculation which has an answer
> > > which can be exactly represented in the chosen data size, it's fine.[/color][/color]
>
> But in Jons example the calculation can be left can certainly out without
> altering the meaning the program because it compares the results of two same
> calculations using constants only.[/color]
The calculation *uses* constants, but the result of it isn't
expressable exactly in 64 bits. That's the difference - any constant is
basically defined to be "the 64-bit (or 32-bit in case of float) value
closest to what is literally specified". It would be an error (I
believe) for an enregistered variable to take a more accurate value.
[color=blue][color=green]
> > Constant are ok, but calculation results usually aren't safe:
> > Console.WriteLi ne(Math.Sqrt(2) *Math.Sqrt(2) == 2);
> > prints out false on my machine.[/color]
>
> I wouldn't have expected any other result than a random value from 'true'
> and 'false' :)
>
> I always have been thinking of floating point values as "fuzzy things" where
> the exact representation of the result of a calculation is not foreseeable.
> Maybe there are IEEE standards but who knows where some machines calculates
> floating point in their own way? I do not care as long as the result comes
> very close to the "real" exact result.[/color]
I believe the result of a particular calculation is and can be
foreseeable. The difficulty here isn't with the calculation, or even
*how* the result is truncated to 64 bits - it's *when* the result is
truncated.
[color=blue][color=green][color=darkred]
> > > I suspect it's very, very rarely a good idea to use == for comparisons
> > > with non-constants in the first place though.[/color]
> >
> > I'd definitely agree to that.[/color]
>
> Who wouldn't agree with that (except the microsoft guy who decided that
> operator== for fp do not need a compiler warning).[/color]
I'm in two minds about that, personally. I can see the argument for a
warning, but at the same time it feels odd.
--
Jon Skeet - <skeet@pobox.co m>
If replying to the group, please do not mail me too
Comment