[issue39086] Division "/" error on Long Integers

Steven D'Aprano report at bugs.python.org
Wed Dec 18 07:28:38 EST 2019


Steven D'Aprano <steve+python at pearwood.info> 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 <report at bugs.python.org>
<https://bugs.python.org/issue39086>
_______________________________________


More information about the Python-bugs-list mailing list