Fix a performance issue in Decimal.pow. Thanks Stefan Krah for finding this.

This commit is contained in:
Mark Dickinson 2010-07-08 19:03:34 +00:00
parent f48ea7c2a9
commit a123631a5c
3 changed files with 25 additions and 6 deletions

View file

@ -2047,12 +2047,14 @@ class Decimal(object):
# case where xc == 1: result is 10**(xe*y), with xe*y
# required to be an integer
if xc == 1:
if ye >= 0:
exponent = xe*yc*10**ye
else:
exponent, remainder = divmod(xe*yc, 10**-ye)
if remainder:
return None
xe *= yc
# result is now 10**(xe * 10**ye); xe * 10**ye must be integral
while xe % 10 == 0:
xe //= 10
ye += 1
if ye < 0:
return None
exponent = xe * 10**ye
if y.sign == 1:
exponent = -exponent
# if other is a nonnegative integer, use ideal exponent