floating point arithmetic issue
30 Jul
2010
30 Jul
'10
10:45 a.m.
Hello, I ran into a difficulty with floating point arithmetic in python. Namely that:
0.001 + 1 - 1 0.00099999999999988987
And, as a consequence, in python:
0.001 + 1 - 1 == 0.001 False
In more details, my problem is that I have a fonction which needs to compute (a + b - c) % a. And for b == c, you would expect the result to be 0 whatever the value of a. But it isn't...
(0.001 + 1 - 1) % 0.001 0.00099999999999988987
Is there any way to solve this? Many thanks, Guillaume
4977
Age (days ago)
4981
Last active (days ago)
15 comments
9 participants
participants (9)
-
Alan G Isaac
-
Benjamin Root
-
Christopher Barker
-
David
-
David Cournapeau
-
Guillaume Chérel
-
Ken Watford
-
Pauli Virtanen
-
Peter