home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!noc.near.net!meiko.com!jim
- From: jim@meiko.co.uk (James Cownie)
- Subject: IEEE arithmetic [was Re: unformatted output]
- Message-ID: <1992Nov11.102611.5464@meiko.com>
- Followup-To: jim@meiko.co.uk
- Sender: jim@canopus (James Cownie)
- Organization: meiko
- 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>
- Date: Wed, 11 Nov 1992 10:26:11 GMT
- Lines: 64
-
- In article comp.lang.fortran <1992Nov10.192736.22118@newshost.lanl.gov>,
- jlg@cochiti.lanl.gov (J. Giles) writes:
-
- |> Unfortunately, the Fortran standard does not conform to
- |> IEEE (in fact, it conflicts with it in some places - like with regard
- |> to negative zero). And the Fortran standard does not require the same
- |> conversion accuracy as the IEEE floating point standard.
-
- This is a less significant difference than some of the others, in particular
- Fortran definition of NINT and ANINT directly conflicts with the IEEE definitions
- of the same functions.
-
- The Fortran definition could be written as
- INTEGER FUNCTION NINT(X)
-
- IF (X > 0.0) THEN
- NINT = INT(X+0.5)
- ELSE
- NINT = INT(X-0.5)
- ENDIF
- END
-
- IEEE (in round nearest mode, which is the default) specifies round even,
- so
- IEEENINT(1.5) == 2.0 (as Fortran NINT)
- BUT IEEENINT(2.5) == 2.0 (Fortran gives 3.0)
-
- Another area where IEEE seems never to be implemented correctly by compilers
- is in the handling of Not a Numbers (NaNs).
-
- In the IEEE standard NaNs are values which can be encoded into a floating point
- variable, which represent the concept that it is not a reasonable number.
- (They are generated for operations such as sqrt(-ve), 0.0/0.0 etc.)
- IEEE specifies that a NaN is unordered with respect to anything else,
- EVEN ITSELF. Therefore ALL comparisons involving floating variables MUST be
- generated by the compiler WITHOUT introducing logical negation, since in the face
- of NaNs (and their unordered relationship with other numbers)
-
- (.NOT. (X .LT. 2.0)) does NOT imply (X .GE 2.0)
-
- (If X is a NaN (X .LT. 2.0) is FALSE (it's not less it's unordered),
- but (X .GE. 2.0) is also FALSE (it's not greater equal it's unordered)).
-
- Similarly (and I've never seen this handled right in an optimising compilation),
-
- IF (X .ne. X) THEN
- print *,'X is a NaN'
- ELSE
- print *,'X is a number'
- ENDIF
-
- should generate code which has a run time test.
-
- -- Jim
- James Cownie Normal disclaimers apply.
- Meiko Limited
- 650 Aztec West
- Bristol BS12 4SD
- England
-
- Phone : +44 454 616171
- FAX : +44 454 618188
- E-Mail: jim@meiko.co.uk or jim@meiko.com
-
-