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 elias
Recipients elias, jyasskin, mark.dickinson, rhettinger, serhiy.storchaka
Date 2018-03-15.05:38:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1521092317.53.0.467229070634.issue32968@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2018-03-15 05:38:37eliassetrecipients: + elias, rhettinger, mark.dickinson, jyasskin, serhiy.storchaka
2018-03-15 05:38:37eliassetmessageid: <1521092317.53.0.467229070634.issue32968@psf.upfronthosting.co.za>
2018-03-15 05:38:37eliaslinkissue32968 messages
2018-03-15 05:38:33eliascreate