Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> 4.2 - 1.8
2.4000000000000004
>>> 1.20 - 1.18
0.020000000000000018
>>> 5.1 - 4
1.0999999999999996
>>> 5 - 4
1
>>> 5.0 - 4.0
1.0
Why is Python getting its maths wrong?
sqrt(2)aren't even representable in a finite amount of space without directly coding them as things likesqrt(2)). The errors in Python's floating point arithmetic have been accepted as "the way it is done" for a very long time, and we just have to live with that as a matter of pragmatism. It is very very important for programmers to be aware of this, but we all have this moment of confusion.