Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76e60d6

Browse files
committed
SF bug #1048728: Bug fixes and cleanup for decimal.py
(Contributed by Neal Norwitz. Reviewed by Facundo Bastista.)
1 parent 9414ded commit 76e60d6

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

Lib/decimal.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136

137137
import threading
138138
import copy
139-
import operator
140139

141140
#Rounding
142141
ROUND_DOWN = 'ROUND_DOWN'
@@ -1716,14 +1715,11 @@ def __pow__(self, n, modulo = None, context=None):
17161715
val = Decimal(1)
17171716
context = context._shallow_copy()
17181717
context.prec = firstprec + elength + 1
1719-
rounding = context.rounding
17201718
if n < 0:
17211719
#n is a long now, not Decimal instance
17221720
n = -n
17231721
mul = Decimal(1).__div__(mul, context=context)
17241722

1725-
shouldround = context._rounding_decision == ALWAYS_ROUND
1726-
17271723
spot = 1
17281724
while spot <= n:
17291725
spot <<= 1
@@ -1742,7 +1738,7 @@ def __pow__(self, n, modulo = None, context=None):
17421738
spot >>= 1
17431739
context.prec = firstprec
17441740

1745-
if shouldround:
1741+
if context._rounding_decision == ALWAYS_ROUND:
17461742
return val._fix(context)
17471743
return val
17481744

@@ -1823,8 +1819,6 @@ def _rescale(self, exp, rounding=None, context=None, watchexp=1):
18231819
if ans:
18241820
return ans
18251821

1826-
out = 0
1827-
18281822
if watchexp and (context.Emax < exp or context.Etiny() > exp):
18291823
return context._raise_error(InvalidOperation, 'rescale(a, INF)')
18301824

@@ -1844,7 +1838,6 @@ def _rescale(self, exp, rounding=None, context=None, watchexp=1):
18441838
tmp._int = (0,) + tmp._int
18451839
digits += 1
18461840

1847-
prevexact = context.flags[Inexact]
18481841
if digits < 0:
18491842
tmp._exp = -digits + tmp._exp
18501843
tmp._int = (0,1)
@@ -1940,7 +1933,6 @@ def sqrt(self, context=None):
19401933

19411934
half = Decimal('0.5')
19421935

1943-
count = 1
19441936
maxp = firstprec + 2
19451937
rounding = context._set_rounding(ROUND_HALF_EVEN)
19461938
while 1:
@@ -2043,8 +2035,9 @@ def max(self, other, context=None):
20432035

20442036
if context is None:
20452037
context = getcontext()
2046-
context._rounding_decision == ALWAYS_ROUND
2047-
return ans._fix(context)
2038+
if context._rounding_decision == ALWAYS_ROUND:
2039+
return ans._fix(context)
2040+
return ans
20482041

20492042
def min(self, other, context=None):
20502043
"""Returns the smaller value.
@@ -2089,8 +2082,9 @@ def min(self, other, context=None):
20892082

20902083
if context is None:
20912084
context = getcontext()
2092-
context._rounding_decision == ALWAYS_ROUND
2093-
return ans._fix(context)
2085+
if context._rounding_decision == ALWAYS_ROUND:
2086+
return ans._fix(context)
2087+
return ans
20942088

20952089
def _isinteger(self):
20962090
"""Returns whether self is an integer"""

0 commit comments

Comments
 (0)