Re: comparing doubles for equality
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Sun, 31 Dec 2006 00:13:12 -0500
Thad Smith wrote:
John Smith wrote:
This code for the comparison of fp types is taken from the C FAQ.
Any problems using it in a macro?
/* compare 2 doubles for equality */
#define DBL_ISEQUAL(a,b) (fabs((a)-(b))<=(DBL_EPSILON)*fabs((a)))
This construction is misleading and I would never use it, because
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.
--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
.
- Follow-Ups:
- Re: comparing doubles for equality
- From: Thad Smith
- Re: comparing doubles for equality
- References:
- comparing doubles for equality
- From: John Smith
- Re: comparing doubles for equality
- From: Thad Smith
- comparing doubles for equality
- Prev by Date: Re: without loop printing 1 to n
- Next by Date: Re: Pass an EOF before pressing enter
- Previous by thread: Re: comparing doubles for equality
- Next by thread: Re: comparing doubles for equality
- Index(es):
Relevant Pages
|