Message361214
math.remainder performs *floating point* remainder. That means it has to convert the arguments to floats first, and there is no float capable of representing either of those two numbers exactly:
py> '%f' % float(12345678901234567890)
'12345678901234567168.000000'
py> '%f' % float(12345678901234567891)
'12345678901234567168.000000'
That's just the way floats work. They don't have infinite precision, so sometimes they have rounding error.
If you want exact integer remainder, use the `%` operator:
py> 12345678901234567890 % 3
0
py> 12345678901234567891 % 3
1
See the tutorial and the FAQs
https://docs.python.org/3/tutorial/floatingpoint.html
https://docs.python.org/3/faq/design.html#why-are-floating-point-calculations-so-inaccurate |
|
Date |
User |
Action |
Args |
2020-02-02 05:42:11 | steven.daprano | set | recipients:
+ steven.daprano, David Hwang |
2020-02-02 05:42:11 | steven.daprano | set | messageid: <1580622131.77.0.341253326354.issue39525@roundup.psfhosted.org> |
2020-02-02 05:42:11 | steven.daprano | link | issue39525 messages |
2020-02-02 05:42:11 | steven.daprano | create | |
|