Re: comparing doubles for equality



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>


.



Relevant Pages

  • Re: comparing doubles for equality
    ... Do the same issues involved in comparing 2 fp types for equality ... apply to comparing a float to zero? ... 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. ...
    (comp.lang.c)
  • RE: How do i cross reference two excel spreadsheets?
    ... Sorry - I forgot we're in the Worksheet Functions page, ... may need to change the column number if you're not just comparing everything ... To make the macro work, go to Tools, Macro, Visual Basic Editor while in the ... Same for the data in the second sheet, ...
    (microsoft.public.excel.worksheet.functions)
  • Re: How do i cross reference two excel spreadsheets?
    ... You definitely don't want to spend 3 minutes per column checking each cell ... Methods of limiting in a macro are to ... may need to change the column number if you're not just comparing everything ... Same for the data in the second sheet, ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Page Break????????
    ... sorting, comparing, matching, listing, finding...) ... Here's the full macro ...
    (microsoft.public.excel.programming)
  • Re: comparing doubles for equality
    ... 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. ... apply to comparing a float to zero? ... have the inaccurate description that the DBL_ISEQUAL macro does. ...
    (comp.lang.c)