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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8362,c7637cfdf68e766 X-Google-Attributes: gidf8362,public X-Google-Thread: 109d8a,c7637cfdf68e766 X-Google-Attributes: gid109d8a,public X-Google-Thread: 107079,c7637cfdf68e766 X-Google-Attributes: gid107079,public X-Google-Thread: f43e6,c7637cfdf68e766 X-Google-Attributes: gidf43e6,public X-Google-Thread: 103376,c7637cfdf68e766 X-Google-Attributes: gid103376,public From: Michael Sierchio Subject: Re: floating point comparison Date: 1997/08/02 Message-ID: <33E3848F.5B1@qanv.pbz>#1/1 X-Deja-AN: 261765835 References: Reply-To: xhqmh@qanv.pbz Organization: Oversized Metaphysics Newsgroups: comp.lang.ada,sci.math.num-analysis,comp.software-eng,comp.theory,sci.math Date: 1997-08-02T00:00:00+00:00 List-Id: Matthew Heaney wrote: > My immediate problem is, How do I test 2 floating point numbers for equality? Never test floating point numbers for equality! :-) > The AQ&S states that > > if abs (X - Y) <= Float_T'Small Numerical analysis is a fun discipline! For all you know, X and Y are equal, except that you used different methods to derive them, and they differ in one bit. Arrgh. Checking that they are within some epsilon is proper, but deciding upon that epsilon may be hard. There are multiple sources of error in a number: imprecision, so that roundoff error accumulates, and the measurement limits (in the case of a physical process) are big ones. The old physics/chem method of retaining a fixed number of significant figures is naive at best -- Interval arithmetic may help -- you may choose to decide that two fp nums are equal if their intervals overlap.