Why does the following statement evaluate to True
even though the two numbers passed to np.isclose()
differ by more than atol
?
In [x]: np.isclose(-2.00231930436153, -2.0023193043615, atol=1.e-14)
Out[x]: True
In the following code:
In [x]: a, b = -2.00231930436153, -2.0023193043615
In [x]: np.isclose(a, b, atol=1.e-14)
Out[x]: True
np.isclose()
returns True
because although the absolute difference between the two numbers is greater than $10^{-14}$, it is (significantly) less than rtol * abs(b)
, the contribution from the default relative difference. To obtain the expected behaviour, set rtol
to 0:
In [x]: np.isclose(-2.00231930436153, -2.0023193043615, atol=1.e-14, rtol=0)
Out[x]: False