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 paul.moore, steve.dower, steven.daprano, tim.golden, wjzbf, zach.ware
Date 2020-02-24.09:42:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582537367.33.0.852833689471.issue39738@roundup.psfhosted.org>
In-reply-to
Content
This is a floating point issue, not a bug. Floats inherently only have a limited precision available, so they are not always the exact number you think they are.

Using 1e9 forces the result to be a float, which introduces rounding errors into the calculation. If you use an exact integer, the calculation is exact:


py> 151476660579404160000-151476660579404160000//1000000007 * (10**9+7)
67543367
py> 151476660579404160000 % (10**9+7)
67543367


*This is not a Python bug* this is an inherent limitation of floating point numbers and the same issues will occur in any language that uses floats.

https://docs.python.org/3/faq/design.html#why-am-i-getting-strange-results-with-simple-arithmetic-operations
History
Date User Action Args
2020-02-24 09:42:47steven.dapranosetrecipients: + steven.daprano, paul.moore, tim.golden, zach.ware, steve.dower, wjzbf
2020-02-24 09:42:47steven.dapranosetmessageid: <1582537367.33.0.852833689471.issue39738@roundup.psfhosted.org>
2020-02-24 09:42:47steven.dapranolinkissue39738 messages
2020-02-24 09:42:47steven.dapranocreate