diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-07-08 19:03:34 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-07-08 19:03:34 (GMT) |
commit | a123631a5ca464c99faf039ee5c74ec9025d5d64 (patch) | |
tree | 93f70adf2ec66d91d1377eeea682eef31e60017a /Lib/decimal.py | |
parent | f48ea7c2a950c81b98c6e689fc51c99598546bb4 (diff) | |
download | cpython-a123631a5ca464c99faf039ee5c74ec9025d5d64.zip cpython-a123631a5ca464c99faf039ee5c74ec9025d5d64.tar.gz cpython-a123631a5ca464c99faf039ee5c74ec9025d5d64.tar.bz2 |
Fix a performance issue in Decimal.pow. Thanks Stefan Krah for finding this.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 828027c..71408a8 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -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 |