Re: IEEE 754 vs Fortran arithmetic

burley@world.std.com (James C Burley)
24 Oct 90 02:50:53

          From comp.compilers

Related articles
IEEE 754 vs Fortran arithmetic robertsj@admin.ogi.edu (John Roberts) (1990-10-22)
Re: IEEE 754 vs Fortran arithmetic burley@world.std.com (1990-10-24)
Re: IEEE 754 vs Fortran arithmetic henry@zoo.toronto.edu (1990-10-24)
Re: IEEE 754 vs Fortran arithmetic tim@ksr.com (Tim Peters) (1990-10-24)
Re: IEEE 754 vs Fortran arithmetic dik@cwi.nl (1990-10-25)
Re: IEEE 754 vs Fortran arithmetic wsb@eng.Sun.COM (1990-10-25)
Re: IEEE 754 vs Fortran arithmetic eggert@twinsun.com (1990-10-25)
Re: IEEE 754 vs Fortran arithmetic wsb@eng.Sun.COM (1990-10-25)
[5 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers,comp.lang.fortran
From: burley@world.std.com (James C Burley)
In-Reply-To: John Roberts's message of Mon, 22 Oct 90 23:28:24 -0700
Keywords: Fortran
Organization: The World
References: <9010230628.AA22160@admin.ogi.edu>
Date: 24 Oct 90 02:50:53

In article <9010230628.AA22160@admin.ogi.edu> John Roberts <robertsj@admin.ogi.edu> writes:


      Does anyone know of any references that compare or contrast IEEE 754
      floating point arithmetic with other standards, such as Fortran?


      [... I know of no reason that an IEEE implementation of F77 would be
      nonconforming. -John]


I don't know any references, but I do know we ran into this problem
implementing Fortran on a machine using an IEEE 754 math chip:


            REAL R(...)
            DATA R/0.5,1.5,2.5,3.5,.../
            DO I=1,...
                  PRINT *,NINT(R)
            END DO
            END


Fortran specifies that the following values must be output:


1, 2, 3, 4,...


However, the IEEE 754 defines nearest-integer so that using its function
instead of Fortran's definition of NINT produces:


0, 2, 2, 4,...


This is because Fortran literally specifies that NINT(X) is INT(X+0.5)
(assuming for convenience here that X>=0), while IEEE 754 specifies that
nearest-integer is to round to the nearest EVEN integer. (Perhaps it allows
alternatives -- my memory is vague here -- but those alternative have to do
with rounding to 0, infinity, and so on, and somehow I think they didn't come
into play with round-to-nearest-integer as a function and in any case there
didn't seem to be any rounding mode equivalent to Fortran's definition of
NINT.)


Also, Fortran specifically prohibits zero from being negative (or being
significantly negative -- for example, I think, given that X is 0.0 and Y is
-0.0, IEEE 754 specifies that (Y.LT.X) whereas Fortran specifies that
(Y.EQ.X)). I might be wrong about the specifics, but there is some issue
here even if I can't remember just what it is! (Love these definitive
pronouncements, don't y'all?! :-)


James Craig Burley, Software Craftsperson burley@world.std.com
[754 says that -0 and +0 are equal, but the point about NINT is good, one
can't implement NINT with a single instruction unless the rounding mode is
set to chop. -John]
--


Post a followup to this message

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