Re: comparing doubles for equality



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>


.



Relevant Pages

  • Re: comparing doubles for equality
    ... 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
    ... 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)
  • Re: overlapping math symbols
    ... If you need that you will basically need to create the macro using \mathchoice ... In our case, it expands to ... In my LaTeX book I once added a construction for \nuparrow because it is missing. ... As it is now that construction does not scale correctly. ...
    (comp.text.tex)
  • Re: If Code
    ... As for the construction of your code in general, I usually try to avoid using On Error traps when it is easy to code around them... ... > Carryout Macro ADD_TO_LIST ... > Sub ADD_TO_LIST ...
    (microsoft.public.excel.programming)
  • reader macro
    ... the new syntax allows making slightly more concise syntax for making very simple anonymous functions. ... i feel i could write something similar as a macro, ... I can't nest my construction, and I can live with that (after all it's ONLY for simple cases, otherwise it wouldn't be any more readable then lambda construction. ...
    (comp.lang.lisp)