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

Method _compare_check_nans

Lib/_pydecimal.py:731–762  ·  view source on GitHub ↗

Version of _check_nans used for the signaling comparisons compare_signal, __le__, __lt__, __ge__, __gt__. Signal InvalidOperation if either self or other is a (quiet or signaling) NaN. Signaling NaNs take precedence over quiet NaNs. Return 0 if neither oper

(self, other, context)

Source from the content-addressed store, hash-verified

729 return 0
730
731 def _compare_check_nans(self, other, context):
732 """Version of _check_nans used for the signaling comparisons
733 compare_signal, __le__, __lt__, __ge__, __gt__.
734
735 Signal InvalidOperation if either self or other is a (quiet
736 or signaling) NaN. Signaling NaNs take precedence over quiet
737 NaNs.
738
739 Return 0 if neither operand is a NaN.
740
741 """
742 if context is None:
743 context = getcontext()
744
745 if self._is_special or other._is_special:
746 if self.is_snan():
747 return context._raise_error(InvalidOperation,
748 'comparison involving sNaN',
749 self)
750 elif other.is_snan():
751 return context._raise_error(InvalidOperation,
752 'comparison involving sNaN',
753 other)
754 elif self.is_qnan():
755 return context._raise_error(InvalidOperation,
756 'comparison involving NaN',
757 self)
758 elif other.is_qnan():
759 return context._raise_error(InvalidOperation,
760 'comparison involving NaN',
761 other)
762 return 0
763
764 def __bool__(self):
765 """Return True if self is nonzero; otherwise return False.

Callers 5

__lt__Method · 0.95
__le__Method · 0.95
__gt__Method · 0.95
__ge__Method · 0.95
compare_signalMethod · 0.95

Calls 4

is_snanMethod · 0.95
is_qnanMethod · 0.95
getcontextFunction · 0.85
_raise_errorMethod · 0.80

Tested by

no test coverage detected