summaryrefslogtreecommitdiffstats
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2004-10-26 23:38:46 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2004-10-26 23:38:46 (GMT)
commit99b5548298ffc2ae5f03bd9ef873ce45a9844f0e (patch)
tree9ea19b0728140bb8b3208229db5927db6f8f7926 /Lib/decimal.py
parentcb91900f6b7790544d00dc6aca0a200838cc97f5 (diff)
downloadcpython-99b5548298ffc2ae5f03bd9ef873ce45a9844f0e.zip
cpython-99b5548298ffc2ae5f03bd9ef873ce45a9844f0e.tar.gz
cpython-99b5548298ffc2ae5f03bd9ef873ce45a9844f0e.tar.bz2
Very few little improvements.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 7ae59d1..8870471 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -938,15 +938,13 @@ class Decimal(object):
sign = 1
return Decimal( (sign, (0,), exp))
if not self:
- if exp < other._exp - context.prec-1:
- exp = other._exp - context.prec-1
+ exp = max(exp, other._exp - context.prec-1)
ans = other._rescale(exp, watchexp=0, context=context)
if shouldround:
ans = ans._fix(context)
return ans
if not other:
- if exp < self._exp - context.prec-1:
- exp = self._exp - context.prec-1
+ exp = max(exp, self._exp - context.prec-1)
ans = self._rescale(exp, watchexp=0, context=context)
if shouldround:
ans = ans._fix(context)
@@ -1228,7 +1226,6 @@ class Decimal(object):
if divmod and res.exp > context.prec + 1:
return context._raise_error(DivisionImpossible)
- ans = None
prec_limit = 10 ** context.prec
while 1:
while op2.int <= op1.int:
@@ -1454,24 +1451,25 @@ class Decimal(object):
if context is None:
context = getcontext()
prec = context.prec
- ans = self._fixexponents(prec, context)
+ ans = self._fixexponents(context)
if len(ans._int) > prec:
ans = ans._round(prec, context=context)
- ans = ans._fixexponents(prec, context)
+ ans = ans._fixexponents(context)
return ans
- def _fixexponents(self, prec, context):
+ def _fixexponents(self, context):
"""Fix the exponents and return a copy with the exponent in bounds.
Only call if known to not be a special value.
"""
folddown = context._clamp
Emin = context.Emin
- ans = Decimal(self)
+ ans = self
ans_adjusted = ans.adjusted()
if ans_adjusted < Emin:
Etiny = context.Etiny()
if ans._exp < Etiny:
if not ans:
+ ans = Decimal(self)
ans._exp = Etiny
context._raise_error(Clamped)
return ans
@@ -1493,6 +1491,7 @@ class Decimal(object):
Emax = context.Emax
if ans_adjusted > Emax:
if not ans:
+ ans = Decimal(self)
ans._exp = Emax
context._raise_error(Clamped)
return ans
@@ -1508,7 +1507,6 @@ class Decimal(object):
context determines it.
"""
-
if self._is_special:
ans = self._check_nans(context=context)
if ans: