+ 1
Python Problem II
Can any one explain why floating point calculations are so inaccurate? This is because I discovered something: I just add an float to an another float just like this: print(1.2 - 1.0) But instead of displaying 0.2, why output is 0.19999999999999996? And situations are the same even I make it more specific, lets say: print(1.200000 - 1.000000) Why 0.19999999999999996 is still the output? Thanks for any response that you make.
4 Antworten
0
No. That's not a bug. It's nature of binary floating point numbers. So that's why it is not advisable to relay of floating point numbers in large codes because that messy thing.
Edit:
James Clark I. Vinarao
This will explain in more details, take a look
https://docs.python.org/3/tutorial/floatingpoint.html#tut-fp-issues)
+ 1
That's depends on compiler internals.. see some other similar discussions. May help you...
https://www.sololearn.com/discuss/2080262/?ref=app
https://www.sololearn.com/discuss/2149084/?ref=app
https://www.sololearn.com/discuss/1733175/?ref=app
https://www.sololearn.com/discuss/1001890/?ref=app
https://www.sololearn.com/discuss/796595/?ref=app
+ 1
When python stores floating-point numbers it uses binary instead of the way we do it which is Decimal
0
decimal is when we get to ten it’s two digit, but binary is when u count to two it gets to ten like this: 1,10,11,20,21