Elias Zamaria <[email protected]> added the comment:
Mark, what you described (operator_fallbacks for both __rfloordiv__ and
__floordiv__, and for both __rmod__ and __mod__) was my initial approach. But
that broke one test (which floor-divides 1.0 by 1/10 and expects the result to
be an integer). I thought about fixing it, to make the behavior more
consistent, but I thought that was a bit risky.
Just now, I tried the change again, as you suggested, but I fixed the test to
expect a result of 10.0 (a float) instead of 10 (an integer). I got a strange
result from that test, saying the result was 9.0.
It seems like this is caused by rounding error, since operator_fallbacks
converts both numbers to floats if one of them is a float, and 1/10 can't be
represented exactly as a float, so it gets rounded to slightly more than 1/10:
>>> float(Fraction(1, 10)).as_integer_ratio()
(3602879701896397, 36028797018963968)
>>> Decimal.from_float(float(Fraction(1, 10)))
Decimal('0.1000000000000000055511151231257827021181583404541015625')
So yes, I can make that change, but I'm not sure if it would be a good idea. Do
you have any thoughts?
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32968>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com