comp.lang.ada
 help / color / mirror / Atom feed
From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: Comparing Floating Point Values
Date: 13 Dec 2006 08:45:25 -0800
Date: 2006-12-13T08:45:25-08:00	[thread overview]
Message-ID: <1166028325.672526.313220@j72g2000cwa.googlegroups.com> (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.

I don't do a lot of floating-point programming, so I don't know whether
there's a standard.  I would do something like

   if abs(x-y) <= epsilon * x then --- treat x and y as equal...

where epsilon is some suitable small constant or named number.  But
this really isn't my area of knowledge, and if someone else has a
different idea you should trust theirs rather than mine.  And I
wouldn't call this a "convention", which implies that this is sort of
like a "custom" that everyone agrees to follow; the correct value of
epsilon, and the correct way to compare, really depend on a
mathematical analysis of your particular problem.

                           -- Adam




  reply	other threads:[~2006-12-13 16:45 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 [this message]
2006-12-13 16:51 ` Ludovic Brenta
2006-12-13 20:02 ` Jeffrey R. Carter
2006-12-13 20:13 ` Gautier
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