home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / compiler / 1895 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.8 KB  |  50 lines

  1. Newsgroups: comp.compilers
  2. Path: sparky!uunet!usc!sol.ctr.columbia.edu!eff!world!iecc!compilers-sender
  3. From: eggert@twinsun.com (Paul Eggert)
  4. Subject: Re: IEEE arithmetic handling
  5. Reply-To: eggert@twinsun.com (Paul Eggert)
  6. Organization: Twin Sun, Inc
  7. Date: Mon, 16 Nov 1992 20:19:55 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <92-11-086@comp.compilers>
  10. References: <92-11-041@comp.compilers> <92-11-079@comp.compilers>
  11. Keywords: arithmetic, design
  12. Sender: compilers-sender@iecc.cambridge.ma.us
  13. Lines: 35
  14.  
  15. jim@meiko.co.uk (James Cownie) writes:
  16.  
  17.    (I've never seen this handled right in an optimising compilation),
  18.  
  19.        IF (X .ne. X) THEN
  20.            print *,'X is a NaN'
  21.        ELSE
  22.            print *,'X is a number'
  23.        ENDIF
  24.  
  25. GCC 2.3.1 (sparc, -O2) handles this right, for C at least.  For example,
  26.  
  27.     int is_NaN(x) double x; { return x != x; }
  28.     int iszero(x) int    x; { return x != x; }
  29.  
  30. works as it should: isNaN contains a runtime test, whereas zero yields
  31. 0 without a test.  Is it really true that most Fortran compilers get
  32. this wrong?
  33.  
  34. tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
  35.  
  36.     An alternative approach ... is that it is an error to use the
  37.     usual language primitives for arithmetic with NaN's....  You
  38.     should have to use special IEEE primitives ("is_nan(x)",
  39.     "ieee_less(x,y)") to get at the IEEE meanings when available.
  40.  
  41. The IEEE floating point standard recommends that the user be able to
  42. request a trap whenever operations like .LT. are applied to NaNs, so
  43. for operations like .LT., Breuel's ``alternative approach'' should
  44. simply be a matter of enabling a trap handler.  However, .EQ. and .NE.
  45. never trap, so (contra Breuel) Cownie's example still works even if
  46. traps are enabled.  See IEEE Std 754-1985, page 13, table 4.
  47. -- 
  48. Send compilers articles to compilers@iecc.cambridge.ma.us or
  49. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  50.