NaN's (was Re: FLOATING NULL?)

Henry Spencer henry at zoo.toronto.edu
Sun Jun 2 07:43:47 AEST 1991


In article <14 at tdatirv.UUCP> sarima at tdatirv.UUCP (Stanley Friesen) writes:
>>... there is a standard way of testing for NaN.
>>If x is a floating point variable, then (x != x) ...
>
>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.

But not under the IEEE FP standard.  Compilers need to be *very* careful
about optimizing floating-point operations if they are to provide a fully
IEEE-conforming environment.  A good many seemingly-innocuous operations
run into trouble.  It is simply a fact that in IEEE floating point, x!=x
is sometimes true, and optimizing it to `false' is a compiler bug.
-- 
"We're thinking about upgrading from    | Henry Spencer @ U of Toronto Zoology
SunOS 4.1.1 to SunOS 3.5."              |  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.lang.c mailing list