Xref: utzoo comp.compilers:1439 comp.lang.fortran:4000 Path: utzoo!attcan!uunet!bu.edu!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!ncar!husc6!spdcc!esegue!compilers-sender From: wsb@eng.Sun.COM (Walt Brainerd) Newsgroups: comp.compilers,comp.lang.fortran Subject: Re: IEEE 754 vs Fortran arithmetic Keywords: Fortran Message-ID: <144172@sun.Eng.Sun.COM> Date: 25 Oct 90 00:46:27 GMT References: <9010230628.AA22160@admin.ogi.edu> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: wsb@eng.Sun.COM (Walt Brainerd) Followup-To: comp.lang.fortran Organization: Compilers Central Lines: 52 Approved: compilers@esegue.segue.boston.ma.us In article , burley@world.std.com (James C Burley) writes: > > 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,... We have had this discussion before some here, but to be a bit nit-picking, "Fortran" (i.e., the standard) does not specify such things, as it does not even specify what + means. It certainly does encourage such things and a vendor must be prepared to answer to the customer, but not worry about strict standard conformace in this area. > > However, the IEEE 754 defines nearest-integer so that using its function > instead of Fortran's definition of NINT produces: > > 0, 2, 2, 4,... > > Also, Fortran specifically prohibits zero from being negative (or being > significantly negative The appendix (not a legal part of the standard) says: "A processor must not consider a negative zero to be different from a positive zero." I would take this as a SUGGESTION to make 0 and I-I compare true, however the result of the subtraction is represented. The standard (13.5.9) does say that a "negative signed zero" must not be produced when doing numeric output into a formatted record. So, from the point of view of the standard, printing 4-4 as 7 is OK, but printing it as -0 (with say an I2 format) is not! It's just a matter of who you run to if something doesn't work the way you think it should. -- Walt Brainerd Sun Microsystems, Inc. wsb@eng.sun.com MS MTV 5-40 Mountain View, CA 94043 415/336-5991 -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.