Steven D'Aprano <[email protected]> added the comment:
Looking at your first example, you calculate:
>>> 63945173192649609/13
4918859476357662.0
which is correct when using floats (64-bit C doubles). 64 bits are not enough
to be any more precise, and you would get the same result in C or any other
language using the same precision.
Using Decimal with the default precision, you could get:
>>> decimal.Decimal(63945173192649609)/13
Decimal('4918859476357662.230769230769')
but the exact result is 4918859476357662.[230769] where the decimal part inside
the square brackets [...] repeats forever.
So within the limitations of the C 64-bit double floating point format, the
calculation is correct and there is no bug here.
Please see
https://docs.python.org/3/faq/design.html#why-are-floating-point-calculations-so-inaccurate
for more information.
----------
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue39086>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com