This project has moved and is read-only. For the latest updates, please go here.

AlmostEqualWithError

Nov 16, 2011 at 1:00 PM

I just noticed an issue with AlmostEqualWithError, something like 1.2E-16.AlmostEqualWithError(1.3E-16, 1E-9) returns false, because the method decides to test by relative error.

From my point of view the abs/rel error decision should be changed from...

if (Math.Abs(a) < _doubleMachinePrecision || Math.Abs(b) < _doubleMachinePrecision)
   return AlmostEqualWithAbsoluteError(a, b, diff, maximumError);

to

if (Math.Abs(a) < maximumError || Math.Abs(b) < maximumError)
   return AlmostEqualWithAbsoluteError(a, b, diff, maximumError);

 

-Andy

 

 

 

 

 

 

Nov 17, 2011 at 12:07 AM

Hi Andy

Yes, this sounds reasonable, I consider to apply the change.

Those who explicitly need either absolute or relative error testing should use the alternative methods anyway, which remain unaffected by this change.

Thanks,
Chris