home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / fortran / 4272 < prev    next >
Encoding:
Text File  |  1992-11-11  |  2.7 KB  |  77 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!noc.near.net!meiko.com!jim
  3. From: jim@meiko.co.uk (James Cownie)
  4. Subject: IEEE arithmetic [was Re: unformatted output]
  5. Message-ID: <1992Nov11.102611.5464@meiko.com>
  6. Followup-To: jim@meiko.co.uk
  7. Sender: jim@canopus (James Cownie)
  8. Organization: meiko
  9. References: <33492@adm.brl.mil> <Bx5IM3.9nF@news.cso.uiuc.edu> <Bx5s1u.C0J@pgroup.com> <KHB.92Nov3190132@chiba.Eng.Sun.COM> <18290@ksr.com> <1992Nov10.192736.22118@newshost.lanl.gov>
  10. Date: Wed, 11 Nov 1992 10:26:11 GMT
  11. Lines: 64
  12.  
  13. In article comp.lang.fortran <1992Nov10.192736.22118@newshost.lanl.gov>,
  14. jlg@cochiti.lanl.gov (J. Giles) writes:
  15.  
  16. |> Unfortunately, the Fortran standard does not conform to
  17. |> IEEE (in fact, it conflicts with it in some places - like with regard
  18. |> to negative zero).  And the Fortran standard does not require the same
  19. |> conversion accuracy as the IEEE floating point standard.  
  20.  
  21. This is a less significant difference than some of the others, in particular 
  22. Fortran definition of NINT and ANINT directly conflicts with the IEEE definitions
  23. of the same functions. 
  24.  
  25. The Fortran definition could be written as
  26.     INTEGER FUNCTION NINT(X)
  27.  
  28.     IF (X > 0.0) THEN
  29.        NINT = INT(X+0.5)
  30.         ELSE
  31.            NINT = INT(X-0.5)
  32.         ENDIF
  33.         END
  34.  
  35. IEEE (in round nearest mode, which is the default) specifies round even,
  36. so
  37.     IEEENINT(1.5) == 2.0  (as Fortran NINT)
  38. BUT     IEEENINT(2.5) == 2.0  (Fortran gives 3.0)
  39.  
  40. Another area where IEEE seems never to be implemented correctly by compilers
  41. is in the handling of Not a Numbers (NaNs). 
  42.  
  43. In the IEEE standard NaNs are values which can be encoded into a floating point
  44. variable, which represent the concept that it is not a reasonable number.
  45. (They are generated for operations such as sqrt(-ve), 0.0/0.0 etc.)
  46. IEEE specifies that a NaN is unordered with respect to anything else, 
  47. EVEN ITSELF. Therefore ALL comparisons involving floating variables MUST be 
  48. generated by the compiler WITHOUT introducing logical negation, since in the face 
  49. of NaNs (and their unordered relationship with other numbers)
  50.     
  51.     (.NOT. (X .LT. 2.0)) does NOT imply (X .GE 2.0)
  52.  
  53. (If X is a NaN (X .LT. 2.0) is FALSE (it's not less it's unordered),
  54.  but (X .GE. 2.0) is also FALSE (it's not greater equal it's unordered)).
  55.  
  56. Similarly (and I've never seen this handled right in an optimising compilation),
  57.  
  58.     IF (X .ne. X) THEN
  59.             print *,'X is a NaN'
  60.         ELSE
  61.             print *,'X is a number'
  62.         ENDIF
  63.  
  64. should generate code which has a run time test. 
  65.  
  66. -- Jim
  67. James Cownie             Normal disclaimers apply.
  68. Meiko Limited
  69. 650 Aztec West
  70. Bristol BS12 4SD
  71. England
  72.  
  73. Phone : +44 454 616171
  74. FAX   : +44 454 618188
  75. E-Mail: jim@meiko.co.uk or jim@meiko.com
  76.  
  77.