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

This commit is contained in:
Raymond Hettinger 2008-01-24 19:30:19 +00:00
parent 5ca924038d
commit 5b0e27e50d
2 changed files with 3 additions and 0 deletions

View File

@ -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

View File

@ -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__())