mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-119189: Fix the power operator for Fraction (GH-119242) (GH-119835)
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.
(cherry picked from commit b9965ef282
)
Co-authored-by: Joshua Herman <30265+zitterbewegung@users.noreply.github.com>
This commit is contained in:
parent
b455a5a55c
commit
d4f57ccc3a
4 changed files with 12 additions and 6 deletions
|
@ -825,8 +825,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