@@ -938,15 +938,13 @@ def __add__(self, other, context=None):
938938 sign = 1
939939 return Decimal ( (sign , (0 ,), exp ))
940940 if not self :
941- if exp < other ._exp - context .prec - 1 :
942- exp = other ._exp - context .prec - 1
941+ exp = max (exp , other ._exp - context .prec - 1 )
943942 ans = other ._rescale (exp , watchexp = 0 , context = context )
944943 if shouldround :
945944 ans = ans ._fix (context )
946945 return ans
947946 if not other :
948- if exp < self ._exp - context .prec - 1 :
949- exp = self ._exp - context .prec - 1
947+ exp = max (exp , self ._exp - context .prec - 1 )
950948 ans = self ._rescale (exp , watchexp = 0 , context = context )
951949 if shouldround :
952950 ans = ans ._fix (context )
@@ -1228,7 +1226,6 @@ def _divide(self, other, divmod = 0, context=None):
12281226 if divmod and res .exp > context .prec + 1 :
12291227 return context ._raise_error (DivisionImpossible )
12301228
1231- ans = None
12321229 prec_limit = 10 ** context .prec
12331230 while 1 :
12341231 while op2 .int <= op1 .int :
@@ -1454,24 +1451,25 @@ def _fix(self, context):
14541451 if context is None :
14551452 context = getcontext ()
14561453 prec = context .prec
1457- ans = self ._fixexponents (prec , context )
1454+ ans = self ._fixexponents (context )
14581455 if len (ans ._int ) > prec :
14591456 ans = ans ._round (prec , context = context )
1460- ans = ans ._fixexponents (prec , context )
1457+ ans = ans ._fixexponents (context )
14611458 return ans
14621459
1463- def _fixexponents (self , prec , context ):
1460+ def _fixexponents (self , context ):
14641461 """Fix the exponents and return a copy with the exponent in bounds.
14651462 Only call if known to not be a special value.
14661463 """
14671464 folddown = context ._clamp
14681465 Emin = context .Emin
1469- ans = Decimal ( self )
1466+ ans = self
14701467 ans_adjusted = ans .adjusted ()
14711468 if ans_adjusted < Emin :
14721469 Etiny = context .Etiny ()
14731470 if ans ._exp < Etiny :
14741471 if not ans :
1472+ ans = Decimal (self )
14751473 ans ._exp = Etiny
14761474 context ._raise_error (Clamped )
14771475 return ans
@@ -1493,6 +1491,7 @@ def _fixexponents(self, prec, context):
14931491 Emax = context .Emax
14941492 if ans_adjusted > Emax :
14951493 if not ans :
1494+ ans = Decimal (self )
14961495 ans ._exp = Emax
14971496 context ._raise_error (Clamped )
14981497 return ans
@@ -1508,7 +1507,6 @@ def _round(self, prec=None, rounding=None, context=None):
15081507 context determines it.
15091508 """
15101509
1511-
15121510 if self ._is_special :
15131511 ans = self ._check_nans (context = context )
15141512 if ans :
0 commit comments