mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Fix a performance issue in Decimal.pow. Thanks Stefan Krah for finding this.
This commit is contained in:
parent
f48ea7c2a9
commit
a123631a5c
3 changed files with 25 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue