Float question

nicolas cellier ncellier at ifrance.com
Mon Oct 8 20:06:57 UTC 2007


Bert Freudenberg a écrit :
> On Oct 7, 2007, at 1:35 , Ralph Johnson wrote:
> 
>> "Float nan = Float nan" is false.   Is it supposed to be false?  I
>> suppoes the rule could be that NaN is not equal to anything, even
>> itself.
> 
> Correct. That's what IEEE specifies IIRC.
> 
>> "Float nan == Float nan" is true.
> 
> It's the same object.
> 
> Is this causing problems anywhere?
> 
> - Bert -
> 
> 
> 
> 

Testing Float nan == Float nan does answer true.
It rely on the fact that Float nan is a constant ^NaN.

But has this any usefull meaning?

I mean, is this really a deliberated feature, or just a side effect of 
current implementation?

I tend to interpret it a side effect, because most operations will 
produce a NaN which is ~~ Float nan:

(0.0 ln / 0.0 ln) == Float nan. "is false"
(0.0 ln / 0.0 ln) isNan/ "is true'

So, the Float tests just assert that implementation is what it is, which 
must absolutely NOT be interpreted by user as a feature.
This test just forbid implementation to change, which is arbitrary and 
useless.
User should never use test == Float nan. It might be true sometimes 
(when coming from Float nan or Number readFrom: 'NaN'), wrong most times.
He (she) should use isNan. That's what the test should emphasize as a 
feature.

Nicolas




More information about the Squeak-dev mailing list