Compare the two non-NaN decimal instances self and other. Returns -1 if self < other, 0 if self == other and 1 if self > other. This routine is for internal use only.
(self, other)
| 825 | return self._is_special or self._int != '0' |
| 826 | |
| 827 | def _cmp(self, other): |
| 828 | """Compare the two non-NaN decimal instances self and other. |
| 829 | |
| 830 | Returns -1 if self < other, 0 if self == other and 1 |
| 831 | if self > other. This routine is for internal use only.""" |
| 832 | |
| 833 | if self._is_special or other._is_special: |
| 834 | self_inf = self._isinfinity() |
| 835 | other_inf = other._isinfinity() |
| 836 | if self_inf == other_inf: |
| 837 | return 0 |
| 838 | elif self_inf < other_inf: |
| 839 | return -1 |
| 840 | else: |
| 841 | return 1 |
| 842 | |
| 843 | # check for zeros; Decimal('0') == Decimal('-0') |
| 844 | if not self: |
| 845 | if not other: |
| 846 | return 0 |
| 847 | else: |
| 848 | return -((-1)**other._sign) |
| 849 | if not other: |
| 850 | return (-1)**self._sign |
| 851 | |
| 852 | # If different signs, neg one is less |
| 853 | if other._sign < self._sign: |
| 854 | return -1 |
| 855 | if self._sign < other._sign: |
| 856 | return 1 |
| 857 | |
| 858 | self_adjusted = self.adjusted() |
| 859 | other_adjusted = other.adjusted() |
| 860 | if self_adjusted == other_adjusted: |
| 861 | self_padded = self._int + '0'*(self._exp - other._exp) |
| 862 | other_padded = other._int + '0'*(other._exp - self._exp) |
| 863 | if self_padded == other_padded: |
| 864 | return 0 |
| 865 | elif self_padded < other_padded: |
| 866 | return -(-1)**self._sign |
| 867 | else: |
| 868 | return (-1)**self._sign |
| 869 | elif self_adjusted > other_adjusted: |
| 870 | return (-1)**self._sign |
| 871 | else: # self_adjusted < other_adjusted |
| 872 | return -((-1)**self._sign) |
| 873 | |
| 874 | # Note: The Decimal standard doesn't cover rich comparisons for |
| 875 | # Decimals. In particular, the specification is silent on the |