Xref: utzoo comp.compilers:1432 comp.lang.fortran:3996 Path: utzoo!attcan!uunet!bu.edu!husc6!spdcc!esegue!compilers-sender From: burley@world.std.com (James C Burley) Newsgroups: comp.compilers,comp.lang.fortran Subject: Re: IEEE 754 vs Fortran arithmetic Keywords: Fortran Message-ID: Date: 24 Oct 90 06:50:53 GMT References: <9010230628.AA22160@admin.ogi.edu> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: burley@world.std.com (James C Burley) Organization: The World Lines: 56 Approved: compilers@esegue.segue.boston.ma.us In-Reply-To: John Roberts's message of Mon, 22 Oct 90 23:28:24 -0700 In article <9010230628.AA22160@admin.ogi.edu> John Roberts 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] -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.