"R. Robert Bell" wrote:
>
> What he means is that 1.01 is obviously only 0.01 away from being equal to
> 1.02. So (equal expr1 expr2 [fuzz]) _should_ return T for (equal 1.01 1.02
> 0.01)! In fact, I was surprised when I saw his post, and verified the
> problem with R14 & AC2K. This could hurt!
I'm not sure where you came to the conclusion that (equal)
should return T in the cited cases, but that is simply not
the case at all.
The purpose of (equal
) is to provide a
way to compare two numbers to a specified precision, and the
reason for it is because (eq) and (=) are both subject to
floating point roundoff, meaning that even though two values
appear to be equal, they may not be treated that way at the
precision that (eq) and (=) use (the underlying C++ runtime
library is what ultimately determines this, and two different
libraries, or even different releases of the same library
could easily yield different results given the same values).
However, when using this form of (equal), and the difference
between the two numbers appears to be equal to the ,
you are once again faced with the very same problem that
(equal ) was intended to solve: floating
point roundoff.
IOW, the underlying implementation of (equal) when used to
compare two numbers with fuzz, is basically this:
bool fuzzy-equal(double a, double b, double fuzz)
{
return abs(a - b) < fuzz;
}
Hence, in a case where the difference between the two
numbers appears to be equal to the fuzz, the success or
failure of (equal) is entirely dependent on how the C
runtime library's "<" (less-than) operator behaves given
these two operands. And, of course, that's essentially the
very same problem you have when using the (=) or (eq)
functions to compare two doubles (IOW, it's pot luck).
--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* [email protected] */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/