wtfpython
wtfpython copied to clipboard
floating point operations and test
I met a nasty bug that will now wake me up at night... It concerns floating point operations and I feel like it is not really included in your list. Note that one could argue this problem is not python specific but it still caused some nasty bug and people might want to be aware of this. (This blog reminded me of the bug and helped me formulate it more clearly here). It boils down to:
1 + 2 == 3
True
(1 + 2)/10 == 3/10
True
1/10 + 2/10 == 3/10
False
.1 + .2 == .3
False
And of course :
0.3 - 0.2 - 0.1 == 0
False
That's not a bug, that's how floating point works