MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _richcmp

Method _richcmp

tools/python-3.11.9-amd64/Lib/fractions.py:699–719  ·  view source on GitHub ↗

Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one

(self, other, op)

Source from the content-addressed store, hash-verified

697 return NotImplemented
698
699 def _richcmp(self, other, op):
700 """Helper for comparison operators, for internal use only.
701
702 Implement comparison between a Rational instance `self`, and
703 either another Rational instance or a float `other`. If
704 `other` is not a Rational instance or a float, return
705 NotImplemented. `op` should be one of the six standard
706 comparison operators.
707
708 """
709 # convert other to a Rational instance where reasonable.
710 if isinstance(other, numbers.Rational):
711 return op(self._numerator * other.denominator,
712 self._denominator * other.numerator)
713 if isinstance(other, float):
714 if math.isnan(other) or math.isinf(other):
715 return op(0.0, other)
716 else:
717 return op(self, self.from_float(other))
718 else:
719 return NotImplemented
720
721 def __lt__(a, b):
722 """a < b"""

Callers 4

__lt__Method · 0.80
__gt__Method · 0.80
__le__Method · 0.80
__ge__Method · 0.80

Calls 1

from_floatMethod · 0.95

Tested by

no test coverage detected