Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: NaN's (was Re: FLOATING NULL?) Message-ID: <1991Jun1.214347.11696@zoo.toronto.edu> Date: Sat, 1 Jun 1991 21:43:47 GMT References: <13223@uhccux.uhcc.Hawaii.Edu> <1991May28.153655.24199@zoo.toronto.edu> <2726@root44.co.uk> <14@tdatirv.UUCP> Organization: U of Toronto Zoology In article <14@tdatirv.UUCP> sarima@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@zoo.toronto.edu utzoo!henry