Re: comparing doubles for equality
- From: Thad Smith <ThadSmith@xxxxxxx>
- Date: Sat, 30 Dec 2006 19:42:13 -0700
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.
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?
Which issues are those? The test "if (x == 0.0)", in contrast, does not have the inaccurate description that the DBL_ISEQUAL macro does.
In both cases, you should employ good analysis for floating point comparisons.
--
Thad
.
- Follow-Ups:
- Re: comparing doubles for equality
- From: CBFalconer
- Re: comparing doubles for equality
- References:
- comparing doubles for equality
- From: John Smith
- comparing doubles for equality
- Prev by Date: Re: comparing doubles for equality
- 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):
Relevant Pages
|