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)
| 769 | return self._is_special or self._int != '0' |
| 770 | |
| 771 | def _cmp(self, other): |
| 772 | """Compare the two non-NaN decimal instances self and other. |
| 773 | |
| 774 | Returns -1 if self < other, 0 if self == other and 1 |
| 775 | if self > other. This routine is for internal use only.""" |
| 776 | |
| 777 | if self._is_special or other._is_special: |
| 778 | self_inf = self._isinfinity() |
| 779 | other_inf = other._isinfinity() |
| 780 | if self_inf == other_inf: |
| 781 | return 0 |
| 782 | elif self_inf < other_inf: |
| 783 | return -1 |
| 784 | else: |
| 785 | return 1 |
| 786 | |
| 787 | # check for zeros; Decimal('0') == Decimal('-0') |
| 788 | if not self: |
| 789 | if not other: |
| 790 | return 0 |
| 791 | else: |
| 792 | return -((-1)**other._sign) |
| 793 | if not other: |
| 794 | return (-1)**self._sign |
| 795 | |
| 796 | # If different signs, neg one is less |
| 797 | if other._sign < self._sign: |
| 798 | return -1 |
| 799 | if self._sign < other._sign: |
| 800 | return 1 |
| 801 | |
| 802 | self_adjusted = self.adjusted() |
| 803 | other_adjusted = other.adjusted() |
| 804 | if self_adjusted == other_adjusted: |
| 805 | self_padded = self._int + '0'*(self._exp - other._exp) |
| 806 | other_padded = other._int + '0'*(other._exp - self._exp) |
| 807 | if self_padded == other_padded: |
| 808 | return 0 |
| 809 | elif self_padded < other_padded: |
| 810 | return -(-1)**self._sign |
| 811 | else: |
| 812 | return (-1)**self._sign |
| 813 | elif self_adjusted > other_adjusted: |
| 814 | return (-1)**self._sign |
| 815 | else: # self_adjusted < other_adjusted |
| 816 | return -((-1)**self._sign) |
| 817 | |
| 818 | # Note: The Decimal standard doesn't cover rich comparisons for |
| 819 | # Decimals. In particular, the specification is silent on the |