diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-01-25 10:47:45 +0000 |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-01-25 10:47:45 +0000 |
commit | 8ec69bcffb0212aad7b9ddf8259bf6bca4fedfe0 (patch) | |
tree | 0046a5ad80d7e16fb4b603d64ba04325bb36a46b | |
parent | 3df16920eb7fe8e3e4b571efb50571b697600c2c (diff) | |
download | cpython-git-8ec69bcffb0212aad7b9ddf8259bf6bca4fedfe0.tar.gz |
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.
........
-rw-r--r-- | Lib/decimal.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index b0a8f7f7c8..661d6ed4af 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -760,9 +760,16 @@ class Decimal(object): 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 @@ -782,7 +789,12 @@ class Decimal(object): 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 |