What determines floating point precision in python?

I learned about the “exactly equal” operator in Erlang, which compares not only values , but also the data types of numbers, and I was curious how everything works in Python and its single “equal” operator. Therefore, making sure that

>>> 1 == 1.0 
True

I wondered about floating point precision and got to this

>>> 0.9999999999999999 == 1
False
>>> 0.99999999999999999 == 1
True
>>>

Can anyone explain how floating point precision is defined here? It works the same in both 2.7.1 and 3.1.2

+5
source share
2 answers

Please check out the Python documentation:

http://docs.python.org/tutorial/floatingpoint.html

+8

All Articles