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: f43e6,c7637cfdf68e766 X-Google-Attributes: gidf43e6,public X-Google-Thread: f8362,c7637cfdf68e766 X-Google-Attributes: gidf8362,public X-Google-Thread: 103376,c7637cfdf68e766 X-Google-Attributes: gid103376,public X-Google-Thread: 109d8a,c7637cfdf68e766 X-Google-Attributes: gid109d8a,public X-Google-Thread: 107079,c7637cfdf68e766 X-Google-Attributes: gid107079,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: floating point comparison Date: 1997/07/30 Message-ID: #1/1 X-Deja-AN: 260853807 References: Distribution: inet Organization: Estormza Software Newsgroups: comp.lang.ada,sci.math.num-analysis,comp.software-eng,comp.theory,sci.math Date: 1997-07-30T00:00:00+00:00 List-Id: In article , dewar@merv.cs.nyu.edu (Robert Dewar) wrote: Another question then. I was digging around deja news, and Bob Eachus responded to a similar query with the answer: > > So, How Do I Do It? > > First, don't. > > Second, if you must, implement your own equality operation that >allows for a small range of error: > > function Equal(L,R: Float) return Boolean is > begin > if L = R then return True; > elsif abs(L-R) < abs(R) * Float'Epsilon then return True; > else return False; > end if; > end Equal; > > (The first check is both for efficiency and to deal with the case >where L = R = 0.0...) > >-- > > Robert I. Eachus Why didn't he just say, "Compare them directly using the equality operator for the floating point type." Why did he bother writing the Equal function? -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271