IEEE arithmetic handling

jim@meiko.co.uk (James Cownie)
Wed, 11 Nov 1992 10:31:40 GMT

          From comp.compilers

Related articles
IEEE arithmetic handling jim@meiko.co.uk (1992-11-11)
Re: IEEE arithmetic handling tmb@arolla.idiap.ch (1992-11-16)
Re: IEEE arithmetic handling eggert@twinsun.com (1992-11-16)
Re: IEEE arithmetic handling bill@amber.csd.harris.com (1992-11-16)
Re: IEEE arithmetic handling jlg@cochiti.lanl.gov (1992-11-17)
Re: IEEE arithmetic handling eggert@twinsun.com (1992-11-17)
Re: IEEE arithmetic handling tmb@arolla.idiap.ch (1992-11-18)
[5 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: jim@meiko.co.uk (James Cownie)
Organization: Compilers Central
Date: Wed, 11 Nov 1992 10:31:40 GMT
Keywords: arithmetic, question

In comp.lang.fortran 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
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
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.