a == b
(a, b)
| 676 | return -2 if result == -1 else result |
| 677 | |
| 678 | def __eq__(a, b): |
| 679 | """a == b""" |
| 680 | if type(b) is int: |
| 681 | return a._numerator == b and a._denominator == 1 |
| 682 | if isinstance(b, numbers.Rational): |
| 683 | return (a._numerator == b.numerator and |
| 684 | a._denominator == b.denominator) |
| 685 | if isinstance(b, numbers.Complex) and b.imag == 0: |
| 686 | b = b.real |
| 687 | if isinstance(b, float): |
| 688 | if math.isnan(b) or math.isinf(b): |
| 689 | # comparisons with an infinity or nan should behave in |
| 690 | # the same way for any finite a, so treat a as zero. |
| 691 | return 0.0 == b |
| 692 | else: |
| 693 | return a == a.from_float(b) |
| 694 | else: |
| 695 | # Since a doesn't know how to compare with b, let's give b |
| 696 | # a chance to compare itself with a. |
| 697 | return NotImplemented |
| 698 | |
| 699 | def _richcmp(self, other, op): |
| 700 | """Helper for comparison operators, for internal use only. |
nothing calls this directly
no test coverage detected