I'm facing a (for me) strange behaviour of the //
operator in python.
When I compute, e.g., 5.//0.25
I become the right result, i.e.
>>> 5.//0.25
20.0
But
>>> 5.//0.2
24.0
Instead of
>>> math.floor(5./0.2)
25
Can anyone explain me this results? Why is the result of the //
24.0?
EDIT: The given link Is floating point math broken? does not really answer the question exhaustively. In fact, with this answer one can not understand why the floor of the normal division give the right result. The real answer should explain how does //
work, as was done by polku in the comments
And perhaps I had to write this from the beginning: why is this happening?
>>> print('%.17f' % (5./0.20000000298023224))
24.99999962747097726
>>> print('%.17f' % (5./0.2))
25.00000000000000000
EDIT2: This question should really be reopened, since it's answers isn't given in the suggested duplicate question, but rather in @polku's comment.