[BUG] Float NaN's

Boris Gaertner Boris.Gaertner at gmx.net
Mon Sep 13 19:57:58 UTC 2004


 "Chris Muller" <afunkyobject at yahoo.com> wrote:
> Oops, I retyped the example in my email and should've cut and pasted.
Here is
> what I meant:
>
>   (Dictionary new at: Float nan put: 'nan'; yourself) printString
>
> Also, I'm interested in your commentary on the first example too..
>
>   (Set with: Float nan) includes: Float nan    "false"
>
> do you think these are bugs?
>

No, I think these are not bugs.
First, this has nothing to do with Sets and Dictionaries,
it is a property of Float.

First, try this:

  Float nan = Float nan

You obtain false. At first sight, this is a surprise, but it is possible
to defend this result with good reasons. Look at this:

1.0e200 tan = 1.0e200 tan

gives false and

  1.0e200 tan = 1.0e200 sin

gives also false.

This last example is the key to a better understanding
of the properties of NaNs. A NaN represents the result
of a computation that can not be represented as a
Float value. As we can certainly not say that
  1.0e200 sin   and  1.0e200 tan
are equal, it is best to assume that two
NaNs are never equal. (Database progammers
will remember similar rules for NULL values.
Two NULL values are never considered to be
equal, simply because the represent unknown
entities).

Form the Intel documentation of instruction
FCOm (Float COMpare)

>>If either operand is a NaN or is in an unsupported
>>format, an invalid-arithmeticoperand exception (#IA)
>>is raised and, if the exception is masked, the condition
>>flags are set to "unordered." If the invalid-arithmetic-
>>operand exception is unmasked, the condition code
>>flags are not set.


This means that NaNs are never considered to be
equal.

Note also that NaN is not represented by a
single bit pattern: There are a lot of different
representations of NaN: A NaN is an invalid
floating-point result that has all ones in the
exponent with a significand that is not all zeros.


Hope this helps,
Boris







More information about the Squeak-dev mailing list