As you know, due to the binary representation of numbers, this expression evaluates to False
(at least in Python):
0.2 + 0.4 == 0.6
To be able to verify equality in numerical errors, the module math
offers isclose
:
import math
math.isclose(0.2 + 0.4 , 0.6)
This last expression gives True
as expected.
Now why again the following expression False
?
math.isclose(0.2 + 0.4 - 0.6 , 0.0)
It seems like everything is compared to 0.0
equalFalse
math.isclose(1.0e-100 , 0.0)
source
share