Lines Matching refs:math

7 import math
61 if math.isnan(x) or math.isinf(x):
67 if math.isinf(x_next):
220 if math.isnan(expected) and math.isnan(got):
223 elif math.isinf(expected) or math.isinf(got):
264 self.ftest('pi', math.pi, 3.141592653589793238462643)
265 self.ftest('e', math.e, 2.718281828459045235360287)
266 self.assertEqual(math.tau, 2*math.pi)
269 self.assertRaises(TypeError, math.acos)
270 self.ftest('acos(-1)', math.acos(-1), math.pi)
271 self.ftest('acos(0)', math.acos(0), math.pi/2)
272 self.ftest('acos(1)', math.acos(1), 0)
273 self.assertRaises(ValueError, math.acos, INF)
274 self.assertRaises(ValueError, math.acos, NINF)
275 self.assertRaises(ValueError, math.acos, 1 + eps)
276 self.assertRaises(ValueError, math.acos, -1 - eps)
277 self.assertTrue(math.isnan(math.acos(NAN)))
280 self.assertRaises(TypeError, math.acosh)
281 self.ftest('acosh(1)', math.acosh(1), 0)
282 self.ftest('acosh(2)', math.acosh(2), 1.3169578969248168)
283 self.assertRaises(ValueError, math.acosh, 0)
284 self.assertRaises(ValueError, math.acosh, -1)
285 self.assertEqual(math.acosh(INF), INF)
286 self.assertRaises(ValueError, math.acosh, NINF)
287 self.assertTrue(math.isnan(math.acosh(NAN)))
290 self.assertRaises(TypeError, math.asin)
291 self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
292 self.ftest('asin(0)', math.asin(0), 0)
293 self.ftest('asin(1)', math.asin(1), math.pi/2)
294 self.assertRaises(ValueError, math.asin, INF)
295 self.assertRaises(ValueError, math.asin, NINF)
296 self.assertRaises(ValueError, math.asin, 1 + eps)
297 self.assertRaises(ValueError, math.asin, -1 - eps)
298 self.assertTrue(math.isnan(math.asin(NAN)))
301 self.assertRaises(TypeError, math.asinh)
302 self.ftest('asinh(0)', math.asinh(0), 0)
303 self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305)
304 self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305)
305 self.assertEqual(math.asinh(INF), INF)
306 self.assertEqual(math.asinh(NINF), NINF)
307 self.assertTrue(math.isnan(math.asinh(NAN)))
310 self.assertRaises(TypeError, math.atan)
311 self.ftest('atan(-1)', math.atan(-1), -math.pi/4)
312 self.ftest('atan(0)', math.atan(0), 0)
313 self.ftest('atan(1)', math.atan(1), math.pi/4)
314 self.ftest('atan(inf)', math.atan(INF), math.pi/2)
315 self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2)
316 self.assertTrue(math.isnan(math.atan(NAN)))
319 self.assertRaises(TypeError, math.atan)
320 self.ftest('atanh(0)', math.atanh(0), 0)
321 self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
322 self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
323 self.assertRaises(ValueError, math.atanh, 1)
324 self.assertRaises(ValueError, math.atanh, -1)
325 self.assertRaises(ValueError, math.atanh, INF)
326 self.assertRaises(ValueError, math.atanh, NINF)
327 self.assertTrue(math.isnan(math.atanh(NAN)))
330 self.assertRaises(TypeError, math.atan2)
331 self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2)
332 self.ftest('atan2(-1, 1)', math.atan2(-1, 1), -math.pi/4)
333 self.ftest('atan2(0, 1)', math.atan2(0, 1), 0)
334 self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4)
335 self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2)
338 self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
339 self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi)
340 self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi)
341 self.assertEqual(math.atan2(0., 0.), 0.)
342 self.assertEqual(math.atan2(0., 2.3), 0.)
343 self.assertEqual(math.atan2(0., INF), 0.)
344 self.assertTrue(math.isnan(math.atan2(0., NAN)))
346 self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi)
347 self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi)
348 self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi)
349 self.assertEqual(math.atan2(-0., 0.), -0.)
350 self.assertEqual(math.atan2(-0., 2.3), -0.)
351 self.assertEqual(math.atan2(-0., INF), -0.)
352 self.assertTrue(math.isnan(math.atan2(-0., NAN)))
354 self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4)
355 self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2)
356 self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2)
357 self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2)
358 self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2)
359 self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4)
360 self.assertTrue(math.isnan(math.atan2(INF, NAN)))
362 self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4)
363 self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2)
364 self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2)
365 self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2)
366 self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2)
367 self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4)
368 self.assertTrue(math.isnan(math.atan2(NINF, NAN)))
370 self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi)
371 self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2)
372 self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2)
373 self.assertEqual(math.atan2(2.3, INF), 0.)
374 self.assertTrue(math.isnan(math.atan2(2.3, NAN)))
376 self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi)
377 self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2)
378 self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2)
379 self.assertEqual(math.atan2(-2.3, INF), -0.)
380 self.assertTrue(math.isnan(math.atan2(-2.3, NAN)))
382 self.assertTrue(math.isnan(math.atan2(NAN, NINF)))
383 self.assertTrue(math.isnan(math.atan2(NAN, -2.3)))
384 self.assertTrue(math.isnan(math.atan2(NAN, -0.)))
385 self.assertTrue(math.isnan(math.atan2(NAN, 0.)))
386 self.assertTrue(math.isnan(math.atan2(NAN, 2.3)))
387 self.assertTrue(math.isnan(math.atan2(NAN, INF)))
388 self.assertTrue(math.isnan(math.atan2(NAN, NAN)))
391 self.assertRaises(TypeError, math.ceil)
392 self.assertEqual(int, type(math.ceil(0.5)))
393 self.ftest('ceil(0.5)', math.ceil(0.5), 1)
394 self.ftest('ceil(1.0)', math.ceil(1.0), 1)
395 self.ftest('ceil(1.5)', math.ceil(1.5), 2)
396 self.ftest('ceil(-0.5)', math.ceil(-0.5), 0)
397 self.ftest('ceil(-1.0)', math.ceil(-1.0), -1)
398 self.ftest('ceil(-1.5)', math.ceil(-1.5), -1)
408 self.ftest('ceil(TestCeil())', math.ceil(TestCeil()), 42)
409 self.assertRaises(TypeError, math.ceil, TestNoCeil())
413 self.assertRaises(TypeError, math.ceil, t)
414 self.assertRaises(TypeError, math.ceil, t, 0)
418 self.assertEqual(math.copysign(1, 42), 1.0)
419 self.assertEqual(math.copysign(0., 42), 0.0)
420 self.assertEqual(math.copysign(1., -42), -1.0)
421 self.assertEqual(math.copysign(3, 0.), 3.0)
422 self.assertEqual(math.copysign(4., -0.), -4.0)
424 self.assertRaises(TypeError, math.copysign)
426 self.assertEqual(math.copysign(1., 0.), 1.)
427 self.assertEqual(math.copysign(1., -0.), -1.)
428 self.assertEqual(math.copysign(INF, 0.), INF)
429 self.assertEqual(math.copysign(INF, -0.), NINF)
430 self.assertEqual(math.copysign(NINF, 0.), INF)
431 self.assertEqual(math.copysign(NINF, -0.), NINF)
433 self.assertEqual(math.copysign(1., INF), 1.)
434 self.assertEqual(math.copysign(1., NINF), -1.)
435 self.assertEqual(math.copysign(INF, INF), INF)
436 self.assertEqual(math.copysign(INF, NINF), NINF)
437 self.assertEqual(math.copysign(NINF, INF), INF)
438 self.assertEqual(math.copysign(NINF, NINF), NINF)
439 self.assertTrue(math.isnan(math.copysign(NAN, 1.)))
440 self.assertTrue(math.isnan(math.copysign(NAN, INF)))
441 self.assertTrue(math.isnan(math.copysign(NAN, NINF)))
442 self.assertTrue(math.isnan(math.copysign(NAN, NAN)))
446 self.assertTrue(math.isinf(math.copysign(INF, NAN)))
448 self.assertEqual(abs(math.copysign(2., NAN)), 2.)
451 self.assertRaises(TypeError, math.cos)
452 self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0, abs_tol=ulp(1))
453 self.ftest('cos(0)', math.cos(0), 1)
454 self.ftest('cos(pi/2)', math.cos(math.pi/2), 0, abs_tol=ulp(1))
455 self.ftest('cos(pi)', math.cos(math.pi), -1)
457 self.assertTrue(math.isnan(math.cos(INF)))
458 self.assertTrue(math.isnan(math.cos(NINF)))
460 self.assertRaises(ValueError, math.cos, INF)
461 self.assertRaises(ValueError, math.cos, NINF)
462 self.assertTrue(math.isnan(math.cos(NAN)))
465 self.assertRaises(TypeError, math.cosh)
466 self.ftest('cosh(0)', math.cosh(0), 1)
467 self.ftest('cosh(2)-2*cosh(1)**2', math.cosh(2)-2*math.cosh(1)**2, -1) # Thanks to Lambert
468 self.assertEqual(math.cosh(INF), INF)
469 self.assertEqual(math.cosh(NINF), INF)
470 self.assertTrue(math.isnan(math.cosh(NAN)))
473 self.assertRaises(TypeError, math.degrees)
474 self.ftest('degrees(pi)', math.degrees(math.pi), 180.0)
475 self.ftest('degrees(pi/2)', math.degrees(math.pi/2), 90.0)
476 self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0)
477 self.ftest('degrees(0)', math.degrees(0), 0)
480 self.assertRaises(TypeError, math.exp)
481 self.ftest('exp(-1)', math.exp(-1), 1/math.e)
482 self.ftest('exp(0)', math.exp(0), 1)
483 self.ftest('exp(1)', math.exp(1), math.e)
484 self.assertEqual(math.exp(INF), INF)
485 self.assertEqual(math.exp(NINF), 0.)
486 self.assertTrue(math.isnan(math.exp(NAN)))
487 self.assertRaises(OverflowError, math.exp, 1000000)
490 self.assertRaises(TypeError, math.fabs)
491 self.ftest('fabs(-1)', math.fabs(-1), 1)
492 self.ftest('fabs(0)', math.fabs(0), 0)
493 self.ftest('fabs(1)', math.fabs(1), 1)
496 self.assertEqual(math.factorial(0), 1)
497 self.assertEqual(math.factorial(0.0), 1)
501 self.assertEqual(math.factorial(i), total)
502 self.assertEqual(math.factorial(float(i)), total)
503 self.assertEqual(math.factorial(i), py_factorial(i))
504 self.assertRaises(ValueError, math.factorial, -1)
505 self.assertRaises(ValueError, math.factorial, -1.0)
506 self.assertRaises(ValueError, math.factorial, -10**100)
507 self.assertRaises(ValueError, math.factorial, -1e100)
508 self.assertRaises(ValueError, math.factorial, math.pi)
515 self.assertRaises(OverflowError, math.factorial, 10**100)
516 self.assertRaises(OverflowError, math.factorial, 1e100)
519 self.assertRaises(TypeError, math.floor)
520 self.assertEqual(int, type(math.floor(0.5)))
521 self.ftest('floor(0.5)', math.floor(0.5), 0)
522 self.ftest('floor(1.0)', math.floor(1.0), 1)
523 self.ftest('floor(1.5)', math.floor(1.5), 1)
524 self.ftest('floor(-0.5)', math.floor(-0.5), -1)
525 self.ftest('floor(-1.0)', math.floor(-1.0), -1)
526 self.ftest('floor(-1.5)', math.floor(-1.5), -2)
529 self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167)
530 self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167)
540 self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42)
541 self.assertRaises(TypeError, math.floor, TestNoFloor())
545 self.assertRaises(TypeError, math.floor, t)
546 self.assertRaises(TypeError, math.floor, t, 0)
549 self.assertRaises(TypeError, math.fmod)
550 self.ftest('fmod(10, 1)', math.fmod(10, 1), 0.0)
551 self.ftest('fmod(10, 0.5)', math.fmod(10, 0.5), 0.0)
552 self.ftest('fmod(10, 1.5)', math.fmod(10, 1.5), 1.0)
553 self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
554 self.ftest('fmod(-10, 0.5)', math.fmod(-10, 0.5), -0.0)
555 self.ftest('fmod(-10, 1.5)', math.fmod(-10, 1.5), -1.0)
556 self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
557 self.assertTrue(math.isnan(math.fmod(1., NAN)))
558 self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
559 self.assertRaises(ValueError, math.fmod, 1., 0.)
560 self.assertRaises(ValueError, math.fmod, INF, 1.)
561 self.assertRaises(ValueError, math.fmod, NINF, 1.)
562 self.assertRaises(ValueError, math.fmod, INF, 0.)
563 self.assertEqual(math.fmod(3.0, INF), 3.0)
564 self.assertEqual(math.fmod(-3.0, INF), -3.0)
565 self.assertEqual(math.fmod(3.0, NINF), 3.0)
566 self.assertEqual(math.fmod(-3.0, NINF), -3.0)
567 self.assertEqual(math.fmod(0.0, 3.0), 0.0)
568 self.assertEqual(math.fmod(0.0, NINF), 0.0)
571 self.assertRaises(TypeError, math.frexp)
579 testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1))
580 testfrexp('frexp(0)', math.frexp(0), (0, 0))
581 testfrexp('frexp(1)', math.frexp(1), (0.5, 1))
582 testfrexp('frexp(2)', math.frexp(2), (0.5, 2))
584 self.assertEqual(math.frexp(INF)[0], INF)
585 self.assertEqual(math.frexp(NINF)[0], NINF)
586 self.assertTrue(math.isnan(math.frexp(NAN)[0]))
615 mant, exp = math.frexp(x)
616 mant, exp = int(math.ldexp(mant, mant_dig)), exp - mant_dig
632 return math.ldexp(tmant, texp)
657 actual = math.fsum(vals)
677 self.assertEqual(msum(vals), math.fsum(vals))
680 gcd = math.gcd
723 self.assertRaises(TypeError, math.hypot)
724 self.ftest('hypot(0,0)', math.hypot(0,0), 0)
725 self.ftest('hypot(3,4)', math.hypot(3,4), 5)
726 self.assertEqual(math.hypot(NAN, INF), INF)
727 self.assertEqual(math.hypot(INF, NAN), INF)
728 self.assertEqual(math.hypot(NAN, NINF), INF)
729 self.assertEqual(math.hypot(NINF, NAN), INF)
730 self.assertRaises(OverflowError, math.hypot, FLOAT_MAX, FLOAT_MAX)
731 self.assertTrue(math.isnan(math.hypot(1.0, NAN)))
732 self.assertTrue(math.isnan(math.hypot(NAN, -2.0)))
735 self.assertRaises(TypeError, math.ldexp)
736 self.ftest('ldexp(0,1)', math.ldexp(0,1), 0)
737 self.ftest('ldexp(1,1)', math.ldexp(1,1), 2)
738 self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5)
739 self.ftest('ldexp(-1,1)', math.ldexp(-1,1), -2)
740 self.assertRaises(OverflowError, math.ldexp, 1., 1000000)
741 self.assertRaises(OverflowError, math.ldexp, -1., 1000000)
742 self.assertEqual(math.ldexp(1., -1000000), 0.)
743 self.assertEqual(math.ldexp(-1., -1000000), -0.)
744 self.assertEqual(math.ldexp(INF, 30), INF)
745 self.assertEqual(math.ldexp(NINF, -213), NINF)
746 self.assertTrue(math.isnan(math.ldexp(NAN, 0)))
750 self.assertEqual(math.ldexp(INF, -n), INF)
751 self.assertEqual(math.ldexp(NINF, -n), NINF)
752 self.assertEqual(math.ldexp(1., -n), 0.)
753 self.assertEqual(math.ldexp(-1., -n), -0.)
754 self.assertEqual(math.ldexp(0., -n), 0.)
755 self.assertEqual(math.ldexp(-0., -n), -0.)
756 self.assertTrue(math.isnan(math.ldexp(NAN, -n)))
758 self.assertRaises(OverflowError, math.ldexp, 1., n)
759 self.assertRaises(OverflowError, math.ldexp, -1., n)
760 self.assertEqual(math.ldexp(0., n), 0.)
761 self.assertEqual(math.ldexp(-0., n), -0.)
762 self.assertEqual(math.ldexp(INF, n), INF)
763 self.assertEqual(math.ldexp(NINF, n), NINF)
764 self.assertTrue(math.isnan(math.ldexp(NAN, n)))
767 self.assertRaises(TypeError, math.log)
768 self.ftest('log(1/e)', math.log(1/math.e), -1)
769 self.ftest('log(1)', math.log(1), 0)
770 self.ftest('log(e)', math.log(math.e), 1)
771 self.ftest('log(32,2)', math.log(32,2), 5)
772 self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
773 self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
774 self.ftest('log(10**1000)', math.log(10**1000),
776 self.assertRaises(ValueError, math.log, -1.5)
777 self.assertRaises(ValueError, math.log, -10**1000)
778 self.assertRaises(ValueError, math.log, NINF)
779 self.assertEqual(math.log(INF), INF)
780 self.assertTrue(math.isnan(math.log(NAN)))
783 self.assertRaises(TypeError, math.log1p)
785 self.assertAlmostEqual(math.log1p(n), math.log1p(float(n)))
786 self.assertRaises(ValueError, math.log1p, -1)
787 self.assertEqual(math.log1p(INF), INF)
791 self.assertRaises(TypeError, math.log2)
794 self.assertEqual(math.log2(1), 0.0)
795 self.assertEqual(math.log2(2), 1.0)
796 self.assertEqual(math.log2(4), 2.0)
799 self.assertEqual(math.log2(2**1023), 1023.0)
800 self.assertEqual(math.log2(2**1024), 1024.0)
801 self.assertEqual(math.log2(2**2000), 2000.0)
803 self.assertRaises(ValueError, math.log2, -1.5)
804 self.assertRaises(ValueError, math.log2, NINF)
805 self.assertTrue(math.isnan(math.log2(NAN)))
812 actual = [math.log2(math.ldexp(1.0, n)) for n in range(-1074, 1024)]
817 self.assertRaises(TypeError, math.log10)
818 self.ftest('log10(0.1)', math.log10(0.1), -1)
819 self.ftest('log10(1)', math.log10(1), 0)
820 self.ftest('log10(10)', math.log10(10), 1)
821 self.ftest('log10(10**1000)', math.log10(10**1000), 1000.0)
822 self.assertRaises(ValueError, math.log10, -1.5)
823 self.assertRaises(ValueError, math.log10, -10**1000)
824 self.assertRaises(ValueError, math.log10, NINF)
825 self.assertEqual(math.log(INF), INF)
826 self.assertTrue(math.isnan(math.log10(NAN)))
829 self.assertRaises(TypeError, math.modf)
837 testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0))
838 testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))
840 self.assertEqual(math.modf(INF), (0.0, INF))
841 self.assertEqual(math.modf(NINF), (-0.0, NINF))
843 modf_nan = math.modf(NAN)
844 self.assertTrue(math.isnan(modf_nan[0]))
845 self.assertTrue(math.isnan(modf_nan[1]))
848 self.assertRaises(TypeError, math.pow)
849 self.ftest('pow(0,1)', math.pow(0,1), 0)
850 self.ftest('pow(1,0)', math.pow(1,0), 1)
851 self.ftest('pow(2,1)', math.pow(2,1), 2)
852 self.ftest('pow(2,-1)', math.pow(2,-1), 0.5)
853 self.assertEqual(math.pow(INF, 1), INF)
854 self.assertEqual(math.pow(NINF, 1), NINF)
855 self.assertEqual((math.pow(1, INF)), 1.)
856 self.assertEqual((math.pow(1, NINF)), 1.)
857 self.assertTrue(math.isnan(math.pow(NAN, 1)))
858 self.assertTrue(math.isnan(math.pow(2, NAN)))
859 self.assertTrue(math.isnan(math.pow(0, NAN)))
860 self.assertEqual(math.pow(1, NAN), 1)
863 self.assertEqual(math.pow(0., INF), 0.)
864 self.assertEqual(math.pow(0., 3.), 0.)
865 self.assertEqual(math.pow(0., 2.3), 0.)
866 self.assertEqual(math.pow(0., 2.), 0.)
867 self.assertEqual(math.pow(0., 0.), 1.)
868 self.assertEqual(math.pow(0., -0.), 1.)
869 self.assertRaises(ValueError, math.pow, 0., -2.)
870 self.assertRaises(ValueError, math.pow, 0., -2.3)
871 self.assertRaises(ValueError, math.pow, 0., -3.)
872 self.assertRaises(ValueError, math.pow, 0., NINF)
873 self.assertTrue(math.isnan(math.pow(0., NAN)))
876 self.assertEqual(math.pow(INF, INF), INF)
877 self.assertEqual(math.pow(INF, 3.), INF)
878 self.assertEqual(math.pow(INF, 2.3), INF)
879 self.assertEqual(math.pow(INF, 2.), INF)
880 self.assertEqual(math.pow(INF, 0.), 1.)
881 self.assertEqual(math.pow(INF, -0.), 1.)
882 self.assertEqual(math.pow(INF, -2.), 0.)
883 self.assertEqual(math.pow(INF, -2.3), 0.)
884 self.assertEqual(math.pow(INF, -3.), 0.)
885 self.assertEqual(math.pow(INF, NINF), 0.)
886 self.assertTrue(math.isnan(math.pow(INF, NAN)))
889 self.assertEqual(math.pow(-0., INF), 0.)
890 self.assertEqual(math.pow(-0., 3.), -0.)
891 self.assertEqual(math.pow(-0., 2.3), 0.)
892 self.assertEqual(math.pow(-0., 2.), 0.)
893 self.assertEqual(math.pow(-0., 0.), 1.)
894 self.assertEqual(math.pow(-0., -0.), 1.)
895 self.assertRaises(ValueError, math.pow, -0., -2.)
896 self.assertRaises(ValueError, math.pow, -0., -2.3)
897 self.assertRaises(ValueError, math.pow, -0., -3.)
898 self.assertRaises(ValueError, math.pow, -0., NINF)
899 self.assertTrue(math.isnan(math.pow(-0., NAN)))
902 self.assertEqual(math.pow(NINF, INF), INF)
903 self.assertEqual(math.pow(NINF, 3.), NINF)
904 self.assertEqual(math.pow(NINF, 2.3), INF)
905 self.assertEqual(math.pow(NINF, 2.), INF)
906 self.assertEqual(math.pow(NINF, 0.), 1.)
907 self.assertEqual(math.pow(NINF, -0.), 1.)
908 self.assertEqual(math.pow(NINF, -2.), 0.)
909 self.assertEqual(math.pow(NINF, -2.3), 0.)
910 self.assertEqual(math.pow(NINF, -3.), -0.)
911 self.assertEqual(math.pow(NINF, NINF), 0.)
912 self.assertTrue(math.isnan(math.pow(NINF, NAN)))
915 self.assertEqual(math.pow(-1., INF), 1.)
916 self.assertEqual(math.pow(-1., 3.), -1.)
917 self.assertRaises(ValueError, math.pow, -1., 2.3)
918 self.assertEqual(math.pow(-1., 2.), 1.)
919 self.assertEqual(math.pow(-1., 0.), 1.)
920 self.assertEqual(math.pow(-1., -0.), 1.)
921 self.assertEqual(math.pow(-1., -2.), 1.)
922 self.assertRaises(ValueError, math.pow, -1., -2.3)
923 self.assertEqual(math.pow(-1., -3.), -1.)
924 self.assertEqual(math.pow(-1., NINF), 1.)
925 self.assertTrue(math.isnan(math.pow(-1., NAN)))
928 self.assertEqual(math.pow(1., INF), 1.)
929 self.assertEqual(math.pow(1., 3.), 1.)
930 self.assertEqual(math.pow(1., 2.3), 1.)
931 self.assertEqual(math.pow(1., 2.), 1.)
932 self.assertEqual(math.pow(1., 0.), 1.)
933 self.assertEqual(math.pow(1., -0.), 1.)
934 self.assertEqual(math.pow(1., -2.), 1.)
935 self.assertEqual(math.pow(1., -2.3), 1.)
936 self.assertEqual(math.pow(1., -3.), 1.)
937 self.assertEqual(math.pow(1., NINF), 1.)
938 self.assertEqual(math.pow(1., NAN), 1.)
941 self.assertEqual(math.pow(2.3, 0.), 1.)
942 self.assertEqual(math.pow(-2.3, 0.), 1.)
943 self.assertEqual(math.pow(NAN, 0.), 1.)
944 self.assertEqual(math.pow(2.3, -0.), 1.)
945 self.assertEqual(math.pow(-2.3, -0.), 1.)
946 self.assertEqual(math.pow(NAN, -0.), 1.)
949 self.assertRaises(ValueError, math.pow, -1., 2.3)
950 self.assertRaises(ValueError, math.pow, -15., -3.1)
953 self.assertEqual(math.pow(1.9, NINF), 0.)
954 self.assertEqual(math.pow(1.1, NINF), 0.)
955 self.assertEqual(math.pow(0.9, NINF), INF)
956 self.assertEqual(math.pow(0.1, NINF), INF)
957 self.assertEqual(math.pow(-0.1, NINF), INF)
958 self.assertEqual(math.pow(-0.9, NINF), INF)
959 self.assertEqual(math.pow(-1.1, NINF), 0.)
960 self.assertEqual(math.pow(-1.9, NINF), 0.)
963 self.assertEqual(math.pow(1.9, INF), INF)
964 self.assertEqual(math.pow(1.1, INF), INF)
965 self.assertEqual(math.pow(0.9, INF), 0.)
966 self.assertEqual(math.pow(0.1, INF), 0.)
967 self.assertEqual(math.pow(-0.1, INF), 0.)
968 self.assertEqual(math.pow(-0.9, INF), 0.)
969 self.assertEqual(math.pow(-1.1, INF), INF)
970 self.assertEqual(math.pow(-1.9, INF), INF)
973 self.ftest('(-2.)**3.', math.pow(-2.0, 3.0), -8.0)
974 self.ftest('(-2.)**2.', math.pow(-2.0, 2.0), 4.0)
975 self.ftest('(-2.)**1.', math.pow(-2.0, 1.0), -2.0)
976 self.ftest('(-2.)**0.', math.pow(-2.0, 0.0), 1.0)
977 self.ftest('(-2.)**-0.', math.pow(-2.0, -0.0), 1.0)
978 self.ftest('(-2.)**-1.', math.pow(-2.0, -1.0), -0.5)
979 self.ftest('(-2.)**-2.', math.pow(-2.0, -2.0), 0.25)
980 self.ftest('(-2.)**-3.', math.pow(-2.0, -3.0), -0.125)
981 self.assertRaises(ValueError, math.pow, -2.0, -0.5)
982 self.assertRaises(ValueError, math.pow, -2.0, 0.5)
997 self.assertRaises(TypeError, math.radians)
998 self.ftest('radians(180)', math.radians(180), math.pi)
999 self.ftest('radians(90)', math.radians(90), math.pi/2)
1000 self.ftest('radians(-45)', math.radians(-45), -math.pi/4)
1001 self.ftest('radians(0)', math.radians(0), 0)
1089 actual = math.remainder(x, y)
1104 actual = math.remainder(x, y)
1106 actual = math.remainder(-x, y)
1112 self.assertIsNaN(math.remainder(NAN, value))
1113 self.assertIsNaN(math.remainder(value, NAN))
1117 self.assertEqual(math.remainder(value, INF), value)
1118 self.assertEqual(math.remainder(value, NINF), value)
1124 math.remainder(INF, value)
1126 math.remainder(NINF, value)
1128 math.remainder(value, 0.0)
1130 math.remainder(value, -0.0)
1133 self.assertRaises(TypeError, math.sin)
1134 self.ftest('sin(0)', math.sin(0), 0)
1135 self.ftest('sin(pi/2)', math.sin(math.pi/2), 1)
1136 self.ftest('sin(-pi/2)', math.sin(-math.pi/2), -1)
1138 self.assertTrue(math.isnan(math.sin(INF)))
1139 self.assertTrue(math.isnan(math.sin(NINF)))
1141 self.assertRaises(ValueError, math.sin, INF)
1142 self.assertRaises(ValueError, math.sin, NINF)
1143 self.assertTrue(math.isnan(math.sin(NAN)))
1146 self.assertRaises(TypeError, math.sinh)
1147 self.ftest('sinh(0)', math.sinh(0), 0)
1148 self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1)
1149 self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0)
1150 self.assertEqual(math.sinh(INF), INF)
1151 self.assertEqual(math.sinh(NINF), NINF)
1152 self.assertTrue(math.isnan(math.sinh(NAN)))
1155 self.assertRaises(TypeError, math.sqrt)
1156 self.ftest('sqrt(0)', math.sqrt(0), 0)
1157 self.ftest('sqrt(1)', math.sqrt(1), 1)
1158 self.ftest('sqrt(4)', math.sqrt(4), 2)
1159 self.assertEqual(math.sqrt(INF), INF)
1160 self.assertRaises(ValueError, math.sqrt, -1)
1161 self.assertRaises(ValueError, math.sqrt, NINF)
1162 self.assertTrue(math.isnan(math.sqrt(NAN)))
1165 self.assertRaises(TypeError, math.tan)
1166 self.ftest('tan(0)', math.tan(0), 0)
1167 self.ftest('tan(pi/4)', math.tan(math.pi/4), 1)
1168 self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1)
1170 self.assertTrue(math.isnan(math.tan(INF)))
1171 self.assertTrue(math.isnan(math.tan(NINF)))
1173 self.assertRaises(ValueError, math.tan, INF)
1174 self.assertRaises(ValueError, math.tan, NINF)
1175 self.assertTrue(math.isnan(math.tan(NAN)))
1178 self.assertRaises(TypeError, math.tanh)
1179 self.ftest('tanh(0)', math.tanh(0), 0)
1180 self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0,
1182 self.ftest('tanh(inf)', math.tanh(INF), 1)
1183 self.ftest('tanh(-inf)', math.tanh(NINF), -1)
1184 self.assertTrue(math.isnan(math.tanh(NAN)))
1191 self.assertEqual(math.tanh(-0.), -0.)
1192 self.assertEqual(math.copysign(1., math.tanh(-0.)),
1193 math.copysign(1., -0.))
1196 self.assertEqual(math.trunc(1), 1)
1197 self.assertEqual(math.trunc(-1), -1)
1198 self.assertEqual(type(math.trunc(1)), int)
1199 self.assertEqual(type(math.trunc(1.5)), int)
1200 self.assertEqual(math.trunc(1.5), 1)
1201 self.assertEqual(math.trunc(-1.5), -1)
1202 self.assertEqual(math.trunc(1.999999), 1)
1203 self.assertEqual(math.trunc(-1.999999), -1)
1204 self.assertEqual(math.trunc(-0.999999), -0)
1205 self.assertEqual(math.trunc(-100.999), -100)
1214 self.assertEqual(math.trunc(TestTrunc()), 23)
1216 self.assertRaises(TypeError, math.trunc)
1217 self.assertRaises(TypeError, math.trunc, 1, 2)
1218 self.assertRaises(TypeError, math.trunc, TestNoTrunc())
1221 self.assertTrue(math.isfinite(0.0))
1222 self.assertTrue(math.isfinite(-0.0))
1223 self.assertTrue(math.isfinite(1.0))
1224 self.assertTrue(math.isfinite(-1.0))
1225 self.assertFalse(math.isfinite(float("nan")))
1226 self.assertFalse(math.isfinite(float("inf")))
1227 self.assertFalse(math.isfinite(float("-inf")))
1230 self.assertTrue(math.isnan(float("nan")))
1231 self.assertTrue(math.isnan(float("-nan")))
1232 self.assertTrue(math.isnan(float("inf") * 0.))
1233 self.assertFalse(math.isnan(float("inf")))
1234 self.assertFalse(math.isnan(0.))
1235 self.assertFalse(math.isnan(1.))
1238 self.assertTrue(math.isinf(float("inf")))
1239 self.assertTrue(math.isinf(float("-inf")))
1240 self.assertTrue(math.isinf(1E400))
1241 self.assertTrue(math.isinf(-1E400))
1242 self.assertFalse(math.isinf(float("nan")))
1243 self.assertFalse(math.isinf(0.))
1244 self.assertFalse(math.isinf(1.))
1248 self.assertTrue(math.isnan(math.nan))
1252 self.assertTrue(math.isinf(math.inf))
1253 self.assertGreater(math.inf, 0.0)
1254 self.assertEqual(math.inf, float("inf"))
1255 self.assertEqual(-math.inf, float("-inf"))
1265 x = math.exp(-1000000000)
1277 x = math.exp(1000000000)
1288 x = math.sqrt(-1.0)
1323 func = getattr(math, fn)
1357 func = getattr(math, fn)
1421 if not math.isnan(value):
1426 isclose = math.isclose # subclasses should override this