Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: comp.arch Subject: Re: IEEE arithmetic (Goldberg paper) Message-ID: <26594@as0c.sei.cmu.edu> Date: 6 Jun 91 11:53:31 GMT References: <9106052113.AA14439@ucbvax.Berkeley.EDU> Reply-To: firth@sei.cmu.edu (Robert Firth) Organization: Software Engineering Institute, Pittsburgh, PA Lines: 43 In article <9106052113.AA14439@ucbvax.Berkeley.EDU> jbs@WATSON.IBM.COM writes: Jim Dehnert said: > If I see a literal zero while compiling (the only >case I can think of when the compiler does anything that might care >about what 0*x equals), I feel quite free to assume that it is really >zero, in which case 0*x is really zero even for very large x. > Some people write: IF(0.D0*X.NE.0.D0)THEN >to detect infs or NaNs (see recent posts to comp.land.fortran). This >works on many systems. If you replace 0*x with 0 then it will not work >on your system and your system is broken. Well, as another compiler writer, I did what I always do when faced with a conumdrum such as this: refer to the standard. The relevant section in this case is [ANSI X3.9-1978 sect 6.6.4], which says, very simply: Evaluation of Arithmetic Expressions ... Once the interpretation has been established in accordance with these rules, the processor may evaluate any mathematically equivalent expression, provided that the integrity of parentheses is not violated. Two arithmetic expressions are mathematiccally equivalent if, for all possible values of their primaries, their mathematical values are equal. However, mathematically equivalent arithmetic expressions may produce different computational results. In otherwords: yes, Jim Dehnert is fully entitled to replace 0.0*X with the mathematically equivalent expression 0.0; he is given explicit licence to do so by the reference document, and anyone who writes rubbish like IF (0.0*X .NE. 0.0) would be well advised to take the trouble to learn the language in which he is attempting to write code.