I run:
print(0.1)
print(0.2)
print(0.3)
print(0.4)
print(0.5)
print(0.5-0.4)
print(0.4-0.3)
print(0.3-0.2)
print(0.2-0.1)
It shows:
0.1
0.2
0.3
0.4
0.5
0.09999999999999998
0.10000000000000003
0.09999999999999998
0.1
Why print number directly is fine, but use of the operator -
will get unexpected value?
I have checked: Is floating point math broken?
If 0.5-0.4
could not be saved in hardware precisely, why just print(0.1) will show 0.1 not 0.10000000000xxx?
Maybe more clear statement is:
In my understanding, python should print(0.1) to be 0.10000000000xxx, and 0.5-0.4 should equal to 0.4-0.3 and equal to 0.3-0.2, right?
Why python could "Python keeps the number of digits manageable by displaying a rounded value"? If python wants to print(0.1) to be 0.1, it should treat 0.4-0.3 as 0.1 well, right? Why python want us to be confusion on this kind of topics?
For even more precise statement that this problem is "not" really argue that 0.5-0.4 != 0.4-0.3. My main problem is print(0.1)= 0.1 not 0.10000000000xxxx, why python could do this kind of action? It will let us very confusion with the "Is floating point math broken?"