home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13693 < prev    next >
Encoding:
Text File  |  1992-09-15  |  1.8 KB  |  45 lines

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