Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.fortran Subject: Re: style--- REAL comparisons Message-ID: <3518@goanna.cs.rmit.oz.au> Date: 6 Aug 90 02:27:27 GMT References: <1990Aug4.173025.15920@ux1.cso.uiuc.edu> <3516@goanna.cs.rmit.oz.au> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 31 In article <3516@goanna.cs.rmit.oz.au>, ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: > In article <1990Aug4.173025.15920@ux1.cso.uiuc.edu>, mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes: > > I just thought of one good - very good - use of comparisons of > > [floating-point] variables for equality: > People who say NEVER compare floats for equality are being realistic. I forgot to mention another problem. Suppose you compile the subroutine with version 18.5 of your compiler, and then compile the main program that calls it with version 19.1. One of the reasons for the upgrade may be that the new version does a better version of converting floating-point literals... A Fortran compiler which claims to conform to the IEEE 754 and/or IEEE 854 standards must get literals like 0.5, 0.625, and so on right. But without that claim of conformance there is no guarantee. And in past times it just wasn't _possible_ to send the compiler back if it didn't get 0.5 exactly right; you often had the choice of the vendor's Fortran compiler or _none_. I have been seriously flamed for pointing out that McDonald's example is a good example of why comparing floats for equality is risky. If you are Herman Rubin, totally in control of the machine, then it is safe for you to compare floats for equality. (It wasn't he who flamed me, I merely cite him as the best known example of someone who might understand his machine well enough to get away with this kind of thing.) But if you expect your code to be portable, or if you haven't got a couple of years of numerical analysis under your hat, don't be silly. -- Distinguishing between a work written in Hebrew and one written in Aramaic when we have only a Latin version made from a Greek translation is not easy. (D.J.Harrington, discussing pseudo-Philo)