[Python-checkins] r68923 - in python/branches/release30-maint: Lib/decimal.py

mark.dickinson python-checkins at python.org
Sun Jan 25 11:50:40 CET 2009


Author: mark.dickinson
Date: Sun Jan 25 11:50:40 2009
New Revision: 68923

Log:
Merged revisions 68922 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r68922 | mark.dickinson | 2009-01-25 10:48:51 +0000 (Sun, 25 Jan 2009) | 9 lines
  
  Merged revisions 68920 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r68920 | mark.dickinson | 2009-01-25 10:39:15 +0000 (Sun, 25 Jan 2009) | 2 lines
    
    Remove uses of cmp from the decimal module.
  ........
................


Modified:
   python/branches/release30-maint/   (props changed)
   python/branches/release30-maint/Lib/decimal.py

Modified: python/branches/release30-maint/Lib/decimal.py
==============================================================================
--- python/branches/release30-maint/Lib/decimal.py	(original)
+++ python/branches/release30-maint/Lib/decimal.py	Sun Jan 25 11:50:40 2009
@@ -764,9 +764,16 @@
         if self > other.  This routine is for internal use only."""
 
         if self._is_special or other._is_special:
-            return cmp(self._isinfinity(), other._isinfinity())
+            self_inf = self._isinfinity()
+            other_inf = other._isinfinity()
+            if self_inf == other_inf:
+                return 0
+            elif self_inf < other_inf:
+                return -1
+            else:
+                return 1
 
-        # check for zeros;  note that cmp(0, -0) should return 0
+        # check for zeros;  Decimal('0') == Decimal('-0')
         if not self:
             if not other:
                 return 0
@@ -786,7 +793,12 @@
         if self_adjusted == other_adjusted:
             self_padded = self._int + '0'*(self._exp - other._exp)
             other_padded = other._int + '0'*(other._exp - self._exp)
-            return cmp(self_padded, other_padded) * (-1)**self._sign
+            if self_padded == other_padded:
+                return 0
+            elif self_padded < other_padded:
+                return -(-1)**self._sign
+            else:
+                return (-1)**self._sign
         elif self_adjusted > other_adjusted:
             return (-1)**self._sign
         else: # self_adjusted < other_adjusted


More information about the Python-checkins mailing list