This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients Mradul, docs@python, steven.daprano
Date 2019-12-18.12:28:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576672118.94.0.461357044364.issue39086@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-12-18 12:28:38steven.dapranosetrecipients: + steven.daprano, docs@python, Mradul
2019-12-18 12:28:38steven.dapranosetmessageid: <1576672118.94.0.461357044364.issue39086@roundup.psfhosted.org>
2019-12-18 12:28:38steven.dapranolinkissue39086 messages
2019-12-18 12:28:38steven.dapranocreate