From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109d8a,c7637cfdf68e766 X-Google-Attributes: gid109d8a,public X-Google-Thread: 107079,c7637cfdf68e766 X-Google-Attributes: gid107079,public X-Google-Thread: 103376,c7637cfdf68e766 X-Google-Attributes: gid103376,public X-Google-Thread: f8362,c7637cfdf68e766 X-Google-Attributes: gidf8362,public X-Google-Thread: f43e6,c7637cfdf68e766 X-Google-Attributes: gidf43e6,public From: fyodor@sally.nas.nasa.gov (Chris L. Kuszmaul) Subject: Re: floating point comparison Date: 1997/08/06 Message-ID: <5sar4r$t7m$1@cnn.nas.nasa.gov>#1/1 X-Deja-AN: 262657730 References: <33E61497.33E2@pseserv3.fw.hac.com> <33E6D359.3EF4@imbi.uni-freiburg.de> <33E74A62.53E2@pseserv3.fw.hac.com> Organization: NAS - NASA Ames Research Center, Moffett Field, CA Newsgroups: comp.lang.ada,sci.math.num-analysis,comp.software-eng,comp.theory,sci.math Date: 1997-08-06T00:00:00+00:00 List-Id: In article <33E74A62.53E2@pseserv3.fw.hac.com> "W. Wesley Groleau x4923" writes: > >What I'm trying to say is that it should be possible to come up with a >few simple guidelines that cover most cases, and a guideline for >identifying the cases that require a mathematician--excuse me, a >numerical analyst. > Fair enough. There are two basic guidlines I follow: 1: Do not test for equality between floating point values. If you do, then you better get a numerical analysit, or figure out how to avoid using floating point, or see if you can use a 'close to equal' check. 2: Watch out when you sum or difference floating point numbers of similar value. You can introduce arbitrarily large errors relative to the resulting value. ((a-b) - a) + b can turn up as equal to b if a is so much larger than b that subtracting it has no effect. Also 3: If you just do multiplication and division, then it is hard to mess up. CLK