comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier <gautier@fakeaddress.nil>
Subject: Re: Comparing Floating Point Values
Date: Wed, 13 Dec 2006 21:13:21 +0100
Date: 2006-12-13T21:13:21+01:00	[thread overview]
Message-ID: <45805ec5$1_5@news.bluewin.ch> (raw)
In-Reply-To: <1166026474.277616.267400@f1g2000cwa.googlegroups.com>

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!



  parent reply	other threads:[~2006-12-13 20:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-13 16:14 Comparing Floating Point Values markp
2006-12-13 16:45 ` Adam Beneschan
2006-12-13 16:51 ` Ludovic Brenta
2006-12-13 20:02 ` Jeffrey R. Carter
2006-12-13 20:13 ` Gautier [this message]
2006-12-14  2:21 ` Steve
2006-12-14 22:22   ` Martin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox