[issue32968] Fraction modulo infinity should behave consistently with other numbers

Elias Zamaria report at bugs.python.org
Fri Mar 16 00:12:13 EDT 2018


Elias Zamaria <mikez302 at gmail.com> added the comment:

Mark, I tried `Fraction(10**23) // 1e22`, and I got 10.

Your `10**23 // 1e22` example was strange, but then `int(1e23)` and got 99999999999999991611392. That is kind of unexpected but I think it is rare for anyone to do something like that with numbers that big.

I think the fact that floating-point rounding error sometimes causes strange results is not a reason to do really unexpected things like making 1.0 // 1/10 equal 9.0, if that can be reasonably avoided.

I updated my pull request with my change, which you suggested, to make __rfloordiv__ and __rmod__ return a float, but with a small change to _operator_fallbacks to avoid the rounding error, so 1.0 // 1/10 is 10.0. You can see it at https://github.com/python/cpython/pull/5956/commits/1020bb219c1a4fad575ee2309c930ce82a4777fb#diff-14d03bfb59581367725b00781e6f802fL391. What do you think?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32968>
_______________________________________


More information about the Python-bugs-list mailing list