Lines Matching refs:other
86 def __add__(self, other):
88 if isint(other):
89 other = Rat(other)
90 if isRat(other):
91 return Rat(self.__num*other.__den + other.__num*self.__den,
92 self.__den*other.__den)
93 if isnum(other):
94 return float(self) + other
99 def __sub__(self, other):
101 if isint(other):
102 other = Rat(other)
103 if isRat(other):
104 return Rat(self.__num*other.__den - other.__num*self.__den,
105 self.__den*other.__den)
106 if isnum(other):
107 return float(self) - other
110 def __rsub__(self, other):
112 if isint(other):
113 other = Rat(other)
114 if isRat(other):
115 return Rat(other.__num*self.__den - self.__num*other.__den,
116 self.__den*other.__den)
117 if isnum(other):
118 return other - float(self)
121 def __mul__(self, other):
123 if isRat(other):
124 return Rat(self.__num*other.__num, self.__den*other.__den)
125 if isint(other):
126 return Rat(self.__num*other, self.__den)
127 if isnum(other):
128 return float(self)*other
133 def __truediv__(self, other):
135 if isRat(other):
136 return Rat(self.__num*other.__den, self.__den*other.__num)
137 if isint(other):
138 return Rat(self.__num, self.__den*other)
139 if isnum(other):
140 return float(self) / other
145 def __rtruediv__(self, other):
147 if isRat(other):
148 return Rat(other.__num*self.__den, other.__den*self.__num)
149 if isint(other):
150 return Rat(other*self.__den, self.__num)
151 if isnum(other):
152 return other / float(self)
157 def __floordiv__(self, other):
159 if isint(other):
160 other = Rat(other)
161 elif not isRat(other):
163 x = self/other
166 def __rfloordiv__(self, other):
168 x = other/self
171 def __divmod__(self, other):
173 if isint(other):
174 other = Rat(other)
175 elif not isRat(other):
177 x = self//other
178 return (x, self - other * x)
180 def __rdivmod__(self, other):
182 if isint(other):
183 other = Rat(other)
184 elif not isRat(other):
186 return divmod(other, self)
188 def __mod__(self, other):
190 return divmod(self, other)[1]
192 def __rmod__(self, other):
194 return divmod(other, self)[1]
196 def __eq__(self, other):
198 if isint(other):
199 return self.__den == 1 and self.__num == other
200 if isRat(other):
201 return self.__num == other.__num and self.__den == other.__den
202 if isnum(other):
203 return float(self) == other
206 def __ne__(self, other):
208 return not self == other