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

Method compare

Lib/_pydecimal.py:879–895  ·  view source on GitHub ↗

Compare self to other. Return a decimal value: a or b is a NaN ==> Decimal('NaN') a < b ==> Decimal('-1') a == b ==> Decimal('0') a > b ==> Decimal('1')

(self, other, context=None)

Source from the content-addressed store, hash-verified

877 return self._cmp(other) >= 0
878
879 def compare(self, other, context=None):
880 """Compare self to other. Return a decimal value:
881
882 a or b is a NaN ==> Decimal('NaN')
883 a < b ==> Decimal('-1')
884 a == b ==> Decimal('0')
885 a > b ==> Decimal('1')
886 """
887 other = _convert_other(other, raiseit=True)
888
889 # Compare(NaN, NaN) = NaN
890 if (self._is_special or other and other._is_special):
891 ans = self._check_nans(other, context)
892 if ans:
893 return ans
894
895 return Decimal(self._cmp(other))
896
897 def __hash__(self):
898 """x.__hash__() <==> hash(x)"""

Callers 3

compare_signalMethod · 0.95
test_none_argsMethod · 0.95
compareMethod · 0.45

Calls 4

_check_nansMethod · 0.95
_cmpMethod · 0.95
_convert_otherFunction · 0.85
DecimalClass · 0.85

Tested by 1

test_none_argsMethod · 0.76