[Issue 15881] approxEqual Ignores maxAbsDiff

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Apr 6 08:52:51 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15881

--- Comment #1 from John Hall <john.michael.hall at gmail.com> ---
Actually, after thinking about it more, it should probably be something like

if (maxAbsDiff >= 0)
     return (fabs((lhs - rhs) / rhs) <= maxRelDiff) && 
          fabs(lhs - rhs) <= maxAbsDiff;
else
     assert(0, "Error: maxAbsDiff must be greater than or equal to zero");

This may not be exactly what the original authors intended, but it makes the
most sense to me. I had also considered making (maxAbsDiff >= 0) to be
(maxAbsDiff > 0). The downside is that this is enforcing them to be exactly
equal, but that might be something worth doing.

--


More information about the Digitalmars-d-bugs mailing list