summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/fractions.py13
-rw-r--r--Lib/test/test_fractions.py10
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Library/2018-03-18-15-57-32.bpo-32968.E4G7BO.rst1
4 files changed, 13 insertions, 12 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py
index 8330202..e0a024a 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -427,23 +427,18 @@ class Fraction(numbers.Rational):
__truediv__, __rtruediv__ = _operator_fallbacks(_div, operator.truediv)
- def __floordiv__(a, b):
+ def _floordiv(a, b):
"""a // b"""
return math.floor(a / b)
- def __rfloordiv__(b, a):
- """a // b"""
- return math.floor(a / b)
+ __floordiv__, __rfloordiv__ = _operator_fallbacks(_floordiv, operator.floordiv)
- def __mod__(a, b):
+ def _mod(a, b):
"""a % b"""
div = a // b
return a - b * div
- def __rmod__(b, a):
- """a % b"""
- div = a // b
- return a - b * div
+ __mod__, __rmod__ = _operator_fallbacks(_mod, operator.mod)
def __pow__(a, b):
"""a ** b
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py
index 7905c36..452f181 100644
--- a/Lib/test/test_fractions.py
+++ b/Lib/test/test_fractions.py
@@ -401,15 +401,19 @@ class FractionTest(unittest.TestCase):
self.assertTypedEquals(10.0 + 0j, (1.0 + 0j) / F(1, 10))
self.assertTypedEquals(0, F(1, 10) // 1)
- self.assertTypedEquals(0, F(1, 10) // 1.0)
+ self.assertTypedEquals(0.0, F(1, 10) // 1.0)
self.assertTypedEquals(10, 1 // F(1, 10))
self.assertTypedEquals(10**23, 10**22 // F(1, 10))
- self.assertTypedEquals(10, 1.0 // F(1, 10))
+ self.assertTypedEquals(1.0 // 0.1, 1.0 // F(1, 10))
self.assertTypedEquals(F(1, 10), F(1, 10) % 1)
self.assertTypedEquals(0.1, F(1, 10) % 1.0)
self.assertTypedEquals(F(0, 1), 1 % F(1, 10))
- self.assertTypedEquals(0.0, 1.0 % F(1, 10))
+ self.assertTypedEquals(1.0 % 0.1, 1.0 % F(1, 10))
+ self.assertTypedEquals(0.1, F(1, 10) % float('inf'))
+ self.assertTypedEquals(float('-inf'), F(1, 10) % float('-inf'))
+ self.assertTypedEquals(float('inf'), F(-1, 10) % float('inf'))
+ self.assertTypedEquals(-0.1, F(-1, 10) % float('-inf'))
# No need for divmod since we don't override it.
diff --git a/Misc/ACKS b/Misc/ACKS
index 8c8d954..82fbc92 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1814,6 +1814,7 @@ Masazumi Yoshikawa
Arnaud Ysmal
Bernard Yue
Moshe Zadka
+Elias Zamaria
Milan Zamazal
Artur Zaprzala
Mike Zarnstorff
diff --git a/Misc/NEWS.d/next/Library/2018-03-18-15-57-32.bpo-32968.E4G7BO.rst b/Misc/NEWS.d/next/Library/2018-03-18-15-57-32.bpo-32968.E4G7BO.rst
new file mode 100644
index 0000000..16bf2f3
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-03-18-15-57-32.bpo-32968.E4G7BO.rst
@@ -0,0 +1 @@
+Modulo and floor division involving Fraction and float should return float.