NaN's (was Re: FLOATING NULL?)

Stanley Friesen sarima at tdatirv.UUCP
Sat Jun 1 05:23:13 AEST 1991


In article <2726 at root44.co.uk> gwc at root.co.uk (Geoff Clare) writes:
>I agree there is no standard way of generating NaN (although sqrt(-1.0)
>is your best bet).  However, there is a standard way of testing for NaN.
>If x is a floating point variable, then (x != x) will be TRUE if and
>only if x has the value NaN.

But what if the compiler notices you are asking for a self comparison and
optimizes it away?  Then this will fail unless x is volatile.

Since NaN's fall in the area of unspecified/undefined behavior I believe
that such an optimization is legal under the ANSI standard.
-- 
---------------
uunet!tdatirv!sarima				(Stanley Friesen)



More information about the Comp.lang.c mailing list