[squeak-dev] Re: FloatTest >> testNaN5
Tim Olson
tim_olson at att.net
Thu Jul 30 13:29:34 UTC 2009
On Jul 30, 2009, at 6:44 AM, Michael Haupt wrote:
> Looking at IEEE 754, it seems that, for NaN, the following bit mask
> would be correct (x means any of 0 or 1):
> 'x111111111xxxxxxxxxxxxxxxxxxxxxx' - at least for a quiet
> (non-signalled) NaN.
Yes, that is correct.
>
> I suspect Squeak intentionally generates a quiet NaN.
Correct. It is generated by subtracting two Infinity values, which
generates the default quiet NaN as a result.
>
> Again, comments?
The canonical NaN value is generated in Float during class
initialization, by the following code:
MaxVal := 1.7976931348623159e308.
Infinity := MaxVal * MaxVal.
NaN := Infinity - Infinity.
The bit pattern for Infinity is defined by IEEE-754, but the spec only
defines NaN values as values with maximum exponent and non-zero
fraction (quiet NaN has most-significant fraction bit set, signaling
NaN has the most-significant fraction bit clear). So different
hardware implementations are free to generate different NaN values (as
long as the exponent is all ones and the fraction is non-zero). But
this should not be a problem, since any NaN value is treated as a NaN
-- so images with a particular NaN value work fine on systems that
would generate a different canonical NaN value. Also, in IEEE-754, a
NaN does not compare equal to any other value, including itself (which
is how Float>>isNaN works), so having different NaN values in the image
does not normally cause a problem. The only time it is visible is in
cases like the test you are pointing out.
I suggest modifying the test to take this into account (only test for
all-ones exponent and non-zero fraction), or remove that particular
test.
-- tim
More information about the Squeak-dev
mailing list
|