, ( 2) . , , 0.01 , . 0.01 float :
0.01 * 2 = 0.02 [0]
0.02 * 2 = 0.04 [0]
0.04 * 2 = 0.08 [0]
0.08 * 2 = 0.16 [0]
0.16 * 2 = 0.32 [0]
0.32 * 2 = 0.64 [0]
0.64 * 2 = 1.28 [0]
0.28 * 2 = 0.56 [0]
0.56 * 2 = 1.12 [1]
...
, , , . , , , . , , , (, , ). , , , , . x + = 0.01 .
0,5 :
0.5 * 2 = 1.0 [1]
So, the binary equivalent of 0.5 float is 0.1 . Since it is perfectly represented in binary format on your computer. You will get the exact result.
This has nothing to do with your code or python. This is just the way computer hardware works :)
source
share