MCPcopy Index your code
hub / github.com/python/cpython / _cmp

Method _cmp

Lib/_pydecimal.py:771–816  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 11

__eq__Method · 0.95
__lt__Method · 0.95
__le__Method · 0.95
__gt__Method · 0.95
__ge__Method · 0.95
compareMethod · 0.95
maxMethod · 0.95
minMethod · 0.95
next_towardMethod · 0.95
max_magMethod · 0.45
min_magMethod · 0.45

Calls 2

_isinfinityMethod · 0.95
adjustedMethod · 0.95

Tested by

no test coverage detected