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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d402aef7676f64a5 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 13 Dec 2006 21:13:21 +0100 From: Gautier User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Comparing Floating Point Values References: <1166026474.277616.267400@f1g2000cwa.googlegroups.com> In-Reply-To: <1166026474.277616.267400@f1g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 81.62.178.184 X-Original-NNTP-Posting-Host: 81.62.178.184 Message-ID: <45805ec5$1_5@news.bluewin.ch> X-Trace: news.bluewin.ch 1166040773 81.62.178.184 (13 Dec 2006 21:12:53 +0100) Organization: Bluewin AG Complaints-To: abuse@bluewin.ch X-Original-NNTP-Posting-Host: 127.0.0.1 Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!news-zh.switch.ch!switch.ch!news.ip-plus.net!newsfeed.ip-plus.net!news.bluewin.ch!not-for-mail Xref: g2news2.google.com comp.lang.ada:7909 Date: 2006-12-13T21:13:21+01:00 List-Id: markp wrote: > I was wondering if there was a convention for comparing 2 floats > dealing with significant digits. For example, if I had 2 variables (x > and y) and wanted to see if they were equal in an if statement, is > there a standard way to do a compare based on "x" significant digits? > > Thank you. Probably you are looking at something like abs(x-y) < 10**(-n) where n is your amount of digits (not "x" !). This is an absolute test, you may rather be interested by a relative one. BTW, it's worth to take a look at... Ada 95 Quality and Style Guide, 7.2.7: http://www.adaic.com/docs/95style/html/sec_7/7-2-7.html HTH ______________________________________________________________ Gautier -- http://www.mysunrise.ch/users/gdm/index.htm Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm NB: For a direct answer, e-mail address on the Web site!