diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2016-08-22 09:50:53 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2016-08-22 09:50:53 (GMT) |
commit | 844796530a21f2a8689f2b9e01035d4a64a95275 (patch) | |
tree | 1866b84a3126cf68b121447bdcd5cb118c4f7896 /Lib/fractions.py | |
parent | 6afe85827c209b9d1e76a65ffdb7420b5f46ad3d (diff) | |
download | cpython-844796530a21f2a8689f2b9e01035d4a64a95275.zip cpython-844796530a21f2a8689f2b9e01035d4a64a95275.tar.gz cpython-844796530a21f2a8689f2b9e01035d4a64a95275.tar.bz2 |
Issue #27539: Fix unnormalised Fraction.__pow__ result for negative exponent and base. Thanks Vedran Čačić.
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r-- | Lib/fractions.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py index 60b0728..9aabab3 100644 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -484,10 +484,14 @@ class Fraction(numbers.Rational): return Fraction(a._numerator ** power, a._denominator ** power, _normalize=False) - else: + elif a._numerator >= 0: return Fraction(a._denominator ** -power, a._numerator ** -power, _normalize=False) + else: + return Fraction((-a._denominator) ** -power, + (-a._numerator) ** -power, + _normalize=False) else: # A fractional power will generally produce an # irrational number. |