Does anyone know why the de-facto standard definition of isapprox
intentionally fails when one of the arguments is zero?
isapprox(0.0, 0.0 + 1e-10) # false
isapprox(1.0, 1.0 + 1e-10) # true
It is clear from the formula why this is happening:
If we set y=0, we get:
The default atol = 0 then makes it:
and the default rtol = \sqrt\epsilon leads to:
which is false because \sqrt\epsilon < 1.
This formula is also used by Pythonâs math standard library isclose
as explained in their docs. More recently, the NumPy library changed the definition to an asymmetric one:
which is âmore intuitiveâ when one of the arguments is zero:
>>> np.isclose(0.0 + 1e-10, 0.0)
np.True_
>>> np.isclose(1.0 + 1e-10, 1.0)
np.True_
However, the asymmetry introduces new nuances as explained in their docs.
Appreciate if someone with background in numerics could justify these formulas with practical examples. Can we achieve something better that works âintuitivelyâ in all cases, including zero arguments?