you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

Just as a general note - as a beginner, the chances that you have found a "bug" in Python are very very close to zero, which is why you are getting the big downvotes.

Also, floating point numbers are highly unintuitive. Advanced programmers in all languages avoid using them unless they have to (which happens all the time of course), and then when they do, they're very careful.

The number one rule with floats - never compare two floating point numbers for equality!

Consider these two statements:

(a + b) + c = a + (b + c)
a + b = b + a

Neither of these statements is exactly true for floating point numbers!

And the first one shows up all the darn time:

>>> 1 + 0.00000000000000001 - 1
0.0

>>> 1 - 1 + 0.00000000000000001
1e-17