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 David Hwang, steven.daprano
Date 2020-02-02.05:42:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580622131.77.0.341253326354.issue39525@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2020-02-02 05:42:11steven.dapranosetrecipients: + steven.daprano, David Hwang
2020-02-02 05:42:11steven.dapranosetmessageid: <1580622131.77.0.341253326354.issue39525@roundup.psfhosted.org>
2020-02-02 05:42:11steven.dapranolinkissue39525 messages
2020-02-02 05:42:11steven.dapranocreate