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)
| 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""" |
no test coverage detected