[Python-checkins] python/dist/src/Lib decimal.py,1.28,1.29

facundobatista at users.sourceforge.net facundobatista at users.sourceforge.net
Wed Oct 27 01:38:49 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4996

Modified Files:
	decimal.py 
Log Message:
Very few little improvements.

Index: decimal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/decimal.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- decimal.py	20 Oct 2004 06:58:28 -0000	1.28
+++ decimal.py	26 Oct 2004 23:38:46 -0000	1.29
@@ -938,15 +938,13 @@
                 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 @@
         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 @@
         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 @@
                 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 @@
         context determines it.
         """
 
-
         if self._is_special:
             ans = self._check_nans(context=context)
             if ans:



More information about the Python-checkins mailing list