summaryrefslogtreecommitdiff
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-07-08 19:03:34 +0000
committerMark Dickinson <dickinsm@gmail.com>2010-07-08 19:03:34 +0000
commite84b68d9d51dccad26e7e7dfa53439bcd14a0ffd (patch)
tree914687e3bda753594c320ce8a34cd2d2dac1bfe3 /Lib/decimal.py
parent4dee114c8ed083654049d6901f4ce132eb955ec0 (diff)
downloadcpython-e84b68d9d51dccad26e7e7dfa53439bcd14a0ffd.tar.gz
Fix a performance issue in Decimal.pow. Thanks Stefan Krah for finding this.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 828027cd61..71408a8e9e 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