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__.
........
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 @@
# 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 @@
# 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: