Subtract two Rats, or a Rat and a number.
(self, other)
| 92 | __radd__ = __add__ |
| 93 | |
| 94 | def __sub__(self, other): |
| 95 | """Subtract two Rats, or a Rat and a number.""" |
| 96 | if isint(other): |
| 97 | other = Rat(other) |
| 98 | if isRat(other): |
| 99 | return Rat(self.__num*other.__den - other.__num*self.__den, |
| 100 | self.__den*other.__den) |
| 101 | if isnum(other): |
| 102 | return float(self) - other |
| 103 | return NotImplemented |
| 104 | |
| 105 | def __rsub__(self, other): |
| 106 | """Subtract two Rats, or a Rat and a number (reversed args).""" |