0
abs(a - b) <= (atol + rtol * abs(b))

vs

(abs(a - b) <= atol
 or
 abs(a - b) / max(abs(a), abs(b)) < rtol)

Docs: numpy.allclose, mpmath.almosteq -- Source: numpy, mpmath

How do these schemes differ? An obvious one is that allclose is and while almosteq is or with respect to the tolerances. To me the and makes more sense, yet mpmath is a library dedicated to precision, so I find this strange.

When is almosteq preferred over allclose, speed/memory aside? (Optional question, can one's rtol be converted to another's rough equivalent)?

OverLordGoldDragon
  • 1
  • 9
  • 53
  • 101
  • 2
    One key difference is that the former is _not_ symmetric while the latter is. `allclose(a, b)` is _not_ the same as `allclose(b, a)`, whereas `almosteq(a, b)` is the same as `almosteq(b, a)`. – Brian61354270 Aug 07 '23 at 21:21

0 Answers0