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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,37e5589e32d8f03f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news-xfer.newsread.com!yellow.newsread.com!netaxs.com!newsread.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Floating-Point Numbers and Internal Representation Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1843142.NoXPLYbHQs@linux1.krischik.com> Date: Sun, 4 Dec 2005 15:50:04 +0100 Message-ID: <4fnetd7d1gzw$.6esjklahq38$.dlg@40tude.net> NNTP-Posting-Date: 04 Dec 2005 15:50:03 MET NNTP-Posting-Host: 5988535a.newsread4.arcor-online.net X-Trace: DXC==k>WWNPnG>ja0B5i45NL;d:ejgIfPPlddjW\KbG]kaMhFYk:AnJB[CmC17_l3Fi;He[6LHn;2LCVn[ On Sun, 4 Dec 2005 14:11:49 +0000 (UTC), Martin Dowie wrote: > Martin Krischik wrote: >> Independent of CPU/Language used I would allways suggest to use >> >> abs (X - Y) < epsilon >> >> with a sufficient but not to small epsilon instead. > > Suggested reading: > > http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm > > There is more than one answer to this problem... Epsilon above can well be relative that depends solely on the algorithm. Usually epsilon is estimated in the course of calculations together with X and Y, as a part of the algorithm. So the answer is still same. (:-)) BTW, I wouldn't use division to evaluate relative errors as the paper suggest. Rather: Half_Epsilon * (abs X + abs Y) A really different answer would be interval arithmetic. If X and Y were intervals they would carry the accuracy estimation with them. So one could directly compare them: case X < Y or X > Y is -- The result is not Boolean! when False | Uncertain => -- The difference cannot be distinguished from accumulated -- inaccuracy when True => -- They are sufficiently different end case; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de