Re: comparing doubles for equality



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
.



Relevant Pages

  • Re: comparing doubles for equality
    ... Any problems using it in a macro? ... This construction is misleading and I would never use it, ... the implied function, determining whether two doubles are equal, ...
    (comp.lang.c)
  • Re: comparing doubles for equality
    ... Any problems using it in a macro? ... Do the same issues involved in comparing 2 fp types for equality ... apply to comparing a float to zero? ... highly dependent on external issues, ...
    (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)