🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4657

Re: Help, best way to compare doubles

#4657
From: mfinney
Date: Wed, 17 Jan 1996 21:41
29 lines
1530 bytes
In <mlK/wQ9ytpDN084yn@csn.net>, thads@csn.net (Thad Smith) writes:
>In article <4ddev4$1vg@stingray.mcnc.org>,
>coats@mcnc.org (Carlie Coats) wrote:
>
>>>14.5:	What's a good way to check for "close enough" floating-point
>>>	equality?
>
>> A safer test is of the form
>>
>>    | a - b | / sqrt( a^2 + b^2 + delta ) < epsilon
>
>This criteria, plus the squared version which uses squares, seems
>to be too much effort with no payback.

Check out "The Art of Computer Programming" by Donald Knuth,
Volume 2 "Seminumerical Alogrithms" starting on page 213 (2nd
edition) the section "4.2.2 Accuracy of Floating Point Arithmetic".

Knuth expounds on a bit of theory (easily followed) and the winds
up with very precise methods for floating point comparision and
the properties that hold.  You really need to read the section to
fully understand the formulae.  But it seems to be reasonably
definitive, outside of possible special application considerations.

BTW, none of the methods suggested so far are the ones that
Knuth recommends.


Michael Lee Finney
Technical Details
Message-ID: <4djqem$9th@mujibur.inmind.com>
Path: arc1-ca.pugleaf.net!mujibur.inmind.com!usenet
References: <4d1k09$aqq@mercury.IntNet.net> <4dbos6$o7q@umbc9.umbc.edu> <mlK/wQ9ytpDN084yn@csn.net>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mujibur.inmind.com!usenet
From: mfinney@inmind.com
Newsgroups: comp.std.c
Subject: Re: Help, best way to compare doubles
Date: 17 Jan 1996 21:41:42 GMT
Organization: In Mind, Inc.
Message-ID: <4djqem$9th@mujibur.inmind.com>
References: <4d1k09$aqq@mercury.IntNet.net> <4dbos6$o7q@umbc9.umbc.edu> <mlK/wQ9ytpDN084yn@csn.net>
Reply-To: mfinney@inmind.com
NNTP-Posting-Host: finneyman.inmind.com
X-Newsreader: IBM NewsReader/2 v1.2