Not A Number in IEEE Math

Andrew Koenig ark at alice.UUCP
Thu Feb 22 05:07:26 AEST 1990


In article <14266 at s.ms.uky.edu>, simon at ms.uky.edu (G. Simon Gales) writes:

> I think that that behavior is correct.  

> 	0.0 * (anything) = 0.0
> and
> 	NaN / NaN = 1.0

Sorry, but that's not what IEEE says.

NaN is infinitely infectious.  That is: any operation that gives a
floating point result is supposed to return NaN if any of its operands
is NaN.  Relational operators all return `false' if either operand
is NaN.  Thus (x == x) is false if and only if x is NaN (unless,
of course, your implementation is broken).

Incidentally,

	0.0 * infinity = NaN (+ or - infinity -- I think it's implementation
		defined whether or not NaN has a sign)
	0.0 * NaN = NaN (as mentioned before)
	0.0 * anything else = 0.0

	NaN / NaN = NaN (as mentioned before)

	infinity / infinity = NaN
	infinity / NaN = Nan (as mentioned before)
	infinity / anything else = infinity
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list