summaryrefslogtreecommitdiffstats
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-07-08 19:21:59 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-07-08 19:21:59 (GMT)
commit0390f504ac81c9eb2b71eea81204284f01b200a2 (patch)
tree75469bce95fe7b358b2e2a1418cab53590323880 /Lib/decimal.py
parent1a1ea285f6b314278e93e1c737dba5d009b46803 (diff)
downloadcpython-0390f504ac81c9eb2b71eea81204284f01b200a2.zip
cpython-0390f504ac81c9eb2b71eea81204284f01b200a2.tar.gz
cpython-0390f504ac81c9eb2b71eea81204284f01b200a2.tar.bz2
Merged revisions 82646,82649-82650 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82646 | mark.dickinson | 2010-07-08 18:23:40 +0100 (Thu, 08 Jul 2010) | 1 line In test_decimal, convert heuristic for skipping tests into an explicit skiplist. ........ r82649 | mark.dickinson | 2010-07-08 20:03:34 +0100 (Thu, 08 Jul 2010) | 1 line Fix a performance issue in Decimal.pow. Thanks Stefan Krah for finding this. ........ r82650 | mark.dickinson | 2010-07-08 20:09:16 +0100 (Thu, 08 Jul 2010) | 1 line Fix misplaced exactness check that was causing unnecessary work in Decimal.__pow__. ........
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index ecf0cd5..958b2f9 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -2044,12 +2044,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
@@ -2322,9 +2324,10 @@ class Decimal(object):
# try for an exact result with precision +1
if ans is None:
ans = self._power_exact(other, context.prec + 1)
- if ans is not None and result_sign == 1:
- ans = _dec_from_triple(1, ans._int, ans._exp)
- exact = True
+ if ans is not None:
+ if result_sign == 1:
+ ans = _dec_from_triple(1, ans._int, ans._exp)
+ exact = True
# usual case: inexact result, x**y computed directly as exp(y*log(x))
if ans is None: