Re: comparing doubles for equality
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Sat, 30 Dec 2006 21:58:37 -0500
Tim Prince 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)))
Do the same issues involved in comparing 2 fp types for equality
apply to comparing a float to zero? E.g. is if(x == 0.0)
considered harmful?
Depending on how you use this, you could make your application
highly dependent on external issues, such as whether you compile
for an extra precision mode, or disable gradual underflow.
That's why gcc has the Wfloat-equal switch. As far as the macro is
concerned, the a argument better not have any 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>
.
- References:
- comparing doubles for equality
- From: John Smith
- Re: comparing doubles for equality
- From: Tim Prince
- comparing doubles for equality
- Prev by Date: Re: comparing doubles for equality
- Next by Date: Re: Good ways to analyze a running c-program?
- Previous by thread: Re: comparing doubles for equality
- Next by thread: Re: comparing doubles for equality
- Index(es):
Relevant Pages
|