Message358625
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. |
|
Date |
User |
Action |
Args |
2019-12-18 12:28:38 | steven.daprano | set | recipients:
+ steven.daprano, docs@python, Mradul |
2019-12-18 12:28:38 | steven.daprano | set | messageid: <1576672118.94.0.461357044364.issue39086@roundup.psfhosted.org> |
2019-12-18 12:28:38 | steven.daprano | link | issue39086 messages |
2019-12-18 12:28:38 | steven.daprano | create | |
|