mirror of https://github.com/python/cpython
Add support for int(r) just like the other numeric classes.
This commit is contained in:
parent
5ca924038d
commit
5b0e27e50d
|
@ -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__())
|
||||
|
|
Loading…
Reference in New Issue