Lines Matching refs:Rat
26 return isinstance(x, Rat)
28 class Rat(object): class
84 other = Rat(other)
86 return Rat(self.__num*other.__den + other.__num*self.__den,
97 other = Rat(other)
99 return Rat(self.__num*other.__den - other.__num*self.__den,
108 other = Rat(other)
110 return Rat(other.__num*self.__den - self.__num*other.__den,
119 return Rat(self.__num*other.__num, self.__den*other.__den)
121 return Rat(self.__num*other, self.__den)
131 return Rat(self.__num*other.__den, self.__den*other.__num)
133 return Rat(self.__num, self.__den*other)
141 return Rat(other.__num*self.__den, other.__den*self.__num)
143 return Rat(other*self.__den, self.__num)
151 other = Rat(other)
165 other = Rat(other)
174 other = Rat(other)
216 a = Rat(10, 15)
219 a = Rat(10, -15)
222 a = Rat(-10, 15)
225 a = Rat(-10, -15)
228 a = Rat(7)
232 a = Rat(1, 0)
237 for bad in "0", 0.0, 0j, (), [], {}, None, Rat, unittest:
239 a = Rat(bad)
245 a = Rat(1, bad)
252 self.assertEqual(Rat(2, 3) + Rat(1, 3), 1)
253 self.assertEqual(Rat(2, 3) + 1, Rat(5, 3))
254 self.assertEqual(1 + Rat(2, 3), Rat(5, 3))
255 self.assertEqual(1.0 + Rat(1, 2), 1.5)
256 self.assertEqual(Rat(1, 2) + 1.0, 1.5)
259 self.assertEqual(Rat(7, 2) - Rat(7, 5), Rat(21, 10))
260 self.assertEqual(Rat(7, 5) - 1, Rat(2, 5))
261 self.assertEqual(1 - Rat(3, 5), Rat(2, 5))
262 self.assertEqual(Rat(3, 2) - 1.0, 0.5)
263 self.assertEqual(1.0 - Rat(1, 2), 0.5)
266 self.assertEqual(Rat(2, 3) * Rat(5, 7), Rat(10, 21))
267 self.assertEqual(Rat(10, 3) * 3, 10)
268 self.assertEqual(3 * Rat(10, 3), 10)
269 self.assertEqual(Rat(10, 5) * 0.5, 1.0)
270 self.assertEqual(0.5 * Rat(10, 5), 1.0)
273 self.assertEqual(Rat(10, 3) / Rat(5, 7), Rat(14, 3))
274 self.assertEqual(Rat(10, 3) / 3, Rat(10, 9))
275 self.assertEqual(2 / Rat(5), Rat(2, 5))
276 self.assertEqual(3.0 * Rat(1, 2), 1.5)
277 self.assertEqual(Rat(1, 2) * 3.0, 1.5)
280 self.assertEqual(Rat(10) // Rat(4), 2)
281 self.assertEqual(Rat(10, 3) // Rat(4, 3), 2)
282 self.assertEqual(Rat(10) // 4, 2)
283 self.assertEqual(10 // Rat(4), 2)
286 self.assertEqual(Rat(10), Rat(20, 2))
287 self.assertEqual(Rat(10), 10)
288 self.assertEqual(10, Rat(10))
289 self.assertEqual(Rat(10), 10.0)
290 self.assertEqual(10.0, Rat(10))
293 self.assertEqual(Rat(10, 3) / Rat(5, 7), Rat(14, 3))
294 self.assertEqual(Rat(10, 3) / 3, Rat(10, 9))
295 self.assertEqual(2 / Rat(5), Rat(2, 5))
296 self.assertEqual(3.0 * Rat(1, 2), 1.5)
297 self.assertEqual(Rat(1, 2) * 3.0, 1.5)