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

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

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

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

Reply via email to