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 of t
(self, other, op)
| 1019 | return NotImplemented |
| 1020 | |
| 1021 | def _richcmp(self, other, op): |
| 1022 | """Helper for comparison operators, for internal use only. |
| 1023 | |
| 1024 | Implement comparison between a Rational instance `self`, and |
| 1025 | either another Rational instance or a float `other`. If |
| 1026 | `other` is not a Rational instance or a float, return |
| 1027 | NotImplemented. `op` should be one of the six standard |
| 1028 | comparison operators. |
| 1029 | |
| 1030 | """ |
| 1031 | # convert other to a Rational instance where reasonable. |
| 1032 | if isinstance(other, numbers.Rational): |
| 1033 | return op(self._numerator * other.denominator, |
| 1034 | self._denominator * other.numerator) |
| 1035 | if isinstance(other, float): |
| 1036 | if math.isnan(other) or math.isinf(other): |
| 1037 | return op(0.0, other) |
| 1038 | else: |
| 1039 | return op(self, self.from_float(other)) |
| 1040 | else: |
| 1041 | return NotImplemented |
| 1042 | |
| 1043 | def __lt__(a, b): |
| 1044 | """a < b""" |
no test coverage detected