8000 bpo-32968: Modulo and floor division involving Fraction and float should return float by elias6 · Pull Request #5956 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-32968: Modulo and floor division involving Fraction and float should return float #5956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 27, 2018
Prev Previous commit
Next Next commit
Undo problematic change to fraction math operations
Certain things, like adding math.inf to a fraction, will no longer raise an OverflowError.
  • Loading branch information
elias6 committed Mar 24, 2018
commit edbea7117f0362d2f306e4ec5642c9bb606839c0
2 changes: 1 addition & 1 deletion Lib/fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def reverse(b, a):
# Includes ints.
return monomorphic_operator(a, b)
elif isinstance(a, numbers.Real):
return float(fallback_operator(Fraction(a), b))
return fallback_operator(float(a), float(b))
elif isinstance(a, numbers.Complex):
return fallback_operator(complex(a), complex(b))
else:
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,12 @@ def testMixedArithmetic(self):
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.0, 1.0 // F(1, 10))
self.assertTypedEquals(9.0, 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(0.09999999999999995, 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'))
Expand Down
0