• Home
  • Raw
  • Download

Lines Matching refs:F

14 F = fractions.Fraction  variable
27 return op(F.from_float(self.value), other)
112 self.assertEqual((0, 1), _components(F()))
113 self.assertEqual((7, 1), _components(F(7)))
114 self.assertEqual((7, 3), _components(F(F(7, 3))))
116 self.assertEqual((-1, 1), _components(F(-1, 1)))
117 self.assertEqual((-1, 1), _components(F(1, -1)))
118 self.assertEqual((1, 1), _components(F(-2, -2)))
119 self.assertEqual((1, 2), _components(F(5, 10)))
120 self.assertEqual((7, 15), _components(F(7, 15)))
121 self.assertEqual((10**23, 1), _components(F(10**23)))
123 self.assertEqual((3, 77), _components(F(F(3, 7), 11)))
124 self.assertEqual((-9, 5), _components(F(2, F(-10, 9))))
125 self.assertEqual((2486, 2485), _components(F(F(22, 7), F(355, 113))))
128 F, 12, 0)
129 self.assertRaises(TypeError, F, 1.5 + 3j)
131 self.assertRaises(TypeError, F, "3/2", 3)
132 self.assertRaises(TypeError, F, 3, 0j)
133 self.assertRaises(TypeError, F, 3, 1j)
134 self.assertRaises(TypeError, F, 1, 2, 3)
138 self.assertEqual((5, 2), _components(F(2.5)))
139 self.assertEqual((0, 1), _components(F(-0.0)))
141 _components(F(0.1)))
143 self.assertRaises(ValueError, F, float('nan'))
144 self.assertRaises(OverflowError, F, float('inf'))
145 self.assertRaises(OverflowError, F, float('-inf'))
149 _components(F(Decimal('1.1'))))
151 _components(F(Decimal('3.5e-2'))))
153 _components(F(Decimal('.000e20'))))
155 self.assertRaises(ValueError, F, Decimal('nan'))
156 self.assertRaises(ValueError, F, Decimal('snan'))
157 self.assertRaises(OverflowError, F, Decimal('inf'))
158 self.assertRaises(OverflowError, F, Decimal('-inf'))
161 self.assertEqual((5, 1), _components(F("5")))
162 self.assertEqual((3, 2), _components(F("3/2")))
163 self.assertEqual((3, 2), _components(F(" \n +3/2")))
164 self.assertEqual((-3, 2), _components(F("-3/2 ")))
165 self.assertEqual((13, 2), _components(F(" 013/02 \n ")))
166 self.assertEqual((16, 5), _components(F(" 3.2 ")))
167 self.assertEqual((-16, 5), _components(F(" -3.2 ")))
168 self.assertEqual((-3, 1), _components(F(" -3. ")))
169 self.assertEqual((3, 5), _components(F(" .6 ")))
170 self.assertEqual((1, 3125), _components(F("32.e-5")))
171 self.assertEqual((1000000, 1), _components(F("1E+06")))
172 self.assertEqual((-12300, 1), _components(F("-1.23e4")))
173 self.assertEqual((0, 1), _components(F(" .0e+0\t")))
174 self.assertEqual((0, 1), _components(F("-0.000e0")))
178 F, "3/0")
181 F, "3/")
184 F, "/2")
187 F, "3 /2")
191 F, "3/+2")
195 F, "+ 3/2")
199 F, "3a2")
203 F, "3/7.2")
207 F, "3.2/7")
211 F, ".")
214 r = F(7, 3)
227 self.assertNotEqual(F(4, 2), r)
230 self.assertRaises(TypeError, F.from_float, 3+4j)
231 self.assertEqual((10, 1), _components(F.from_float(10)))
233 self.assertEqual((bigint, 1), _components(F.from_float(bigint)))
234 self.assertEqual((0, 1), _components(F.from_float(-0.0)))
235 self.assertEqual((10, 1), _components(F.from_float(10.0)))
236 self.assertEqual((-5, 2), _components(F.from_float(-2.5)))
238 _components(F.from_float(1e23)))
239 self.assertEqual(float(10**23), float(F.from_float(1e23)))
241 _components(F.from_float(3.2)))
242 self.assertEqual(3.2, float(F.from_float(3.2)))
249 F.from_float, inf)
252 F.from_float, -inf)
255 F.from_float, nan)
258 self.assertRaises(TypeError, F.from_decimal, 3+4j)
259 self.assertEqual(F(10, 1), F.from_decimal(10))
260 self.assertEqual(F(0), F.from_decimal(Decimal("-0")))
261 self.assertEqual(F(5, 10), F.from_decimal(Decimal("0.5")))
262 self.assertEqual(F(5, 1000), F.from_decimal(Decimal("5e-3")))
263 self.assertEqual(F(5000), F.from_decimal(Decimal("5e3")))
264 self.assertEqual(1 - F(1, 10**30),
265 F.from_decimal(Decimal("0." + "9" * 30)))
270 F.from_decimal, Decimal("inf"))
273 F.from_decimal, Decimal("-inf"))
276 F.from_decimal, Decimal("nan"))
279 F.from_decimal, Decimal("snan"))
282 self.assertEqual(F(4, 6).as_integer_ratio(), (2, 3))
283 self.assertEqual(F(-4, 6).as_integer_ratio(), (-2, 3))
284 self.assertEqual(F(4, -6).as_integer_ratio(), (-2, 3))
285 self.assertEqual(F(0, 6).as_integer_ratio(), (0, 1))
288 rpi = F('3.1415926535897932')
289 self.assertEqual(rpi.limit_denominator(10000), F(355, 113))
290 self.assertEqual(-rpi.limit_denominator(10000), F(-355, 113))
291 self.assertEqual(rpi.limit_denominator(113), F(355, 113))
292 self.assertEqual(rpi.limit_denominator(112), F(333, 106))
293 self.assertEqual(F(201, 200).limit_denominator(100), F(1))
294 self.assertEqual(F(201, 200).limit_denominator(101), F(102, 101))
295 self.assertEqual(F(0).limit_denominator(10000), F(0))
299 F(1).limit_denominator, i)
302 self.assertTypedEquals(-1, math.trunc(F(-11, 10)))
303 self.assertTypedEquals(1, math.trunc(F(11, 10)))
304 self.assertTypedEquals(-2, math.floor(F(-11, 10)))
305 self.assertTypedEquals(-1, math.ceil(F(-11, 10)))
306 self.assertTypedEquals(-1, math.ceil(F(-10, 10)))
307 self.assertTypedEquals(-1, int(F(-11, 10)))
308 self.assertTypedEquals(0, round(F(-1, 10)))
309 self.assertTypedEquals(0, round(F(-5, 10)))
310 self.assertTypedEquals(-2, round(F(-15, 10)))
311 self.assertTypedEquals(-1, round(F(-7, 10)))
313 self.assertEqual(False, bool(F(0, 1)))
314 self.assertEqual(True, bool(F(3, 2)))
315 self.assertTypedEquals(0.1, float(F(1, 10)))
321 float(F(int('2'*400+'7'), int('3'*400+'1'))))
323 self.assertTypedEquals(0.1+0j, complex(F(1,10)))
352 r = F(numerator)
358 r = F(numerator)
362 self.assertTypedEquals(F(-200), round(F(-150), -2))
363 self.assertTypedEquals(F(-200), round(F(-250), -2))
364 self.assertTypedEquals(F(30), round(F(26), -1))
365 self.assertTypedEquals(F(-2, 10), round(F(-15, 100), 1))
366 self.assertTypedEquals(F(-2, 10), round(F(-25, 100), 1))
369 self.assertEqual(F(1, 2), F(1, 10) + F(2, 5))
370 self.assertEqual(F(-3, 10), F(1, 10) - F(2, 5))
371 self.assertEqual(F(1, 25), F(1, 10) * F(2, 5))
372 self.assertEqual(F(1, 4), F(1, 10) / F(2, 5))
373 self.assertTypedEquals(2, F(9, 10) // F(2, 5))
374 self.assertTypedEquals(10**23, F(10**23, 1) // F(1))
375 self.assertEqual(F(5, 6), F(7, 3) % F(3, 2))
376 self.assertEqual(F(2, 3), F(-7, 3) % F(3, 2))
377 self.assertEqual((F(1), F(5, 6)), divmod(F(7, 3), F(3, 2)))
378 self.assertEqual((F(-2), F(2, 3)), divmod(F(-7, 3), F(3, 2)))
379 self.assertEqual(F(8, 27), F(2, 3) ** F(3))
380 self.assertEqual(F(27, 8), F(2, 3) ** F(-3))
381 self.assertTypedEquals(2.0, F(4) ** F(1, 2))
382 self.assertEqual(F(1, 1), +F(1, 1))
383 z = pow(F(-1), F(1, 2))
387 p = F(-1, 2) ** 0
388 self.assertEqual(p, F(1, 1))
391 p = F(-1, 2) ** -1
392 self.assertEqual(p, F(-2, 1))
395 p = F(-1, 2) ** -2
396 self.assertEqual(p, F(4, 1))
402 F(10101010100808080808080808101010101010000000000000000,
404 F(10**35+1, 10**27+1) % F(10**27+1, 10**35-1)
407 F(7, 1901475900342344102245054808064),
408 F(-2**100, 3) % F(5, 2**100)
412 F(10101010100808080808080808101010101010000000000000000,
414 divmod(F(10**35+1, 10**27+1), F(10**27+1, 10**35-1))
418 F(-2**100, 3) // F(5, 2**100)
422 F(5, 2**100) // F(3, 2**100)
425 (1, F(2, 2**100)),
426 divmod(F(5, 2**100), F(3, 2**100))
430 F(7, 1901475900342344102245054808064)),
431 divmod(F(-2**100, 3), F(5, 2**100))
435 self.assertTypedEquals(F(11, 10), F(1, 10) + 1)
436 self.assertTypedEquals(1.1, F(1, 10) + 1.0)
437 self.assertTypedEquals(1.1 + 0j, F(1, 10) + (1.0 + 0j))
438 self.assertTypedEquals(F(11, 10), 1 + F(1, 10))
439 self.assertTypedEquals(1.1, 1.0 + F(1, 10))
440 self.assertTypedEquals(1.1 + 0j, (1.0 + 0j) + F(1, 10))
442 self.assertTypedEquals(F(-9, 10), F(1, 10) - 1)
443 self.assertTypedEquals(-0.9, F(1, 10) - 1.0)
444 self.assertTypedEquals(-0.9 + 0j, F(1, 10) - (1.0 + 0j))
445 self.assertTypedEquals(F(9, 10), 1 - F(1, 10))
446 self.assertTypedEquals(0.9, 1.0 - F(1, 10))
447 self.assertTypedEquals(0.9 + 0j, (1.0 + 0j) - F(1, 10))
449 self.assertTypedEquals(F(1, 10), F(1, 10) * 1)
450 self.assertTypedEquals(0.1, F(1, 10) * 1.0)
451 self.assertTypedEquals(0.1 + 0j, F(1, 10) * (1.0 + 0j))
452 self.assertTypedEquals(F(1, 10), 1 * F(1, 10))
453 self.assertTypedEquals(0.1, 1.0 * F(1, 10))
454 self.assertTypedEquals(0.1 + 0j, (1.0 + 0j) * F(1, 10))
456 self.assertTypedEquals(F(1, 10), F(1, 10) / 1)
457 self.assertTypedEquals(0.1, F(1, 10) / 1.0)
458 self.assertTypedEquals(0.1 + 0j, F(1, 10) / (1.0 + 0j))
459 self.assertTypedEquals(F(10, 1), 1 / F(1, 10))
460 self.assertTypedEquals(10.0, 1.0 / F(1, 10))
461 self.assertTypedEquals(10.0 + 0j, (1.0 + 0j) / F(1, 10))
463 self.assertTypedEquals(0, F(1, 10) // 1)
464 self.assertTypedEquals(0.0, F(1, 10) // 1.0)
465 self.assertTypedEquals(10, 1 // F(1, 10))
466 self.assertTypedEquals(10**23, 10**22 // F(1, 10))
467 self.assertTypedEquals(1.0 // 0.1, 1.0 // F(1, 10))
469 self.assertTypedEquals(F(1, 10), F(1, 10) % 1)
470 self.assertTypedEquals(0.1, F(1, 10) % 1.0)
471 self.assertTypedEquals(F(0, 1), 1 % F(1, 10))
472 self.assertTypedEquals(1.0 % 0.1, 1.0 % F(1, 10))
473 self.assertTypedEquals(0.1, F(1, 10) % float('inf'))
474 self.assertTypedEquals(float('-inf'), F(1, 10) % float('-inf'))
475 self.assertTypedEquals(float('inf'), F(-1, 10) % float('inf'))
476 self.assertTypedEquals(-0.1, F(-1, 10) % float('-inf'))
478 self.assertTypedTupleEquals((0, F(1, 10)), divmod(F(1, 10), 1))
479 self.assertTypedTupleEquals(divmod(0.1, 1.0), divmod(F(1, 10), 1.0))
480 self.assertTypedTupleEquals((10, F(0)), divmod(1, F(1, 10)))
481 self.assertTypedTupleEquals(divmod(1.0, 0.1), divmod(1.0, F(1, 10)))
482 self.assertTypedTupleEquals(divmod(0.1, float('inf')), divmod(F(1, 10), float('inf')))
483 self.assertTypedTupleEquals(divmod(0.1, float('-inf')), divmod(F(1, 10), float('-inf')))
484 self.assertTypedTupleEquals(divmod(-0.1, float('inf')), divmod(F(-1, 10), float('inf')))
485 self.assertTypedTupleEquals(divmod(-0.1, float('-inf')), divmod(F(-1, 10), float('-inf')))
488 self.assertTypedEquals(F(100, 1), F(1, 10) ** -2)
489 self.assertTypedEquals(F(100, 1), F(10, 1) ** 2)
490 self.assertTypedEquals(0.1, F(1, 10) ** 1.0)
491 self.assertTypedEquals(0.1 + 0j, F(1, 10) ** (1.0 + 0j))
492 self.assertTypedEquals(4 , 2 ** F(2, 1))
493 z = pow(-1, F(1, 2))
496 self.assertTypedEquals(F(1, 4) , 2 ** F(-2, 1))
497 self.assertTypedEquals(2.0 , 4 ** F(1, 2))
498 self.assertTypedEquals(0.25, 2.0 ** F(-2, 1))
499 self.assertTypedEquals(1.0 + 0j, (1.0 + 0j) ** F(1, 10))
501 F(0, 1), -2)
506 F(3,11), Decimal('3.1415926'))
508 Decimal('3.1415926'), F(3,11))
511 self.assertTrue(F(1, 2) < F(2, 3))
512 self.assertFalse(F(1, 2) < F(1, 2))
513 self.assertTrue(F(1, 2) <= F(2, 3))
514 self.assertTrue(F(1, 2) <= F(1, 2))
515 self.assertFalse(F(2, 3) <= F(1, 2))
516 self.assertTrue(F(1, 2) == F(1, 2))
517 self.assertFalse(F(1, 2) == F(1, 3))
518 self.assertFalse(F(1, 2) != F(1, 2))
519 self.assertTrue(F(1, 2) != F(1, 3))
522 self.assertTrue(F(1, 2) == DummyRational(1, 2))
523 self.assertTrue(DummyRational(1, 2) == F(1, 2))
524 self.assertFalse(F(1, 2) == DummyRational(3, 4))
525 self.assertFalse(DummyRational(3, 4) == F(1, 2))
527 self.assertTrue(F(1, 2) < DummyRational(3, 4))
528 self.assertFalse(F(1, 2) < DummyRational(1, 2))
529 self.assertFalse(F(1, 2) < DummyRational(1, 7))
530 self.assertFalse(F(1, 2) > DummyRational(3, 4))
531 self.assertFalse(F(1, 2) > DummyRational(1, 2))
532 self.assertTrue(F(1, 2) > DummyRational(1, 7))
533 self.assertTrue(F(1, 2) <= DummyRational(3, 4))
534 self.assertTrue(F(1, 2) <= DummyRational(1, 2))
535 self.assertFalse(F(1, 2) <= DummyRational(1, 7))
536 self.assertFalse(F(1, 2) >= DummyRational(3, 4))
537 self.assertTrue(F(1, 2) >= DummyRational(1, 2))
538 self.assertTrue(F(1, 2) >= DummyRational(1, 7))
540 self.assertTrue(DummyRational(1, 2) < F(3, 4))
541 self.assertFalse(DummyRational(1, 2) < F(1, 2))
542 self.assertFalse(DummyRational(1, 2) < F(1, 7))
543 self.assertFalse(DummyRational(1, 2) > F(3, 4))
544 self.assertFalse(DummyRational(1, 2) > F(1, 2))
545 self.assertTrue(DummyRational(1, 2) > F(1, 7))
546 self.assertTrue(DummyRational(1, 2) <= F(3, 4))
547 self.assertTrue(DummyRational(1, 2) <= F(1, 2))
548 self.assertFalse(DummyRational(1, 2) <= F(1, 7))
549 self.assertFalse(DummyRational(1, 2) >= F(3, 4))
550 self.assertTrue(DummyRational(1, 2) >= F(1, 2))
551 self.assertTrue(DummyRational(1, 2) >= F(1, 7))
555 y = F(1, 3)
566 self.assertTrue(2 < F(5, 2))
567 self.assertFalse(2 < F(4, 2))
568 self.assertTrue(F(5, 2) < 3)
569 self.assertFalse(F(4, 2) < 2)
571 self.assertTrue(F(1, 2) < 0.6)
572 self.assertFalse(F(1, 2) < 0.4)
573 self.assertTrue(0.4 < F(1, 2))
574 self.assertFalse(0.5 < F(1, 2))
576 self.assertFalse(float('inf') < F(1, 2))
577 self.assertTrue(float('-inf') < F(0, 10))
578 self.assertFalse(float('nan') < F(-3, 7))
579 self.assertTrue(F(1, 2) < float('inf'))
580 self.assertFalse(F(17, 12) < float('-inf'))
581 self.assertFalse(F(144, -89) < float('nan'))
584 self.assertTrue(0.5 <= F(1, 2))
585 self.assertFalse(0.6 <= F(1, 2))
586 self.assertTrue(F(1, 2) <= 0.5)
587 self.assertFalse(F(1, 2) <= 0.4)
588 self.assertTrue(2 <= F(4, 2))
589 self.assertFalse(2 <= F(3, 2))
590 self.assertTrue(F(4, 2) <= 2)
591 self.assertFalse(F(5, 2) <= 2)
593 self.assertFalse(float('inf') <= F(1, 2))
594 self.assertTrue(float('-inf') <= F(0, 10))
595 self.assertFalse(float('nan') <= F(-3, 7))
596 self.assertTrue(F(1, 2) <= float('inf'))
597 self.assertFalse(F(17, 12) <= float('-inf'))
598 self.assertFalse(F(144, -89) <= float('nan'))
602 self.assertFalse(F(10**23) == float(10**23))
604 self.assertFalse(1e23 < float(F(math.trunc(1e23) + 1)))
605 self.assertTrue(1e23 < F(math.trunc(1e23) + 1))
606 self.assertFalse(1e23 <= F(math.trunc(1e23) - 1))
607 self.assertTrue(1e23 > F(math.trunc(1e23) - 1))
608 self.assertFalse(1e23 >= F(math.trunc(1e23) + 1))
611 self.assertFalse(F(10**23) == complex(10**23))
612 self.assertRaises(TypeError, operator.gt, F(10**23), complex(10**23))
613 self.assertRaises(TypeError, operator.le, F(10**23), complex(10**23))
615 x = F(3, 8)
629 self.assertTrue(0.5 == F(1, 2))
630 self.assertFalse(0.6 == F(1, 2))
631 self.assertTrue(F(1, 2) == 0.5)
632 self.assertFalse(F(1, 2) == 0.4)
633 self.assertTrue(2 == F(4, 2))
634 self.assertFalse(2 == F(3, 2))
635 self.assertTrue(F(4, 2) == 2)
636 self.assertFalse(F(5, 2) == 2)
637 self.assertFalse(F(5, 2) == float('nan'))
638 self.assertFalse(float('nan') == F(3, 7))
639 self.assertFalse(F(5, 2) == float('inf'))
640 self.assertFalse(float('-inf') == F(2, 5))
643 self.assertEqual("Fraction(7, 3)", repr(F(7, 3)))
645 repr(F('3.1415926535')))
647 repr(F(1, -10**20)))
648 self.assertEqual("7/3", str(F(7, 3)))
649 self.assertEqual("7", str(F(7, 1)))
654 self.assertEqual(hash(2.5), hash(F(5, 2)))
655 self.assertEqual(hash(10**50), hash(F(10**50)))
656 self.assertNotEqual(hash(float(10**23)), hash(F(10**23)))
657 self.assertEqual(hinf, hash(F(1, hmod)))
660 self.assertEqual(hash(F(-1)), F(-1).__hash__())
665 three = F(3)
667 while abs(s - lasts) > F(1, 10**9):
678 x = F(1)
679 i, lasts, s, fact, num, sign = 0, 0, F(1), 1, 1, 1
680 while abs(s - lasts) > F(1, 10**9):
690 r = F(13, 7)
702 r = F(13, 7)