Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

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

----------
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39738>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to