Re: comparing doubles for equality
- From: Thad Smith <ThadSmith@xxxxxxx>
- Date: Sat, 30 Dec 2006 23:31:18 -0700
CBFalconer wrote:
Thad Smith wrote:John Smith wrote:
This code for the comparison of fp types is taken from the C FAQ.This construction is misleading and I would never use it, because
Any problems using it in a macro?
/* compare 2 doubles for equality */
#define DBL_ISEQUAL(a,b) (fabs((a)-(b))<=(DBL_EPSILON)*fabs((a)))
the implied function, determining whether two doubles are equal,
is not an accurate description of the returned value.
How about:
#define DUNEQUAL(a, b) (fabs((a)-(b)) > (DBL_EPSILON)*fabs((a)))
with a caveat against passing an a with side effects.
That misses the point. The only true equality test is given by a==b. If you need an epsilon, fine, but you should make it explicit. DBL_EPSILON isn't necessarily the correct choice for a particular application. In fact, the two tests above may not provide any advantage
over a strict equality.
--
Thad
.
- Follow-Ups:
- Re: comparing doubles for equality
- From: CBFalconer
- Re: comparing doubles for equality
- References:
- comparing doubles for equality
- From: John Smith
- Re: comparing doubles for equality
- From: Thad Smith
- Re: comparing doubles for equality
- From: CBFalconer
- comparing doubles for equality
- Prev by Date: Re: without loop printing 1 to n
- Next by Date: Re: comparing doubles for equality
- Previous by thread: Re: comparing doubles for equality
- Next by thread: Re: comparing doubles for equality
- Index(es):