Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!tut.cis.ohio-state.edu!att!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Floating point non-exactness Message-ID: <11160@alice.UUCP> Date: 7 Aug 90 22:47:41 GMT References: <622@.tetrauk.UUCP> <5467@quanta.eng.ohio-state.edu> <26691@nigel.ee.udel.edu> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 37 In article <26691@nigel.ee.udel.edu>, gdtltr@freezer.it.udel.edu (Gary Duzan) writes: > All practical applications aside, isn't it philosophically unnatural to > apply an eqivalence comparison to two floating point (presumably real) > numbers? Not if you're doing appropriate operations on a machine with IEEE floating point or some other good floating point system. For example, IEEE guarantees that if I read the decimal representation of a number that can be represented exactly in floating point, that's what I'll get, period. It also guarantees exact results for primitive operations including addition, subtraction, multiplication, division, and square root. Suppose, then that I want to do calculations on integers that are too big to fit in `int' values but small enough to be represented exactly in floating point. I see no reason not to do any comparison on floating point numbers that I would do on integers. As a simple example, double d; for (d = 0; d < 1e10; d++) { /* stuff */ } under IEEE floating point can be counted on to execute precisely 1e10 (ten billion) times. Yes, such techniques are not portable to machines with lousy floating point, but it might be that your program wouldn't run there anyway for some reason. As good floating point systems become more widespread, this becomes less of an issue. -- --Andrew Koenig ark@europa.att.com