Article View: comp.std.c
Article #4631Re: Help, best way to compare doubles
From: Jerry Coffin
Date: Sat, 13 Jan 1996 21:54
Date: Sat, 13 Jan 1996 21:54
35 lines
1299 bytes
1299 bytes
jtomich@IntNet.net (Jeff Tomich) wrote:
>Having a hard time to figure out a function on how to compare doubles.
>Any ideas?
Generally something like:
#include <float.h>
double a, b;
/* ... */
if ( fabs(a-b) <= DBL_EPSILON) {
/* They're equal */
}
else {
/* They're not equal... */
}
Note that this isn't the real purpose of DBL_EPSILON, so you may need to
change the exact value used...
As you've doubtless already dicovered, a simple test for equality or
lack of it is generally meaningless with floating point numbers.
BTW, you might want to ask questions like this in comp.lang.c or
comp.lang.c.moderated -- this newsgroup is really intended for
discussion of the C standard, not normal C programming as such.
Later,
Jerry.
/* I can barely express my own opinions; I certainly can't
* express anybody else's.
*
* The universe is a figment of its own imagination.
*/
Technical Details
Message-ID:
<4d95mp$c01@natasha.rmii.com>Path:
arc1-ca.pugleaf.net!news.rmii.com!usenetReferences:
<4d1k09$aqq@mercury.IntNet.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.rmii.com!usenet From: jcoffin@rmii.com (Jerry Coffin) Newsgroups: comp.std.c Subject: Re: Help, best way to compare doubles Date: Sat, 13 Jan 1996 21:54:41 GMT Organization: TAEUS Message-ID: <4d95mp$c01@natasha.rmii.com> References: <4d1k09$aqq@mercury.IntNet.net> NNTP-Posting-Host: slip8166.rmii.com X-Newsreader: Forte Free Agent 1.0.82