Why do some floating-point calculations with 0.1 produce exact results while others do not?
In Python, `0.1 + 0.2 == 0.3` evaluates to `False`, while `0.1 + 0.1 == 0.2` evaluates to `True`. Even more confusingly, `sum([0.1] * 10000) == 1000` may…
In Python, `0.1 + 0.2 == 0.3` evaluates to `False`, while `0.1 + 0.1 == 0.2` evaluates to `True`. Even more confusingly, `sum([0.1] * 10000) == 1000` may…
In Python, these expressions produce surprising results: print(0.1 + 0.2 == 0.3) # False print(0.1 + 0.1 == 0.2) # True print(sum([0.1] * 10000) == 1000) # True…
I recently learned that Python's round() uses bankers' rounding: an exact halfway value rounds to whichever adjacent integer is even, so round(2.5) gives 2 while round(3.5) gives 4.…