Commit 5b0e27e5 authored by Raymond Hettinger's avatar Raymond Hettinger

Add support for int(r) just like the other numeric classes.

parent 5ca92403
......@@ -376,6 +376,8 @@ class Rational(RationalAbc):
else:
return a.numerator // a.denominator
__int__ = __trunc__
def __floor__(a):
"""Will be math.floor(a) in 3.0."""
return a.numerator // a.denominator
......
......@@ -160,6 +160,7 @@ class RationalTest(unittest.TestCase):
def testConversions(self):
self.assertTypedEquals(-1, trunc(R(-11, 10)))
self.assertTypedEquals(-1, int(R(-11, 10)))
self.assertTypedEquals(-2, R(-11, 10).__floor__())
self.assertTypedEquals(-1, R(-11, 10).__ceil__())
self.assertTypedEquals(-1, R(-10, 10).__ceil__())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment