comp.lang.ada
 help / color / mirror / Atom feed
* floating point comparison
@ 1997-07-29  0:00 Matthew Heaney
  1997-07-30  0:00 ` Robert Dewar
                   ` (3 more replies)
  0 siblings, 4 replies; 105+ messages in thread
From: Matthew Heaney @ 1997-07-29  0:00 UTC (permalink / raw)



I need to do some floating point comparisons in Ada 83 (but I'd like Ada 95
advice too), and needed someone to interpret the advice in AQ&S.

My immediate problem is, How do I test 2 floating point numbers for equality?

The AQ&S states that 

if abs (X - Y) <= Float_T'Small 

be used to test for "absolute equality in storage."

Q: What does "absolute equality in storage" mean?

Q: Why exactly is the test

if X - Y 

a Bad Thing?  Is it nonportable?  Not guaranteed to work?

Q: Is it ever acceptable to write "if X = Y" ?

Robert Dewar has stated in previous threads (one has the same name as the
subject of this post, so you can go to deja news to look it up), that it's
often OK to test for equality.  Robert: can you enumerate the conditions
under which such a test is appropriate, or refer us to a book explaining
why?


The AQ&S states that 

if abs (X - Y) <= Float_Type'Base'Small 

be used to test for "absolute equality in computation."

Q : What does "absolute equality in computation" mean?

Q: How is equality in "computation" different from "storage"?


The AQ&S states that 

if abs (X - Y) <= abs X * Float_Type'Epsilon 

be used to test for "relative equality in storage."

Q: What does "relative equality in storage" mean?

Q: How is "relative" equality different from "absolute" equality?


The AQ&S states that

if abs (X - Y) <= abs X * Float_Type'Base'Epsilon 

be used to test for "relative equality in computation."

Q: What does "relative equality in computation" mean?



Suppose I have 2 lines, and I want to make sure they aren't parallel.  How
should I write the predicate to compare the slopes of the lines, eg

if M1 = M2 then

or

if abs (M1 - M2) <= Slope'Small

or 

if abs (M1 - M2) <= abs M1 * Slope'Epsilon

or

<one of the forms that uses Slope'Base>

Honestly, the advice in the AQ&S is way over my head.  Does anyone out
there understand it, and care to explain it?

Is there a paper or book that explains Everything You Wanted To Know About
Floating Point Comparisons?

Under what circumstances would one use T'Small vs T'Epsilon?

I looked around in the Ada programming FAQ and couldn't find anything about
floating point comparisons.  Perhaps we can use the discussion this thread
engenders to add something to it.

Oddly enough, none of my Ada books state how to properly write a predicate
to compare floating point numbers.  Even Norm's book just had a vague
"compare the difference to a carefully chosen small value."  Anybody have
any substantive advice?

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 105+ messages in thread

end of thread, other threads:[~1997-09-16  0:00 UTC | newest]

Thread overview: 105+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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     ` 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
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                 ` 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                                 ` 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
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
     [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-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

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