[squeak-dev] a==b "true" but a=b "false"
trygver at ifi.uio.no
Fri Sep 5 08:27:39 UTC 2014
Old Fortran wisdom from the stone age:
/never test Floats for equality/
A Float is an approximation; there are an infinite number of values that
yield the same Float. Calculations with Floats are likely to introduce
rounding errors. Always test Floats for equality within a tolerance.
Float nan = Float nan is just one of the many tests that are meaningless
in practical programming.
On 04.09.2014 21:33, Eliot Miranda wrote:
> On Wed, Sep 3, 2014 at 4:11 PM, Chris Muller <ma.chris.m at gmail.com
> <mailto:ma.chris.m at gmail.com>> wrote:
> When could it happen?
> A: With Float nan.
> Float nan == Float nan "true"
> Float nan = Float nan "false"
> It violates what I have long considered an invariant that if a==b,
> then a=b.
> Real world context: When two DB clients change the same object in the
> exact same way, it's not a conflict. If they change it differently,
> it is.
> They've both made the same reference to Float nan, but just asking if
> they made equivalent changes still reports false. So I have to put in
> a complicated special check for NaN first..??
> Okay, I actually wrote: (a==b or: [a=b]) but who would ever write
> that or not "simplify it" in teh future if they saw it?
> Comments? Why shouldn't Float nan = Float nan?
> Because non-a-numbers result from overflowing or underflowing
> computations, and hence, just because two computations produce the
> same not-a-number doesn't imply that the two computations are
> equivalent. This is why the IEEE-754 standard requires that NaN != NaN.
Trygve Reenskaug mailto: trygver at ifi.uio.no
Morgedalsvn. 5A http://folk.uio.no/trygver/
N-0378 Oslo http://fullOO.info
Norway Tel: (+47) 22 49 57 27
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev