summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-01-24 23:50:26 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-01-24 23:50:26 (GMT)
commit909e334e8a525e8430f1532c0ecf133f19d3d185 (patch)
tree0292e8dc34f2416b7e25ce3707a61463697f886e /Lib
parent31eaafef4a710b657133bbf206e9d9c42c8841d9 (diff)
downloadcpython-909e334e8a525e8430f1532c0ecf133f19d3d185.zip
cpython-909e334e8a525e8430f1532c0ecf133f19d3d185.tar.gz
cpython-909e334e8a525e8430f1532c0ecf133f19d3d185.tar.bz2
More code cleanup. Remove unnecessary indirection to useless class methods.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/rational.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/Lib/rational.py b/Lib/rational.py
index 6824f4a..0d3ea2f 100755
--- a/Lib/rational.py
+++ b/Lib/rational.py
@@ -285,8 +285,9 @@ class Rational(RationalAbc):
__truediv__, __rtruediv__ = _operator_fallbacks(_div, operator.truediv)
__div__, __rdiv__ = _operator_fallbacks(_div, operator.div)
- @classmethod
- def _floordiv(cls, a, b):
+ def __floordiv__(a, b):
+ """a // b"""
+ # Will be math.floor(a / b) in 3.0.
div = a / b
if isinstance(div, RationalAbc):
# trunc(math.floor(div)) doesn't work if the rational is
@@ -296,28 +297,27 @@ class Rational(RationalAbc):
else:
return math.floor(div)
- def __floordiv__(a, b):
- """a // b"""
- # Will be math.floor(a / b) in 3.0.
- return a._floordiv(a, b)
-
def __rfloordiv__(b, a):
"""a // b"""
# Will be math.floor(a / b) in 3.0.
- return b._floordiv(a, b)
-
- @classmethod
- def _mod(cls, a, b):
- div = a // b
- return a - b * div
+ div = a / b
+ if isinstance(div, RationalAbc):
+ # trunc(math.floor(div)) doesn't work if the rational is
+ # more precise than a float because the intermediate
+ # rounding may cross an integer boundary.
+ return div.numerator // div.denominator
+ else:
+ return math.floor(div)
def __mod__(a, b):
"""a % b"""
- return a._mod(a, b)
+ div = a // b
+ return a - b * div
def __rmod__(b, a):
"""a % b"""
- return b._mod(a, b)
+ div = a // b
+ return a - b * div
def __pow__(a, b):
"""a ** b