• Home
  • Raw
  • Download

Lines Matching refs:math

9 import math
200 if math.isnan(expected) and math.isnan(got):
203 elif math.isinf(expected) or math.isinf(got):
254 self.ftest('pi', math.pi, 3.141592653589793238462643)
255 self.ftest('e', math.e, 2.718281828459045235360287)
256 self.assertEqual(math.tau, 2*math.pi)
259 self.assertRaises(TypeError, math.acos)
260 self.ftest('acos(-1)', math.acos(-1), math.pi)
261 self.ftest('acos(0)', math.acos(0), math.pi/2)
262 self.ftest('acos(1)', math.acos(1), 0)
263 self.assertRaises(ValueError, math.acos, INF)
264 self.assertRaises(ValueError, math.acos, NINF)
265 self.assertRaises(ValueError, math.acos, 1 + eps)
266 self.assertRaises(ValueError, math.acos, -1 - eps)
267 self.assertTrue(math.isnan(math.acos(NAN)))
270 self.assertRaises(TypeError, math.acosh)
271 self.ftest('acosh(1)', math.acosh(1), 0)
272 self.ftest('acosh(2)', math.acosh(2), 1.3169578969248168)
273 self.assertRaises(ValueError, math.acosh, 0)
274 self.assertRaises(ValueError, math.acosh, -1)
275 self.assertEqual(math.acosh(INF), INF)
276 self.assertRaises(ValueError, math.acosh, NINF)
277 self.assertTrue(math.isnan(math.acosh(NAN)))
280 self.assertRaises(TypeError, math.asin)
281 self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
282 self.ftest('asin(0)', math.asin(0), 0)
283 self.ftest('asin(1)', math.asin(1), math.pi/2)
284 self.assertRaises(ValueError, math.asin, INF)
285 self.assertRaises(ValueError, math.asin, NINF)
286 self.assertRaises(ValueError, math.asin, 1 + eps)
287 self.assertRaises(ValueError, math.asin, -1 - eps)
288 self.assertTrue(math.isnan(math.asin(NAN)))
291 self.assertRaises(TypeError, math.asinh)
292 self.ftest('asinh(0)', math.asinh(0), 0)
293 self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305)
294 self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305)
295 self.assertEqual(math.asinh(INF), INF)
296 self.assertEqual(math.asinh(NINF), NINF)
297 self.assertTrue(math.isnan(math.asinh(NAN)))
300 self.assertRaises(TypeError, math.atan)
301 self.ftest('atan(-1)', math.atan(-1), -math.pi/4)
302 self.ftest('atan(0)', math.atan(0), 0)
303 self.ftest('atan(1)', math.atan(1), math.pi/4)
304 self.ftest('atan(inf)', math.atan(INF), math.pi/2)
305 self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2)
306 self.assertTrue(math.isnan(math.atan(NAN)))
309 self.assertRaises(TypeError, math.atan)
310 self.ftest('atanh(0)', math.atanh(0), 0)
311 self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
312 self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
313 self.assertRaises(ValueError, math.atanh, 1)
314 self.assertRaises(ValueError, math.atanh, -1)
315 self.assertRaises(ValueError, math.atanh, INF)
316 self.assertRaises(ValueError, math.atanh, NINF)
317 self.assertTrue(math.isnan(math.atanh(NAN)))
320 self.assertRaises(TypeError, math.atan2)
321 self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2)
322 self.ftest('atan2(-1, 1)', math.atan2(-1, 1), -math.pi/4)
323 self.ftest('atan2(0, 1)', math.atan2(0, 1), 0)
324 self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4)
325 self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2)
328 self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
329 self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi)
330 self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi)
331 self.assertEqual(math.atan2(0., 0.), 0.)
332 self.assertEqual(math.atan2(0., 2.3), 0.)
333 self.assertEqual(math.atan2(0., INF), 0.)
334 self.assertTrue(math.isnan(math.atan2(0., NAN)))
336 self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi)
337 self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi)
338 self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi)
339 self.assertEqual(math.atan2(-0., 0.), -0.)
340 self.assertEqual(math.atan2(-0., 2.3), -0.)
341 self.assertEqual(math.atan2(-0., INF), -0.)
342 self.assertTrue(math.isnan(math.atan2(-0., NAN)))
344 self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4)
345 self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2)
346 self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2)
347 self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2)
348 self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2)
349 self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4)
350 self.assertTrue(math.isnan(math.atan2(INF, NAN)))
352 self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4)
353 self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2)
354 self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2)
355 self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2)
356 self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2)
357 self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4)
358 self.assertTrue(math.isnan(math.atan2(NINF, NAN)))
360 self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi)
361 self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2)
362 self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2)
363 self.assertEqual(math.atan2(2.3, INF), 0.)
364 self.assertTrue(math.isnan(math.atan2(2.3, NAN)))
366 self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi)
367 self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2)
368 self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2)
369 self.assertEqual(math.atan2(-2.3, INF), -0.)
370 self.assertTrue(math.isnan(math.atan2(-2.3, NAN)))
372 self.assertTrue(math.isnan(math.atan2(NAN, NINF)))
373 self.assertTrue(math.isnan(math.atan2(NAN, -2.3)))
374 self.assertTrue(math.isnan(math.atan2(NAN, -0.)))
375 self.assertTrue(math.isnan(math.atan2(NAN, 0.)))
376 self.assertTrue(math.isnan(math.atan2(NAN, 2.3)))
377 self.assertTrue(math.isnan(math.atan2(NAN, INF)))
378 self.assertTrue(math.isnan(math.atan2(NAN, NAN)))
381 self.assertRaises(TypeError, math.ceil)
382 self.assertEqual(int, type(math.ceil(0.5)))
383 self.assertEqual(math.ceil(0.5), 1)
384 self.assertEqual(math.ceil(1.0), 1)
385 self.assertEqual(math.ceil(1.5), 2)
386 self.assertEqual(math.ceil(-0.5), 0)
387 self.assertEqual(math.ceil(-1.0), -1)
388 self.assertEqual(math.ceil(-1.5), -1)
389 self.assertEqual(math.ceil(0.0), 0)
390 self.assertEqual(math.ceil(-0.0), 0)
403 self.assertEqual(math.ceil(TestCeil()), 42)
404 self.assertEqual(math.ceil(FloatCeil()), 42)
405 self.assertEqual(math.ceil(FloatLike(42.5)), 43)
406 self.assertRaises(TypeError, math.ceil, TestNoCeil())
410 self.assertRaises(TypeError, math.ceil, t)
411 self.assertRaises(TypeError, math.ceil, t, 0)
415 self.assertEqual(math.copysign(1, 42), 1.0)
416 self.assertEqual(math.copysign(0., 42), 0.0)
417 self.assertEqual(math.copysign(1., -42), -1.0)
418 self.assertEqual(math.copysign(3, 0.), 3.0)
419 self.assertEqual(math.copysign(4., -0.), -4.0)
421 self.assertRaises(TypeError, math.copysign)
423 self.assertEqual(math.copysign(1., 0.), 1.)
424 self.assertEqual(math.copysign(1., -0.), -1.)
425 self.assertEqual(math.copysign(INF, 0.), INF)
426 self.assertEqual(math.copysign(INF, -0.), NINF)
427 self.assertEqual(math.copysign(NINF, 0.), INF)
428 self.assertEqual(math.copysign(NINF, -0.), NINF)
430 self.assertEqual(math.copysign(1., INF), 1.)
431 self.assertEqual(math.copysign(1., NINF), -1.)
432 self.assertEqual(math.copysign(INF, INF), INF)
433 self.assertEqual(math.copysign(INF, NINF), NINF)
434 self.assertEqual(math.copysign(NINF, INF), INF)
435 self.assertEqual(math.copysign(NINF, NINF), NINF)
436 self.assertTrue(math.isnan(math.copysign(NAN, 1.)))
437 self.assertTrue(math.isnan(math.copysign(NAN, INF)))
438 self.assertTrue(math.isnan(math.copysign(NAN, NINF)))
439 self.assertTrue(math.isnan(math.copysign(NAN, NAN)))
443 self.assertTrue(math.isinf(math.copysign(INF, NAN)))
445 self.assertEqual(abs(math.copysign(2., NAN)), 2.)
448 self.assertRaises(TypeError, math.cos)
449 self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0, abs_tol=math.ulp(1))
450 self.ftest('cos(0)', math.cos(0), 1)
451 self.ftest('cos(pi/2)', math.cos(math.pi/2), 0, abs_tol=math.ulp(1))
452 self.ftest('cos(pi)', math.cos(math.pi), -1)
454 self.assertTrue(math.isnan(math.cos(INF)))
455 self.assertTrue(math.isnan(math.cos(NINF)))
457 self.assertRaises(ValueError, math.cos, INF)
458 self.assertRaises(ValueError, math.cos, NINF)
459 self.assertTrue(math.isnan(math.cos(NAN)))
464 self.assertRaises(TypeError, math.cosh)
465 self.ftest('cosh(0)', math.cosh(0), 1)
466 self.ftest('cosh(2)-2*cosh(1)**2', math.cosh(2)-2*math.cosh(1)**2, -1) # Thanks to Lambert
467 self.assertEqual(math.cosh(INF), INF)
468 self.assertEqual(math.cosh(NINF), INF)
469 self.assertTrue(math.isnan(math.cosh(NAN)))
472 self.assertRaises(TypeError, math.degrees)
473 self.ftest('degrees(pi)', math.degrees(math.pi), 180.0)
474 self.ftest('degrees(pi/2)', math.degrees(math.pi/2), 90.0)
475 self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0)
476 self.ftest('degrees(0)', math.degrees(0), 0)
479 self.assertRaises(TypeError, math.exp)
480 self.ftest('exp(-1)', math.exp(-1), 1/math.e)
481 self.ftest('exp(0)', math.exp(0), 1)
482 self.ftest('exp(1)', math.exp(1), math.e)
483 self.assertEqual(math.exp(INF), INF)
484 self.assertEqual(math.exp(NINF), 0.)
485 self.assertTrue(math.isnan(math.exp(NAN)))
486 self.assertRaises(OverflowError, math.exp, 1000000)
489 self.assertRaises(TypeError, math.fabs)
490 self.ftest('fabs(-1)', math.fabs(-1), 1)
491 self.ftest('fabs(0)', math.fabs(0), 0)
492 self.ftest('fabs(1)', math.fabs(1), 1)
495 self.assertEqual(math.factorial(0), 1)
499 self.assertEqual(math.factorial(i), total)
500 self.assertEqual(math.factorial(i), py_factorial(i))
501 self.assertRaises(ValueError, math.factorial, -1)
502 self.assertRaises(ValueError, math.factorial, -10**100)
505 self.assertRaises(TypeError, math.factorial, 5.0)
506 self.assertRaises(TypeError, math.factorial, 5.2)
507 self.assertRaises(TypeError, math.factorial, -1.0)
508 self.assertRaises(TypeError, math.factorial, -1e100)
509 self.assertRaises(TypeError, math.factorial, decimal.Decimal('5'))
510 self.assertRaises(TypeError, math.factorial, decimal.Decimal('5.2'))
511 self.assertRaises(TypeError, math.factorial, "5")
518 self.assertRaises(OverflowError, math.factorial, 10**100)
519 self.assertRaises(TypeError, math.factorial, 1e100)
522 self.assertRaises(TypeError, math.floor)
523 self.assertEqual(int, type(math.floor(0.5)))
524 self.assertEqual(math.floor(0.5), 0)
525 self.assertEqual(math.floor(1.0), 1)
526 self.assertEqual(math.floor(1.5), 1)
527 self.assertEqual(math.floor(-0.5), -1)
528 self.assertEqual(math.floor(-1.0), -1)
529 self.assertEqual(math.floor(-1.5), -2)
542 self.assertEqual(math.floor(TestFloor()), 42)
543 self.assertEqual(math.floor(FloatFloor()), 42)
544 self.assertEqual(math.floor(FloatLike(41.9)), 41)
545 self.assertRaises(TypeError, math.floor, TestNoFloor())
549 self.assertRaises(TypeError, math.floor, t)
550 self.assertRaises(TypeError, math.floor, t, 0)
553 self.assertRaises(TypeError, math.fmod)
554 self.ftest('fmod(10, 1)', math.fmod(10, 1), 0.0)
555 self.ftest('fmod(10, 0.5)', math.fmod(10, 0.5), 0.0)
556 self.ftest('fmod(10, 1.5)', math.fmod(10, 1.5), 1.0)
557 self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
558 self.ftest('fmod(-10, 0.5)', math.fmod(-10, 0.5), -0.0)
559 self.ftest('fmod(-10, 1.5)', math.fmod(-10, 1.5), -1.0)
560 self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
561 self.assertTrue(math.isnan(math.fmod(1., NAN)))
562 self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
563 self.assertRaises(ValueError, math.fmod, 1., 0.)
564 self.assertRaises(ValueError, math.fmod, INF, 1.)
565 self.assertRaises(ValueError, math.fmod, NINF, 1.)
566 self.assertRaises(ValueError, math.fmod, INF, 0.)
567 self.assertEqual(math.fmod(3.0, INF), 3.0)
568 self.assertEqual(math.fmod(-3.0, INF), -3.0)
569 self.assertEqual(math.fmod(3.0, NINF), 3.0)
570 self.assertEqual(math.fmod(-3.0, NINF), -3.0)
571 self.assertEqual(math.fmod(0.0, 3.0), 0.0)
572 self.assertEqual(math.fmod(0.0, NINF), 0.0)
575 self.assertRaises(TypeError, math.frexp)
583 testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1))
584 testfrexp('frexp(0)', math.frexp(0), (0, 0))
585 testfrexp('frexp(1)', math.frexp(1), (0.5, 1))
586 testfrexp('frexp(2)', math.frexp(2), (0.5, 2))
588 self.assertEqual(math.frexp(INF)[0], INF)
589 self.assertEqual(math.frexp(NINF)[0], NINF)
590 self.assertTrue(math.isnan(math.frexp(NAN)[0]))
619 mant, exp = math.frexp(x)
620 mant, exp = int(math.ldexp(mant, mant_dig)), exp - mant_dig
636 return math.ldexp(tmant, texp)
667 actual = math.fsum(vals)
687 self.assertEqual(msum(vals), math.fsum(vals))
690 gcd = math.gcd
735 hypot = math.hypot
739 args = math.e, math.pi, math.sqrt(2.0), math.gamma(3.5), math.sin(2.1)
743 math.sqrt(sum(s**2 for s in args[:i]))
751 self.assertEqual(hypot(bool(1), bool(0), bool(1), bool(1)), math.sqrt(3))
758 math.copysign(1.0, hypot(-0.0)) # Convert negative zero to positive zero
788 self.assertTrue(math.isnan(hypot(NAN)))
789 self.assertTrue(math.isnan(hypot(0, NAN)))
790 self.assertTrue(math.isnan(hypot(NAN, 10)))
791 self.assertTrue(math.isnan(hypot(10, NAN)))
792 self.assertTrue(math.isnan(hypot(NAN, NAN)))
793 self.assertTrue(math.isnan(hypot(NAN)))
798 self.assertTrue(math.isclose(hypot(*([fourthmax]*n)),
799 fourthmax * math.sqrt(n)))
804 self.assertEqual(math.hypot(4*scale, 3*scale), 5*scale)
821 hypot = math.hypot
873 dist = math.dist
874 sqrt = math.sqrt
911 math.copysign(1.0, dist((-0.0,), (0.0,)))
914 math.copysign(1.0, dist((0.0,), (-0.0,)))
959 if any(map(math.isinf, diffs)):
962 elif any(map(math.isnan, diffs)):
964 self.assertTrue(math.isnan(dist(p, q)))
971 self.assertTrue(math.isclose(dist(p, q), fourthmax * math.sqrt(n)))
972 self.assertTrue(math.isclose(dist(q, p), fourthmax * math.sqrt(n)))
979 self.assertEqual(math.dist(p, q), 5*scale)
980 self.assertEqual(math.dist(q, p), 5*scale)
993 s = math.isqrt(value)
1000 math.isqrt(-1)
1003 s = math.isqrt(True)
1007 s = math.isqrt(False)
1018 s = math.isqrt(IntegerLike(1729))
1023 math.isqrt(IntegerLike(-3))
1033 math.isqrt(value)
1036 lcm = math.lcm
1080 self.assertRaises(TypeError, math.ldexp)
1081 self.ftest('ldexp(0,1)', math.ldexp(0,1), 0)
1082 self.ftest('ldexp(1,1)', math.ldexp(1,1), 2)
1083 self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5)
1084 self.ftest('ldexp(-1,1)', math.ldexp(-1,1), -2)
1085 self.assertRaises(OverflowError, math.ldexp, 1., 1000000)
1086 self.assertRaises(OverflowError, math.ldexp, -1., 1000000)
1087 self.assertEqual(math.ldexp(1., -1000000), 0.)
1088 self.assertEqual(math.ldexp(-1., -1000000), -0.)
1089 self.assertEqual(math.ldexp(INF, 30), INF)
1090 self.assertEqual(math.ldexp(NINF, -213), NINF)
1091 self.assertTrue(math.isnan(math.ldexp(NAN, 0)))
1095 self.assertEqual(math.ldexp(INF, -n), INF)
1096 self.assertEqual(math.ldexp(NINF, -n), NINF)
1097 self.assertEqual(math.ldexp(1., -n), 0.)
1098 self.assertEqual(math.ldexp(-1., -n), -0.)
1099 self.assertEqual(math.ldexp(0., -n), 0.)
1100 self.assertEqual(math.ldexp(-0., -n), -0.)
1101 self.assertTrue(math.isnan(math.ldexp(NAN, -n)))
1103 self.assertRaises(OverflowError, math.ldexp, 1., n)
1104 self.assertRaises(OverflowError, math.ldexp, -1., n)
1105 self.assertEqual(math.ldexp(0., n), 0.)
1106 self.assertEqual(math.ldexp(-0., n), -0.)
1107 self.assertEqual(math.ldexp(INF, n), INF)
1108 self.assertEqual(math.ldexp(NINF, n), NINF)
1109 self.assertTrue(math.isnan(math.ldexp(NAN, n)))
1112 self.assertRaises(TypeError, math.log)
1113 self.ftest('log(1/e)', math.log(1/math.e), -1)
1114 self.ftest('log(1)', math.log(1), 0)
1115 self.ftest('log(e)', math.log(math.e), 1)
1116 self.ftest('log(32,2)', math.log(32,2), 5)
1117 self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
1118 self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
1119 self.ftest('log(10**1000)', math.log(10**1000),
1121 self.assertRaises(ValueError, math.log, -1.5)
1122 self.assertRaises(ValueError, math.log, -10**1000)
1123 self.assertRaises(ValueError, math.log, NINF)
1124 self.assertEqual(math.log(INF), INF)
1125 self.assertTrue(math.isnan(math.log(NAN)))
1128 self.assertRaises(TypeError, math.log1p)
1130 self.assertAlmostEqual(math.log1p(n), math.log1p(float(n)))
1131 self.assertRaises(ValueError, math.log1p, -1)
1132 self.assertEqual(math.log1p(INF), INF)
1136 self.assertRaises(TypeError, math.log2)
1139 self.assertEqual(math.log2(1), 0.0)
1140 self.assertEqual(math.log2(2), 1.0)
1141 self.assertEqual(math.log2(4), 2.0)
1144 self.assertEqual(math.log2(2**1023), 1023.0)
1145 self.assertEqual(math.log2(2**1024), 1024.0)
1146 self.assertEqual(math.log2(2**2000), 2000.0)
1148 self.assertRaises(ValueError, math.log2, -1.5)
1149 self.assertRaises(ValueError, math.log2, NINF)
1150 self.assertTrue(math.isnan(math.log2(NAN)))
1157 actual = [math.log2(math.ldexp(1.0, n)) for n in range(-1074, 1024)]
1162 self.assertRaises(TypeError, math.log10)
1163 self.ftest('log10(0.1)', math.log10(0.1), -1)
1164 self.ftest('log10(1)', math.log10(1), 0)
1165 self.ftest('log10(10)', math.log10(10), 1)
1166 self.ftest('log10(10**1000)', math.log10(10**1000), 1000.0)
1167 self.assertRaises(ValueError, math.log10, -1.5)
1168 self.assertRaises(ValueError, math.log10, -10**1000)
1169 self.assertRaises(ValueError, math.log10, NINF)
1170 self.assertEqual(math.log(INF), INF)
1171 self.assertTrue(math.isnan(math.log10(NAN)))
1174 self.assertRaises(TypeError, math.modf)
1182 testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0))
1183 testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))
1185 self.assertEqual(math.modf(INF), (0.0, INF))
1186 self.assertEqual(math.modf(NINF), (-0.0, NINF))
1188 modf_nan = math.modf(NAN)
1189 self.assertTrue(math.isnan(modf_nan[0]))
1190 self.assertTrue(math.isnan(modf_nan[1]))
1193 self.assertRaises(TypeError, math.pow)
1194 self.ftest('pow(0,1)', math.pow(0,1), 0)
1195 self.ftest('pow(1,0)', math.pow(1,0), 1)
1196 self.ftest('pow(2,1)', math.pow(2,1), 2)
1197 self.ftest('pow(2,-1)', math.pow(2,-1), 0.5)
1198 self.assertEqual(math.pow(INF, 1), INF)
1199 self.assertEqual(math.pow(NINF, 1), NINF)
1200 self.assertEqual((math.pow(1, INF)), 1.)
1201 self.assertEqual((math.pow(1, NINF)), 1.)
1202 self.assertTrue(math.isnan(math.pow(NAN, 1)))
1203 self.assertTrue(math.isnan(math.pow(2, NAN)))
1204 self.assertTrue(math.isnan(math.pow(0, NAN)))
1205 self.assertEqual(math.pow(1, NAN), 1)
1208 self.assertEqual(math.pow(0., INF), 0.)
1209 self.assertEqual(math.pow(0., 3.), 0.)
1210 self.assertEqual(math.pow(0., 2.3), 0.)
1211 self.assertEqual(math.pow(0., 2.), 0.)
1212 self.assertEqual(math.pow(0., 0.), 1.)
1213 self.assertEqual(math.pow(0., -0.), 1.)
1214 self.assertRaises(ValueError, math.pow, 0., -2.)
1215 self.assertRaises(ValueError, math.pow, 0., -2.3)
1216 self.assertRaises(ValueError, math.pow, 0., -3.)
1217 self.assertRaises(ValueError, math.pow, 0., NINF)
1218 self.assertTrue(math.isnan(math.pow(0., NAN)))
1221 self.assertEqual(math.pow(INF, INF), INF)
1222 self.assertEqual(math.pow(INF, 3.), INF)
1223 self.assertEqual(math.pow(INF, 2.3), INF)
1224 self.assertEqual(math.pow(INF, 2.), INF)
1225 self.assertEqual(math.pow(INF, 0.), 1.)
1226 self.assertEqual(math.pow(INF, -0.), 1.)
1227 self.assertEqual(math.pow(INF, -2.), 0.)
1228 self.assertEqual(math.pow(INF, -2.3), 0.)
1229 self.assertEqual(math.pow(INF, -3.), 0.)
1230 self.assertEqual(math.pow(INF, NINF), 0.)
1231 self.assertTrue(math.isnan(math.pow(INF, NAN)))
1234 self.assertEqual(math.pow(-0., INF), 0.)
1235 self.assertEqual(math.pow(-0., 3.), -0.)
1236 self.assertEqual(math.pow(-0., 2.3), 0.)
1237 self.assertEqual(math.pow(-0., 2.), 0.)
1238 self.assertEqual(math.pow(-0., 0.), 1.)
1239 self.assertEqual(math.pow(-0., -0.), 1.)
1240 self.assertRaises(ValueError, math.pow, -0., -2.)
1241 self.assertRaises(ValueError, math.pow, -0., -2.3)
1242 self.assertRaises(ValueError, math.pow, -0., -3.)
1243 self.assertRaises(ValueError, math.pow, -0., NINF)
1244 self.assertTrue(math.isnan(math.pow(-0., NAN)))
1247 self.assertEqual(math.pow(NINF, INF), INF)
1248 self.assertEqual(math.pow(NINF, 3.), NINF)
1249 self.assertEqual(math.pow(NINF, 2.3), INF)
1250 self.assertEqual(math.pow(NINF, 2.), INF)
1251 self.assertEqual(math.pow(NINF, 0.), 1.)
1252 self.assertEqual(math.pow(NINF, -0.), 1.)
1253 self.assertEqual(math.pow(NINF, -2.), 0.)
1254 self.assertEqual(math.pow(NINF, -2.3), 0.)
1255 self.assertEqual(math.pow(NINF, -3.), -0.)
1256 self.assertEqual(math.pow(NINF, NINF), 0.)
1257 self.assertTrue(math.isnan(math.pow(NINF, NAN)))
1260 self.assertEqual(math.pow(-1., INF), 1.)
1261 self.assertEqual(math.pow(-1., 3.), -1.)
1262 self.assertRaises(ValueError, math.pow, -1., 2.3)
1263 self.assertEqual(math.pow(-1., 2.), 1.)
1264 self.assertEqual(math.pow(-1., 0.), 1.)
1265 self.assertEqual(math.pow(-1., -0.), 1.)
1266 self.assertEqual(math.pow(-1., -2.), 1.)
1267 self.assertRaises(ValueError, math.pow, -1., -2.3)
1268 self.assertEqual(math.pow(-1., -3.), -1.)
1269 self.assertEqual(math.pow(-1., NINF), 1.)
1270 self.assertTrue(math.isnan(math.pow(-1., NAN)))
1273 self.assertEqual(math.pow(1., INF), 1.)
1274 self.assertEqual(math.pow(1., 3.), 1.)
1275 self.assertEqual(math.pow(1., 2.3), 1.)
1276 self.assertEqual(math.pow(1., 2.), 1.)
1277 self.assertEqual(math.pow(1., 0.), 1.)
1278 self.assertEqual(math.pow(1., -0.), 1.)
1279 self.assertEqual(math.pow(1., -2.), 1.)
1280 self.assertEqual(math.pow(1., -2.3), 1.)
1281 self.assertEqual(math.pow(1., -3.), 1.)
1282 self.assertEqual(math.pow(1., NINF), 1.)
1283 self.assertEqual(math.pow(1., NAN), 1.)
1286 self.assertEqual(math.pow(2.3, 0.), 1.)
1287 self.assertEqual(math.pow(-2.3, 0.), 1.)
1288 self.assertEqual(math.pow(NAN, 0.), 1.)
1289 self.assertEqual(math.pow(2.3, -0.), 1.)
1290 self.assertEqual(math.pow(-2.3, -0.), 1.)
1291 self.assertEqual(math.pow(NAN, -0.), 1.)
1294 self.assertRaises(ValueError, math.pow, -1., 2.3)
1295 self.assertRaises(ValueError, math.pow, -15., -3.1)
1298 self.assertEqual(math.pow(1.9, NINF), 0.)
1299 self.assertEqual(math.pow(1.1, NINF), 0.)
1300 self.assertEqual(math.pow(0.9, NINF), INF)
1301 self.assertEqual(math.pow(0.1, NINF), INF)
1302 self.assertEqual(math.pow(-0.1, NINF), INF)
1303 self.assertEqual(math.pow(-0.9, NINF), INF)
1304 self.assertEqual(math.pow(-1.1, NINF), 0.)
1305 self.assertEqual(math.pow(-1.9, NINF), 0.)
1308 self.assertEqual(math.pow(1.9, INF), INF)
1309 self.assertEqual(math.pow(1.1, INF), INF)
1310 self.assertEqual(math.pow(0.9, INF), 0.)
1311 self.assertEqual(math.pow(0.1, INF), 0.)
1312 self.assertEqual(math.pow(-0.1, INF), 0.)
1313 self.assertEqual(math.pow(-0.9, INF), 0.)
1314 self.assertEqual(math.pow(-1.1, INF), INF)
1315 self.assertEqual(math.pow(-1.9, INF), INF)
1318 self.ftest('(-2.)**3.', math.pow(-2.0, 3.0), -8.0)
1319 self.ftest('(-2.)**2.', math.pow(-2.0, 2.0), 4.0)
1320 self.ftest('(-2.)**1.', math.pow(-2.0, 1.0), -2.0)
1321 self.ftest('(-2.)**0.', math.pow(-2.0, 0.0), 1.0)
1322 self.ftest('(-2.)**-0.', math.pow(-2.0, -0.0), 1.0)
1323 self.ftest('(-2.)**-1.', math.pow(-2.0, -1.0), -0.5)
1324 self.ftest('(-2.)**-2.', math.pow(-2.0, -2.0), 0.25)
1325 self.ftest('(-2.)**-3.', math.pow(-2.0, -3.0), -0.125)
1326 self.assertRaises(ValueError, math.pow, -2.0, -0.5)
1327 self.assertRaises(ValueError, math.pow, -2.0, 0.5)
1342 self.assertRaises(TypeError, math.radians)
1343 self.ftest('radians(180)', math.radians(180), math.pi)
1344 self.ftest('radians(90)', math.radians(90), math.pi/2)
1345 self.ftest('radians(-45)', math.radians(-45), -math.pi/4)
1346 self.ftest('radians(0)', math.radians(0), 0)
1434 actual = math.remainder(x, y)
1449 actual = math.remainder(x, y)
1451 actual = math.remainder(-x, y)
1457 self.assertIsNaN(math.remainder(NAN, value))
1458 self.assertIsNaN(math.remainder(value, NAN))
1462 self.assertEqual(math.remainder(value, INF), value)
1463 self.assertEqual(math.remainder(value, NINF), value)
1469 math.remainder(INF, value)
1471 math.remainder(NINF, value)
1473 math.remainder(value, 0.0)
1475 math.remainder(value, -0.0)
1478 self.assertRaises(TypeError, math.sin)
1479 self.ftest('sin(0)', math.sin(0), 0)
1480 self.ftest('sin(pi/2)', math.sin(math.pi/2), 1)
1481 self.ftest('sin(-pi/2)', math.sin(-math.pi/2), -1)
1483 self.assertTrue(math.isnan(math.sin(INF)))
1484 self.assertTrue(math.isnan(math.sin(NINF)))
1486 self.assertRaises(ValueError, math.sin, INF)
1487 self.assertRaises(ValueError, math.sin, NINF)
1488 self.assertTrue(math.isnan(math.sin(NAN)))
1491 self.assertRaises(TypeError, math.sinh)
1492 self.ftest('sinh(0)', math.sinh(0), 0)
1493 self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1)
1494 self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0)
1495 self.assertEqual(math.sinh(INF), INF)
1496 self.assertEqual(math.sinh(NINF), NINF)
1497 self.assertTrue(math.isnan(math.sinh(NAN)))
1500 self.assertRaises(TypeError, math.sqrt)
1501 self.ftest('sqrt(0)', math.sqrt(0), 0)
1502 self.ftest('sqrt(1)', math.sqrt(1), 1)
1503 self.ftest('sqrt(4)', math.sqrt(4), 2)
1504 self.assertEqual(math.sqrt(INF), INF)
1505 self.assertRaises(ValueError, math.sqrt, -1)
1506 self.assertRaises(ValueError, math.sqrt, NINF)
1507 self.assertTrue(math.isnan(math.sqrt(NAN)))
1510 self.assertRaises(TypeError, math.tan)
1511 self.ftest('tan(0)', math.tan(0), 0)
1512 self.ftest('tan(pi/4)', math.tan(math.pi/4), 1)
1513 self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1)
1515 self.assertTrue(math.isnan(math.tan(INF)))
1516 self.assertTrue(math.isnan(math.tan(NINF)))
1518 self.assertRaises(ValueError, math.tan, INF)
1519 self.assertRaises(ValueError, math.tan, NINF)
1520 self.assertTrue(math.isnan(math.tan(NAN)))
1523 self.assertRaises(TypeError, math.tanh)
1524 self.ftest('tanh(0)', math.tanh(0), 0)
1525 self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0,
1526 abs_tol=math.ulp(1))
1527 self.ftest('tanh(inf)', math.tanh(INF), 1)
1528 self.ftest('tanh(-inf)', math.tanh(NINF), -1)
1529 self.assertTrue(math.isnan(math.tanh(NAN)))
1534 self.assertEqual(math.tanh(-0.), -0.)
1535 self.assertEqual(math.copysign(1., math.tanh(-0.)),
1536 math.copysign(1., -0.))
1539 self.assertEqual(math.trunc(1), 1)
1540 self.assertEqual(math.trunc(-1), -1)
1541 self.assertEqual(type(math.trunc(1)), int)
1542 self.assertEqual(type(math.trunc(1.5)), int)
1543 self.assertEqual(math.trunc(1.5), 1)
1544 self.assertEqual(math.trunc(-1.5), -1)
1545 self.assertEqual(math.trunc(1.999999), 1)
1546 self.assertEqual(math.trunc(-1.999999), -1)
1547 self.assertEqual(math.trunc(-0.999999), -0)
1548 self.assertEqual(math.trunc(-100.999), -100)
1559 self.assertEqual(math.trunc(TestTrunc()), 23)
1560 self.assertEqual(math.trunc(FloatTrunc()), 23)
1562 self.assertRaises(TypeError, math.trunc)
1563 self.assertRaises(TypeError, math.trunc, 1, 2)
1564 self.assertRaises(TypeError, math.trunc, FloatLike(23.5))
1565 self.assertRaises(TypeError, math.trunc, TestNoTrunc())
1568 self.assertTrue(math.isfinite(0.0))
1569 self.assertTrue(math.isfinite(-0.0))
1570 self.assertTrue(math.isfinite(1.0))
1571 self.assertTrue(math.isfinite(-1.0))
1572 self.assertFalse(math.isfinite(float("nan")))
1573 self.assertFalse(math.isfinite(float("inf")))
1574 self.assertFalse(math.isfinite(float("-inf")))
1577 self.assertTrue(math.isnan(float("nan")))
1578 self.assertTrue(math.isnan(float("-nan")))
1579 self.assertTrue(math.isnan(float("inf") * 0.))
1580 self.assertFalse(math.isnan(float("inf")))
1581 self.assertFalse(math.isnan(0.))
1582 self.assertFalse(math.isnan(1.))
1585 self.assertTrue(math.isinf(float("inf")))
1586 self.assertTrue(math.isinf(float("-inf")))
1587 self.assertTrue(math.isinf(1E400))
1588 self.assertTrue(math.isinf(-1E400))
1589 self.assertFalse(math.isinf(float("nan")))
1590 self.assertFalse(math.isinf(0.))
1591 self.assertFalse(math.isinf(1.))
1595 self.assertTrue(math.isnan(math.nan))
1599 self.assertTrue(math.isinf(math.inf))
1600 self.assertGreater(math.inf, 0.0)
1601 self.assertEqual(math.inf, float("inf"))
1602 self.assertEqual(-math.inf, float("-inf"))
1612 x = math.exp(-1000000000)
1624 x = math.exp(1000000000)
1635 x = math.sqrt(-1.0)
1670 func = getattr(math, fn)
1704 func = getattr(math, fn)
1766 prod = math.prod
1858 perm = math.perm
1859 factorial = math.factorial
1922 comb = math.comb
1923 factorial = math.factorial
1994 self.assertEqual(math.nextafter(4503599627370496.0, -INF),
1996 self.assertEqual(math.nextafter(4503599627370496.0, INF),
1998 self.assertEqual(math.nextafter(9223372036854775808.0, 0.0),
2000 self.assertEqual(math.nextafter(-9223372036854775808.0, 0.0),
2004 self.assertEqual(math.nextafter(1.0, -INF),
2006 self.assertEqual(math.nextafter(1.0, INF),
2010 self.assertEqual(math.nextafter(2.0, 2.0), 2.0)
2011 self.assertEqualSign(math.nextafter(-0.0, +0.0), +0.0)
2012 self.assertEqualSign(math.nextafter(+0.0, -0.0), -0.0)
2016 self.assertEqual(math.nextafter(+0.0, INF), smallest_subnormal)
2017 self.assertEqual(math.nextafter(-0.0, INF), smallest_subnormal)
2018 self.assertEqual(math.nextafter(+0.0, -INF), -smallest_subnormal)
2019 self.assertEqual(math.nextafter(-0.0, -INF), -smallest_subnormal)
2020 self.assertEqualSign(math.nextafter(smallest_subnormal, +0.0), +0.0)
2021 self.assertEqualSign(math.nextafter(-smallest_subnormal, +0.0), -0.0)
2022 self.assertEqualSign(math.nextafter(smallest_subnormal, -0.0), +0.0)
2023 self.assertEqualSign(math.nextafter(-smallest_subnormal, -0.0), -0.0)
2027 self.assertEqual(math.nextafter(INF, 0.0), largest_normal)
2028 self.assertEqual(math.nextafter(-INF, 0.0), -largest_normal)
2029 self.assertEqual(math.nextafter(largest_normal, INF), INF)
2030 self.assertEqual(math.nextafter(-largest_normal, -INF), -INF)
2033 self.assertIsNaN(math.nextafter(NAN, 1.0))
2034 self.assertIsNaN(math.nextafter(1.0, NAN))
2035 self.assertIsNaN(math.nextafter(NAN, NAN))
2039 self.assertEqual(math.ulp(1.0), sys.float_info.epsilon)
2041 self.assertEqual(math.ulp(2 ** 52), 1.0)
2042 self.assertEqual(math.ulp(2 ** 53), 2.0)
2043 self.assertEqual(math.ulp(2 ** 64), 4096.0)
2046 self.assertEqual(math.ulp(0.0),
2048 self.assertEqual(math.ulp(FLOAT_MAX),
2049 FLOAT_MAX - math.nextafter(FLOAT_MAX, -INF))
2052 self.assertEqual(math.ulp(INF), INF)
2053 self.assertIsNaN(math.ulp(math.nan))
2058 self.assertEqual(math.ulp(-x), math.ulp(x))
2067 for func in math.atan2, math.copysign, math.remainder:
2079 if not math.isnan(value):
2088 self.assertEqual(math.copysign(1.0, x), math.copysign(1.0, y))
2092 isclose = math.isclose # subclasses should override this