MCPcopy Index your code
hub / github.com/RustPython/RustPython / _cmp

Method _cmp

Lib/_pydecimal.py:768–813  ·  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

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