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

Skip to content

Commit e6aad75

Browse files
committed
Merged revisions 68920 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 78246b6 commit e6aad75

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

Lib/decimal.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,16 @@ def _cmp(self, other):
805805
if self > other. This routine is for internal use only."""
806806

807807
if self._is_special or other._is_special:
808-
return cmp(self._isinfinity(), other._isinfinity())
808+
self_inf = self._isinfinity()
809+
other_inf = other._isinfinity()
810+
if self_inf == other_inf:
811+
return 0
812+
elif self_inf < other_inf:
813+
return -1
814+
else:
815+
return 1
809816

810-
# check for zeros; note that cmp(0, -0) should return 0
817+
# check for zeros; Decimal('0') == Decimal('-0')
811818
if not self:
812819
if not other:
813820
return 0
@@ -827,7 +834,12 @@ def _cmp(self, other):
827834
if self_adjusted == other_adjusted:
828835
self_padded = self._int + '0'*(self._exp - other._exp)
829836
other_padded = other._int + '0'*(other._exp - self._exp)
830-
return cmp(self_padded, other_padded) * (-1)**self._sign
837+
if self_padded == other_padded:
838+
return 0
839+
elif self_padded < other_padded:
840+
return -(-1)**self._sign
841+
else:
842+
return (-1)**self._sign
831843
elif self_adjusted > other_adjusted:
832844
return (-1)**self._sign
833845
else: # self_adjusted < other_adjusted

0 commit comments

Comments
 (0)