From: Gerhard Heinzel <ghh@mpq.mpg.de>
Subject: Re: floating point comparison
Date: 1997/08/08
Date: 1997-08-08T00:00:00+00:00 [thread overview]
Message-ID: <Pine.SOL.3.91.970808104726.13390B-100000@mpqgrav1.mpq.mpg.de> (raw)
In-Reply-To: 5sbb90$qsc@redtail.cruzio.com
On 7 Aug 1997 schlafly@bbs.cruzio.com wrote:
> In article <5sar4r$t7m$1@cnn.nas.nasa.gov>, fyodor@sally.nas.nasa.gov (Chris L. Kuszmaul) writes:
> > Fair enough. There are two basic guidlines I follow:
> >
> > 1: Do not test for equality between floating point values. If you do, then
> > you better get a numerical analysit, or figure out how to avoid using floating
> > point, or see if you can use a 'close to equal' check.
>
> There is nothing inherently wrong with testing for equality,
> if that is what you really want. It is a very easily
> understandable and reliable operation, except for some funny
> business involving NANs.
>
Maybe it should be clarified WHY one would want to test for equality.
I can imagine two distinct situations:
First, to test whether two numbers that have not been computed, but only
entered and maybe stored back and forth, are the same. I rarely have that
case (It is usually much better to mark things with logical or integer
variables in that case, and test the integers). But I assume that testing
for equality may be ok in that case.
Second, if you want to compare two numbers that come from some algorithm
(i.e. is an eigenvalue zero? is a pivot zero? is a correlation coefficient
unity?) In these cases one must NEVER test for exact equality, but always
take into account rounding errors and devise some test such as
fabs(x-y)<EPSILON
or fabs((x-y)/y)<EPSILON
or something similar, depending on the situation.
=====================================================================
Gerhard Heinzel E-mail: ghh@mpq.mpg.de
Max-Planck-Institut fuer Quantenoptik Phone: +49(89)32905-268/252
Hans-Kopfermann-Str. 1 Phone (30m Lab): +49(89)3299-3282
D-85748 Garching Fax: +49(89)32905-200
Germany http://www.geo600.uni-hannover.de
=====================================================================
next prev parent reply other threads:[~1997-08-08 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 ` Robert Dewar
1997-07-30 0:00 ` Matthew Heaney
1997-07-31 0:00 ` Jim Carr
1997-07-30 0:00 ` Matthew Heaney
1997-07-31 0:00 ` Robert Dewar
1997-07-31 0:00 ` Samuel Mize
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 ` Lynn Killingbeck
1997-08-03 0:00 ` Bob Binder (remove .mapson to email)
1997-08-03 0:00 ` Charles R. Lyttle
1997-08-03 0:00 ` Robert Dewar
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-07-31 0:00 ` Martin Tom Brown
1997-08-02 0:00 ` Lynn Killingbeck
1997-07-31 0:00 ` Gerald Kasner
1997-07-31 0:00 ` Robert Dewar
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 ` 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 ` Chris L. Kuszmaul
1997-08-07 0:00 ` Dave Sparks
1997-08-08 0:00 ` Robert Dewar
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
[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 [this message]
1997-08-08 0:00 ` Daniel Villeneuve
1997-08-08 0:00 ` schlafly
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 ` Hans Olsson
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
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
[not found] ` <5u4eq6$30b$1@news.lth.se>
1997-08-29 0:00 ` floating point comparison Robert Dewar
1997-09-01 0:00 ` Chris RL Morgan
1997-09-01 0:00 ` 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-30 0:00 ` Paul Eggert
1997-08-06 0:00 ` Robert Dewar
[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 ` Dr. Rex A. Dwyer
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-07 0:00 ` Do-While Jones
1997-08-03 0:00 ` Brian Rogoff
1997-08-03 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