home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Optimizers and (NaN != NaN) (was Re: How i
- Message-ID: <1992Sep15.165224.12489@taumet.com>
- Organization: TauMetric Corporation
- References: <1992Sep13.233629.25805@kronos.arc.nasa.gov> <1992Sep14.154648.17214@nrao.edu>
- Date: Tue, 15 Sep 1992 16:52:24 GMT
- Lines: 34
-
- cflatter@nrao.edu (Chris Flatters) writes:
-
- >In article 25805@kronos.arc.nasa.gov, raymond@kronos.arc.nasa.gov (Eric A. Raymond) writes:
- >>>including a NaN itself. So `if (x != x) printf("A NaN\n");' could do
- >>
- >>I tried this in one compiler and it didn't work. It is possible that
- >>the compiler optimized the test away. Is there any way to eliminate
- >>the optimization via a source hack?
-
- >Your compiler/hardware combination does not comply with IEEE-754. File
- >a bug report (or buy a better compiler).
-
- After a careful re-reading of 754, I'm not convinced it requires that
- (x!=x) hold for NaN's. NaN's must not compare equal, but that is not
- the same as saying they must compare unequal!
-
- IEEE-754 talks about "equal", "unequal", and "unordered". NaN's
- are "unordered", and it is unspecified (in 754 or the C Standard)
- whether the != operator in C includes "unordered".
-
- It seems to me, then, that the C expression (x!=x) could be either
- true or false for a NaN and still conform to 754. It is clear,
- however, that (x==x) must be false for NaN's. (I wonder how
- many compilers get that right.)
-
- IEEE-754 recommends that certain functions be provided to test for
- NaN's and other special cases. An implementation which claims 754
- conformance really should provide them (and many do). Check your
- manual for a function with a name like "isnan". That should be the
- most reliable way to test for a NaN.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-