comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Mize <smize@link.com>
Subject: Re: floating point comparison
Date: 1997/07/31
Date: 1997-07-31T00:00:00+00:00	[thread overview]
Message-ID: <33E0EFFA.698E@link.com> (raw)
In-Reply-To: mheaney-ya023680003007972240570001@news.ni.net


[reformatted for line length]
Matthew Heaney wrote:
> 
> In article <dewar.870304869@merv>, dewar@merv.cs.nyu.edu (Robert Dewar) wrote:
> 
> >As for when it makes sense to compare floating-point values
> >for equality, that is a matter for the programmer to understand.
> >Floating-point arithmetic on modern IEEE machines is not some kind
> > of approximate hocus-pocus, it is a well defined arithmetic systenm,
> >with well defined, well behaved results, in which equality has a
> > perfectly reasonable meaning.
> 
> OK, so if  do this
> 
> declare
>    m1, m2 : slope;
> begin
>    if m1 = m2 then
> 
> and I'm using IEEE floating point types (I'm on a SUN box), can I assume
> that the lines are parallel?

IEEE float calculation is a well-defined arithmetic system, but it
does not always match exact real-number arithmetic.  You need to
read up in one or more of the references other people provided, to
determine how the differences impact your computations.

The short answer is that there is no short answer.

The longer short answer is that usually, the inaccuracy of the data
swamps the imprecision of discrete floating-point arithmetic.  If
you're measuring lengths under 10 yards to the nearest foot, it really
doesn't matter if you compute the rectangular area with 32 or 64 bits.
In this case, you might consider 10.01 and 9.09 equal.  If you're
measuring to the nearest inch, you might not.  In neither case are
you approaching the precision of the machine.

There are cases where the machine precision plays a part.  For instance,
solution by successive approximation may thrash indefinitely if the
value you are hunting is further than your "close enough" criterion
from two "adjacent" approximations.

You might also find that the computations you are doing introduce a
significant level of imprecision due to representation limits, although
usually anything that amplifies imprecision also amplifies the
inaccuracy of your data.

And there are special boundary cases, e.g. trig functions zooming off
to infinity.

There really is no substitute for some knowledge of numerical analysis,
even if self-taught.  You have to at least know enough to tell when you
are safe, and when you need to be careful.  There isn't a set of
cookbook directions that will guide you.

What makes Ada intimidating in this respect is that the standard tries
to make these issues visible and controllable, instead of giving you
whatever's on the machine and ignoring the problem.  (A language like
that wouldn't get a better grade than C.)*

Best,
Sam Mize

* Yes, it was gratuitous.  :-)




  parent reply	other threads:[~1997-07-31  0:00 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-07-29  0:00 floating point comparison Matthew Heaney
1997-07-30  0:00 ` Jan Galkowski
1997-07-31  0:00   ` Don Taylor
1997-07-31  0:00     ` Russ Lyttle
1997-08-01  0:00       ` W. Wesley Groleau x4923
1997-08-02  0:00         ` Robert Dewar
1997-08-02  0:00           ` Matthew Heaney
1997-08-03  0:00             ` Robert Dewar
1997-08-04  0:00           ` W. Wesley Groleau x4923
1997-08-05  0:00             ` Jan-Christoph Puchta
1997-08-05  0:00               ` W. Wesley Groleau x4923
1997-08-05  0:00                 ` Samuel Mize
1997-08-06  0:00                 ` Chris L. Kuszmaul
1997-08-07  0:00                   ` Dave Sparks
1997-08-08  0:00                     ` Jan-Christoph Puchta
1997-08-09  0:00                       ` Robert Dewar
1997-08-10  0:00                       ` Lynn Killingbeck
1997-08-08  0:00                     ` Mark Eichin
1997-08-08  0:00                     ` Robert Dewar
     [not found]                   ` <5sbb90$qsc@redtail.cruzio.com>
     [not found]                     ` <5scugs$jdc$1@cnn.nas.nasa.gov>
1997-08-07  0:00                       ` Robert Dewar
1997-08-08  0:00                     ` Gerhard Heinzel
1997-08-08  0:00                       ` schlafly
1997-08-08  0:00                       ` Daniel Villeneuve
1997-08-09  0:00                       ` Robert Dewar
1997-08-09  0:00                         ` David Ullrich
1997-08-10  0:00                           ` Robert Dewar
1997-08-16  0:00                             ` Andrew V. Nesterov
1997-08-18  0:00                               ` Robert Dewar
1997-08-19  0:00                                 ` Jim Carr
1997-08-21  0:00                                   ` Christian Bau
1997-08-21  0:00                                     ` Jim Carr
1997-08-21  0:00                                       ` Robert Dewar
1997-08-22  0:00                                         ` Jim Carr
1997-08-22  0:00                                           ` Robert Dewar
1997-08-23  0:00                                             ` Jim Carr
1997-08-24  0:00                                               ` Robert Dewar
     [not found]                                                 ` <5u4eq6$30b$1@news.lth.se>
1997-08-29  0:00                                                   ` Robert Dewar
1997-09-01  0:00                                                     ` Chris RL Morgan
1997-08-29  0:00                                                 ` Andrew V. Nesterov
1997-08-29  0:00                                                   ` Robert Dewar
     [not found]                                                     ` <340DF1DD.2736@iop.com>
1997-09-07  0:00                                                       ` Get_Immediate Robert Dewar
1997-09-07  0:00                                                       ` Get_Immediate Robert Dewar
1997-09-08  0:00                                                       ` Get_Immediate J Giffen
1997-09-01  0:00                                                 ` floating point comparison Jim Carr
     [not found]                                                   ` <checkerEFx6xI.FCM@netcom.com>
1997-09-03  0:00                                                     ` Chris L. Kuszmaul
1997-09-05  0:00                                                       ` Malome Khomo
1997-09-07  0:00                                                       ` Robert Dewar
1997-09-05  0:00                                                   ` Robert Dewar
1997-09-10  0:00                                                     ` Jim Carr
1997-09-12  0:00                                                       ` Robert Dewar
1997-09-15  0:00                                                         ` James Pauley
1997-09-16  0:00                                                           ` Robert Dewar
1997-08-23  0:00                                         ` W. Wesley Groleau x4923
1997-08-23  0:00                                           ` Robert Dewar
1997-08-19  0:00                                 ` Hans Olsson
1997-08-30  0:00                                 ` Paul Eggert
1997-08-06  0:00                 ` Robert Dewar
1997-08-07  0:00                   ` Shmuel (Seymour J.) Metz
1997-08-08  0:00                     ` Peter Shenkin
1997-08-09  0:00                       ` Albert Y.C. Lai
1997-08-06  0:00             ` Robert Dewar
     [not found]               ` <33E8E3E1.17EA@pseserv3.fw.hac.com>
     [not found]                 ` <5sbgpk$q0n$1@goanna.cs.rmit.edu.au>
1997-08-07  0:00                   ` Robert Dewar
     [not found]                     ` <33FE4603.1B6B@pseserv3.fw.hac.com>
1997-08-23  0:00                       ` Robert Dewar
1997-08-08  0:00                   ` W. Wesley Groleau x4923
1997-08-06  0:00             ` Robert Dewar
1997-08-07  0:00               ` Dr. Rex A. Dwyer
     [not found]               ` <33E8DFF6.6F44@pseserv3.fw.hac.com>
1997-08-07  0:00                 ` Robert Dewar
     [not found]                 ` <33EA1251.3466@link.com>
     [not found]                   ` <33EA46CC.226@pseserv3.fw.hac.com>
1997-08-08  0:00                     ` Christian Bau
1997-08-12  0:00                     ` Martin Tom Brown
1997-08-23  0:00                       ` W. Wesley Groleau x4923
1997-08-23  0:00                         ` Robert Dewar
1997-09-05  0:00                         ` Robert I. Eachus
1997-09-06  0:00                           ` schlafly
1997-09-09  0:00                             ` Robert Dewar
1997-09-07  0:00                           ` M. J. Saltzman
1997-09-11  0:00                           ` Robin Rosenberg
1997-08-07  0:00             ` Do-While Jones
1997-08-03  0:00         ` Brian Rogoff
1997-08-03  0:00           ` Robert Dewar
1997-07-30  0:00 ` Robert Dewar
1997-07-30  0:00   ` Matthew Heaney
1997-07-31  0:00     ` Bob Binder  (remove .mapson to email)
1997-07-31  0:00       ` Robert Dewar
1997-08-01  0:00         ` Dale Stanbrough
1997-08-04  0:00         ` Paul Eggert
1997-08-06  0:00           ` Robert Dewar
1997-08-14  0:00             ` Paul Eggert
1997-08-01  0:00       ` user
1997-08-02  0:00         ` Peter L. Montgomery
1997-08-04  0:00           ` W. Wesley Groleau x4923
1997-08-05  0:00             ` Bob Binder  (remove .mapson to email)
1997-08-02  0:00         ` Lynn Killingbeck
1997-08-03  0:00           ` Robert Dewar
1997-08-03  0:00           ` Bob Binder  (remove .mapson to email)
1997-08-03  0:00             ` Charles R. Lyttle
1997-07-31  0:00     ` Martin Tom Brown
1997-07-31  0:00     ` Samuel Mize [this message]
1997-07-31  0:00     ` Robert Dewar
1997-08-02  0:00     ` Lynn Killingbeck
1997-07-30  0:00   ` Matthew Heaney
1997-07-31  0:00     ` Jim Carr
1997-07-31  0:00   ` Gerald Kasner
1997-07-31  0:00     ` Robert Dewar
1997-08-02  0:00 ` Michael Sierchio
1997-08-08  0:00 ` floating point conversions Mark Lusti
replies disabled

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