mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
gh-119189: Fix the power operator for Fraction (GH-119242)
When using the ** operator or pow() with Fraction as the base and an exponent that is not rational, a float, or a complex, the fraction is no longer converted to a float.
This commit is contained in:
parent
dae0375bd9
commit
b9965ef282
4 changed files with 12 additions and 6 deletions
|
|
@ -877,8 +877,10 @@ class Fraction(numbers.Rational):
|
|||
# A fractional power will generally produce an
|
||||
# irrational number.
|
||||
return float(a) ** float(b)
|
||||
else:
|
||||
elif isinstance(b, (float, complex)):
|
||||
return float(a) ** b
|
||||
else:
|
||||
return NotImplemented
|
||||
|
||||
def __rpow__(b, a):
|
||||
"""a ** b"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue