IEEE arithmetic handling (James Cownie)
Wed, 11 Nov 1992 10:31:40 GMT

          From comp.compilers

Related articles
IEEE arithmetic handling (1992-11-11)
Re: IEEE arithmetic handling (1992-11-16)
Re: IEEE arithmetic handling (1992-11-16)
Re: IEEE arithmetic handling (1992-11-16)
Re: IEEE arithmetic handling (1992-11-17)
Re: IEEE arithmetic handling (1992-11-17)
Re: IEEE arithmetic handling (1992-11-18)
[5 later articles]
| List of all articles for this month |

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

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

IF (X > 0.0) THEN
NINT = INT(X+0.5)
                      NINT = INT(X-0.5)

IEEE (in round nearest mode, which is the default) specifies round even,
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

(.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

IF (X .ne. X) THEN
                        print *,'X is a NaN'
                        print *,'X is a number'

should generate code which has a run time test.

-- Jim
James Cownie
Meiko Limited
650 Aztec West
Bristol BS12 4SD

Phone : +44 454 616171
FAX : +44 454 618188
E-Mail: or

Post a followup to this message

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