• Home
  • Raw
  • Download

Lines Matching refs:math

6 import math
71 if math.isinf(expected) and got == expected:
143 self.ftest('pi', math.pi, 3.1415926)
144 self.ftest('e', math.e, 2.7182818)
147 self.assertRaises(TypeError, math.acos)
148 self.ftest('acos(-1)', math.acos(-1), math.pi)
149 self.ftest('acos(0)', math.acos(0), math.pi/2)
150 self.ftest('acos(1)', math.acos(1), 0)
151 self.assertRaises(ValueError, math.acos, INF)
152 self.assertRaises(ValueError, math.acos, NINF)
153 self.assertTrue(math.isnan(math.acos(NAN)))
156 self.assertRaises(TypeError, math.acosh)
157 self.ftest('acosh(1)', math.acosh(1), 0)
158 self.ftest('acosh(2)', math.acosh(2), 1.3169578969248168)
159 self.assertRaises(ValueError, math.acosh, 0)
160 self.assertRaises(ValueError, math.acosh, -1)
161 self.assertEqual(math.acosh(INF), INF)
162 self.assertRaises(ValueError, math.acosh, NINF)
163 self.assertTrue(math.isnan(math.acosh(NAN)))
166 self.assertRaises(TypeError, math.asin)
167 self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
168 self.ftest('asin(0)', math.asin(0), 0)
169 self.ftest('asin(1)', math.asin(1), math.pi/2)
170 self.assertRaises(ValueError, math.asin, INF)
171 self.assertRaises(ValueError, math.asin, NINF)
172 self.assertTrue(math.isnan(math.asin(NAN)))
175 self.assertRaises(TypeError, math.asinh)
176 self.ftest('asinh(0)', math.asinh(0), 0)
177 self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305)
178 self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305)
179 self.assertEqual(math.asinh(INF), INF)
180 self.assertEqual(math.asinh(NINF), NINF)
181 self.assertTrue(math.isnan(math.asinh(NAN)))
184 self.assertRaises(TypeError, math.atan)
185 self.ftest('atan(-1)', math.atan(-1), -math.pi/4)
186 self.ftest('atan(0)', math.atan(0), 0)
187 self.ftest('atan(1)', math.atan(1), math.pi/4)
188 self.ftest('atan(inf)', math.atan(INF), math.pi/2)
189 self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2)
190 self.assertTrue(math.isnan(math.atan(NAN)))
193 self.assertRaises(TypeError, math.atan)
194 self.ftest('atanh(0)', math.atanh(0), 0)
195 self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
196 self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
197 self.assertRaises(ValueError, math.atanh, 1)
198 self.assertRaises(ValueError, math.atanh, -1)
199 self.assertRaises(ValueError, math.atanh, INF)
200 self.assertRaises(ValueError, math.atanh, NINF)
201 self.assertTrue(math.isnan(math.atanh(NAN)))
204 self.assertRaises(TypeError, math.atan2)
205 self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2)
206 self.ftest('atan2(-1, 1)', math.atan2(-1, 1), -math.pi/4)
207 self.ftest('atan2(0, 1)', math.atan2(0, 1), 0)
208 self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4)
209 self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2)
212 self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
213 self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi)
214 self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi)
215 self.assertEqual(math.atan2(0., 0.), 0.)
216 self.assertEqual(math.atan2(0., 2.3), 0.)
217 self.assertEqual(math.atan2(0., INF), 0.)
218 self.assertTrue(math.isnan(math.atan2(0., NAN)))
220 self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi)
221 self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi)
222 self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi)
223 self.assertEqual(math.atan2(-0., 0.), -0.)
224 self.assertEqual(math.atan2(-0., 2.3), -0.)
225 self.assertEqual(math.atan2(-0., INF), -0.)
226 self.assertTrue(math.isnan(math.atan2(-0., NAN)))
228 self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4)
229 self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2)
230 self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2)
231 self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2)
232 self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2)
233 self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4)
234 self.assertTrue(math.isnan(math.atan2(INF, NAN)))
236 self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4)
237 self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2)
238 self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2)
239 self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2)
240 self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2)
241 self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4)
242 self.assertTrue(math.isnan(math.atan2(NINF, NAN)))
244 self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi)
245 self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2)
246 self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2)
247 self.assertEqual(math.atan2(2.3, INF), 0.)
248 self.assertTrue(math.isnan(math.atan2(2.3, NAN)))
250 self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi)
251 self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2)
252 self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2)
253 self.assertEqual(math.atan2(-2.3, INF), -0.)
254 self.assertTrue(math.isnan(math.atan2(-2.3, NAN)))
256 self.assertTrue(math.isnan(math.atan2(NAN, NINF)))
257 self.assertTrue(math.isnan(math.atan2(NAN, -2.3)))
258 self.assertTrue(math.isnan(math.atan2(NAN, -0.)))
259 self.assertTrue(math.isnan(math.atan2(NAN, 0.)))
260 self.assertTrue(math.isnan(math.atan2(NAN, 2.3)))
261 self.assertTrue(math.isnan(math.atan2(NAN, INF)))
262 self.assertTrue(math.isnan(math.atan2(NAN, NAN)))
265 self.assertRaises(TypeError, math.ceil)
267 self.assertEqual(float, type(math.ceil(1)))
268 self.assertEqual(float, type(math.ceil(1L)))
269 self.assertEqual(float, type(math.ceil(1.0)))
270 self.ftest('ceil(0.5)', math.ceil(0.5), 1)
271 self.ftest('ceil(1.0)', math.ceil(1.0), 1)
272 self.ftest('ceil(1.5)', math.ceil(1.5), 2)
273 self.ftest('ceil(-0.5)', math.ceil(-0.5), 0)
274 self.ftest('ceil(-1.0)', math.ceil(-1.0), -1)
275 self.ftest('ceil(-1.5)', math.ceil(-1.5), -1)
276 self.assertEqual(math.ceil(INF), INF)
277 self.assertEqual(math.ceil(NINF), NINF)
278 self.assertTrue(math.isnan(math.ceil(NAN)))
285 self.ftest('ceil(TestCeil())', math.ceil(TestCeil()), 42)
286 self.assertRaises(TypeError, math.ceil, TestNoCeil())
290 self.assertRaises(TypeError, math.ceil, t)
291 self.assertRaises(TypeError, math.ceil, t, 0)
295 self.assertEqual(math.copysign(1, 42), 1.0)
296 self.assertEqual(math.copysign(0., 42), 0.0)
297 self.assertEqual(math.copysign(1., -42), -1.0)
298 self.assertEqual(math.copysign(3, 0.), 3.0)
299 self.assertEqual(math.copysign(4., -0.), -4.0)
301 self.assertRaises(TypeError, math.copysign)
303 self.assertEqual(math.copysign(1., 0.), 1.)
304 self.assertEqual(math.copysign(1., -0.), -1.)
305 self.assertEqual(math.copysign(INF, 0.), INF)
306 self.assertEqual(math.copysign(INF, -0.), NINF)
307 self.assertEqual(math.copysign(NINF, 0.), INF)
308 self.assertEqual(math.copysign(NINF, -0.), NINF)
310 self.assertEqual(math.copysign(1., INF), 1.)
311 self.assertEqual(math.copysign(1., NINF), -1.)
312 self.assertEqual(math.copysign(INF, INF), INF)
313 self.assertEqual(math.copysign(INF, NINF), NINF)
314 self.assertEqual(math.copysign(NINF, INF), INF)
315 self.assertEqual(math.copysign(NINF, NINF), NINF)
316 self.assertTrue(math.isnan(math.copysign(NAN, 1.)))
317 self.assertTrue(math.isnan(math.copysign(NAN, INF)))
318 self.assertTrue(math.isnan(math.copysign(NAN, NINF)))
319 self.assertTrue(math.isnan(math.copysign(NAN, NAN)))
323 self.assertTrue(math.isinf(math.copysign(INF, NAN)))
325 self.assertEqual(abs(math.copysign(2., NAN)), 2.)
328 self.assertRaises(TypeError, math.cos)
329 self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0)
330 self.ftest('cos(0)', math.cos(0), 1)
331 self.ftest('cos(pi/2)', math.cos(math.pi/2), 0)
332 self.ftest('cos(pi)', math.cos(math.pi), -1)
334 self.assertTrue(math.isnan(math.cos(INF)))
335 self.assertTrue(math.isnan(math.cos(NINF)))
337 self.assertRaises(ValueError, math.cos, INF)
338 self.assertRaises(ValueError, math.cos, NINF)
339 self.assertTrue(math.isnan(math.cos(NAN)))
342 self.assertRaises(TypeError, math.cosh)
343 self.ftest('cosh(0)', math.cosh(0), 1)
344 self.ftest('cosh(2)-2*cosh(1)**2', math.cosh(2)-2*math.cosh(1)**2, -1) # Thanks to Lambert
345 self.assertEqual(math.cosh(INF), INF)
346 self.assertEqual(math.cosh(NINF), INF)
347 self.assertTrue(math.isnan(math.cosh(NAN)))
350 self.assertRaises(TypeError, math.degrees)
351 self.ftest('degrees(pi)', math.degrees(math.pi), 180.0)
352 self.ftest('degrees(pi/2)', math.degrees(math.pi/2), 90.0)
353 self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0)
356 self.assertRaises(TypeError, math.exp)
357 self.ftest('exp(-1)', math.exp(-1), 1/math.e)
358 self.ftest('exp(0)', math.exp(0), 1)
359 self.ftest('exp(1)', math.exp(1), math.e)
360 self.assertEqual(math.exp(INF), INF)
361 self.assertEqual(math.exp(NINF), 0.)
362 self.assertTrue(math.isnan(math.exp(NAN)))
365 self.assertRaises(TypeError, math.fabs)
366 self.ftest('fabs(-1)', math.fabs(-1), 1)
367 self.ftest('fabs(0)', math.fabs(0), 0)
368 self.ftest('fabs(1)', math.fabs(1), 1)
380 self.assertEqual(math.factorial(cast(x)), fact(x), (x, fact(x), math.factorial(x)))
381 self.assertRaises(ValueError, math.factorial, -1)
382 self.assertRaises(ValueError, math.factorial, math.pi)
385 self.assertRaises(TypeError, math.floor)
387 self.assertEqual(float, type(math.floor(1)))
388 self.assertEqual(float, type(math.floor(1L)))
389 self.assertEqual(float, type(math.floor(1.0)))
390 self.ftest('floor(0.5)', math.floor(0.5), 0)
391 self.ftest('floor(1.0)', math.floor(1.0), 1)
392 self.ftest('floor(1.5)', math.floor(1.5), 1)
393 self.ftest('floor(-0.5)', math.floor(-0.5), -1)
394 self.ftest('floor(-1.0)', math.floor(-1.0), -1)
395 self.ftest('floor(-1.5)', math.floor(-1.5), -2)
398 self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167)
399 self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167)
400 self.assertEqual(math.ceil(INF), INF)
401 self.assertEqual(math.ceil(NINF), NINF)
402 self.assertTrue(math.isnan(math.floor(NAN)))
409 self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42)
410 self.assertRaises(TypeError, math.floor, TestNoFloor())
414 self.assertRaises(TypeError, math.floor, t)
415 self.assertRaises(TypeError, math.floor, t, 0)
418 self.assertRaises(TypeError, math.fmod)
419 self.ftest('fmod(10,1)', math.fmod(10,1), 0)
420 self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0)
421 self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1)
422 self.ftest('fmod(-10,1)', math.fmod(-10,1), 0)
423 self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0)
424 self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
425 self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
426 self.assertTrue(math.isnan(math.fmod(1., NAN)))
427 self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
428 self.assertRaises(ValueError, math.fmod, 1., 0.)
429 self.assertRaises(ValueError, math.fmod, INF, 1.)
430 self.assertRaises(ValueError, math.fmod, NINF, 1.)
431 self.assertRaises(ValueError, math.fmod, INF, 0.)
432 self.assertEqual(math.fmod(3.0, INF), 3.0)
433 self.assertEqual(math.fmod(-3.0, INF), -3.0)
434 self.assertEqual(math.fmod(3.0, NINF), 3.0)
435 self.assertEqual(math.fmod(-3.0, NINF), -3.0)
436 self.assertEqual(math.fmod(0.0, 3.0), 0.0)
437 self.assertEqual(math.fmod(0.0, NINF), 0.0)
440 self.assertRaises(TypeError, math.frexp)
448 testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1))
449 testfrexp('frexp(0)', math.frexp(0), (0, 0))
450 testfrexp('frexp(1)', math.frexp(1), (0.5, 1))
451 testfrexp('frexp(2)', math.frexp(2), (0.5, 2))
453 self.assertEqual(math.frexp(INF)[0], INF)
454 self.assertEqual(math.frexp(NINF)[0], NINF)
455 self.assertTrue(math.isnan(math.frexp(NAN)[0]))
484 mant, exp = math.frexp(x)
485 mant, exp = int(math.ldexp(mant, mant_dig)), exp - mant_dig
501 return math.ldexp(tmant, texp)
526 actual = math.fsum(vals)
546 self.assertEqual(msum(vals), math.fsum(vals))
549 self.assertRaises(TypeError, math.hypot)
550 self.ftest('hypot(0,0)', math.hypot(0,0), 0)
551 self.ftest('hypot(3,4)', math.hypot(3,4), 5)
552 self.assertEqual(math.hypot(NAN, INF), INF)
553 self.assertEqual(math.hypot(INF, NAN), INF)
554 self.assertEqual(math.hypot(NAN, NINF), INF)
555 self.assertEqual(math.hypot(NINF, NAN), INF)
556 self.assertTrue(math.isnan(math.hypot(1.0, NAN)))
557 self.assertTrue(math.isnan(math.hypot(NAN, -2.0)))
560 self.assertRaises(TypeError, math.ldexp)
561 self.ftest('ldexp(0,1)', math.ldexp(0,1), 0)
562 self.ftest('ldexp(1,1)', math.ldexp(1,1), 2)
563 self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5)
564 self.ftest('ldexp(-1,1)', math.ldexp(-1,1), -2)
565 self.assertRaises(OverflowError, math.ldexp, 1., 1000000)
566 self.assertRaises(OverflowError, math.ldexp, -1., 1000000)
567 self.assertEqual(math.ldexp(1., -1000000), 0.)
568 self.assertEqual(math.ldexp(-1., -1000000), -0.)
569 self.assertEqual(math.ldexp(INF, 30), INF)
570 self.assertEqual(math.ldexp(NINF, -213), NINF)
571 self.assertTrue(math.isnan(math.ldexp(NAN, 0)))
575 self.assertEqual(math.ldexp(INF, -n), INF)
576 self.assertEqual(math.ldexp(NINF, -n), NINF)
577 self.assertEqual(math.ldexp(1., -n), 0.)
578 self.assertEqual(math.ldexp(-1., -n), -0.)
579 self.assertEqual(math.ldexp(0., -n), 0.)
580 self.assertEqual(math.ldexp(-0., -n), -0.)
581 self.assertTrue(math.isnan(math.ldexp(NAN, -n)))
583 self.assertRaises(OverflowError, math.ldexp, 1., n)
584 self.assertRaises(OverflowError, math.ldexp, -1., n)
585 self.assertEqual(math.ldexp(0., n), 0.)
586 self.assertEqual(math.ldexp(-0., n), -0.)
587 self.assertEqual(math.ldexp(INF, n), INF)
588 self.assertEqual(math.ldexp(NINF, n), NINF)
589 self.assertTrue(math.isnan(math.ldexp(NAN, n)))
592 self.assertRaises(TypeError, math.log)
593 self.ftest('log(1/e)', math.log(1/math.e), -1)
594 self.ftest('log(1)', math.log(1), 0)
595 self.ftest('log(e)', math.log(math.e), 1)
596 self.ftest('log(32,2)', math.log(32,2), 5)
597 self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
598 self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
599 self.assertEqual(math.log(INF), INF)
600 self.assertRaises(ValueError, math.log, NINF)
601 self.assertTrue(math.isnan(math.log(NAN)))
604 self.assertEqual(math.log(n), math.log(long(n)))
607 self.assertRaises(TypeError, math.log1p)
608 self.ftest('log1p(1/e -1)', math.log1p(1/math.e-1), -1)
609 self.ftest('log1p(0)', math.log1p(0), 0)
610 self.ftest('log1p(e-1)', math.log1p(math.e-1), 1)
611 self.ftest('log1p(1)', math.log1p(1), math.log(2))
612 self.assertEqual(math.log1p(INF), INF)
613 self.assertRaises(ValueError, math.log1p, NINF)
614 self.assertTrue(math.isnan(math.log1p(NAN)))
616 self.assertAlmostEqual(math.log1p(n), 62.383246250395075)
617 self.assertAlmostEqual(math.log1p(n), math.log1p(float(n)))
620 self.assertRaises(TypeError, math.log10)
621 self.ftest('log10(0.1)', math.log10(0.1), -1)
622 self.ftest('log10(1)', math.log10(1), 0)
623 self.ftest('log10(10)', math.log10(10), 1)
624 self.assertEqual(math.log(INF), INF)
625 self.assertRaises(ValueError, math.log10, NINF)
626 self.assertTrue(math.isnan(math.log10(NAN)))
629 self.assertEqual(math.log10(n), math.log10(long(n)))
632 self.assertRaises(TypeError, math.modf)
640 testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0))
641 testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))
643 self.assertEqual(math.modf(INF), (0.0, INF))
644 self.assertEqual(math.modf(NINF), (-0.0, NINF))
646 modf_nan = math.modf(NAN)
647 self.assertTrue(math.isnan(modf_nan[0]))
648 self.assertTrue(math.isnan(modf_nan[1]))
651 self.assertRaises(TypeError, math.pow)
652 self.ftest('pow(0,1)', math.pow(0,1), 0)
653 self.ftest('pow(1,0)', math.pow(1,0), 1)
654 self.ftest('pow(2,1)', math.pow(2,1), 2)
655 self.ftest('pow(2,-1)', math.pow(2,-1), 0.5)
656 self.assertEqual(math.pow(INF, 1), INF)
657 self.assertEqual(math.pow(NINF, 1), NINF)
658 self.assertEqual((math.pow(1, INF)), 1.)
659 self.assertEqual((math.pow(1, NINF)), 1.)
660 self.assertTrue(math.isnan(math.pow(NAN, 1)))
661 self.assertTrue(math.isnan(math.pow(2, NAN)))
662 self.assertTrue(math.isnan(math.pow(0, NAN)))
663 self.assertEqual(math.pow(1, NAN), 1)
666 self.assertEqual(math.pow(0., INF), 0.)
667 self.assertEqual(math.pow(0., 3.), 0.)
668 self.assertEqual(math.pow(0., 2.3), 0.)
669 self.assertEqual(math.pow(0., 2.), 0.)
670 self.assertEqual(math.pow(0., 0.), 1.)
671 self.assertEqual(math.pow(0., -0.), 1.)
672 self.assertRaises(ValueError, math.pow, 0., -2.)
673 self.assertRaises(ValueError, math.pow, 0., -2.3)
674 self.assertRaises(ValueError, math.pow, 0., -3.)
675 self.assertRaises(ValueError, math.pow, 0., NINF)
676 self.assertTrue(math.isnan(math.pow(0., NAN)))
679 self.assertEqual(math.pow(INF, INF), INF)
680 self.assertEqual(math.pow(INF, 3.), INF)
681 self.assertEqual(math.pow(INF, 2.3), INF)
682 self.assertEqual(math.pow(INF, 2.), INF)
683 self.assertEqual(math.pow(INF, 0.), 1.)
684 self.assertEqual(math.pow(INF, -0.), 1.)
685 self.assertEqual(math.pow(INF, -2.), 0.)
686 self.assertEqual(math.pow(INF, -2.3), 0.)
687 self.assertEqual(math.pow(INF, -3.), 0.)
688 self.assertEqual(math.pow(INF, NINF), 0.)
689 self.assertTrue(math.isnan(math.pow(INF, NAN)))
692 self.assertEqual(math.pow(-0., INF), 0.)
693 self.assertEqual(math.pow(-0., 3.), -0.)
694 self.assertEqual(math.pow(-0., 2.3), 0.)
695 self.assertEqual(math.pow(-0., 2.), 0.)
696 self.assertEqual(math.pow(-0., 0.), 1.)
697 self.assertEqual(math.pow(-0., -0.), 1.)
698 self.assertRaises(ValueError, math.pow, -0., -2.)
699 self.assertRaises(ValueError, math.pow, -0., -2.3)
700 self.assertRaises(ValueError, math.pow, -0., -3.)
701 self.assertRaises(ValueError, math.pow, -0., NINF)
702 self.assertTrue(math.isnan(math.pow(-0., NAN)))
705 self.assertEqual(math.pow(NINF, INF), INF)
706 self.assertEqual(math.pow(NINF, 3.), NINF)
707 self.assertEqual(math.pow(NINF, 2.3), INF)
708 self.assertEqual(math.pow(NINF, 2.), INF)
709 self.assertEqual(math.pow(NINF, 0.), 1.)
710 self.assertEqual(math.pow(NINF, -0.), 1.)
711 self.assertEqual(math.pow(NINF, -2.), 0.)
712 self.assertEqual(math.pow(NINF, -2.3), 0.)
713 self.assertEqual(math.pow(NINF, -3.), -0.)
714 self.assertEqual(math.pow(NINF, NINF), 0.)
715 self.assertTrue(math.isnan(math.pow(NINF, NAN)))
718 self.assertEqual(math.pow(-1., INF), 1.)
719 self.assertEqual(math.pow(-1., 3.), -1.)
720 self.assertRaises(ValueError, math.pow, -1., 2.3)
721 self.assertEqual(math.pow(-1., 2.), 1.)
722 self.assertEqual(math.pow(-1., 0.), 1.)
723 self.assertEqual(math.pow(-1., -0.), 1.)
724 self.assertEqual(math.pow(-1., -2.), 1.)
725 self.assertRaises(ValueError, math.pow, -1., -2.3)
726 self.assertEqual(math.pow(-1., -3.), -1.)
727 self.assertEqual(math.pow(-1., NINF), 1.)
728 self.assertTrue(math.isnan(math.pow(-1., NAN)))
731 self.assertEqual(math.pow(1., INF), 1.)
732 self.assertEqual(math.pow(1., 3.), 1.)
733 self.assertEqual(math.pow(1., 2.3), 1.)
734 self.assertEqual(math.pow(1., 2.), 1.)
735 self.assertEqual(math.pow(1., 0.), 1.)
736 self.assertEqual(math.pow(1., -0.), 1.)
737 self.assertEqual(math.pow(1., -2.), 1.)
738 self.assertEqual(math.pow(1., -2.3), 1.)
739 self.assertEqual(math.pow(1., -3.), 1.)
740 self.assertEqual(math.pow(1., NINF), 1.)
741 self.assertEqual(math.pow(1., NAN), 1.)
744 self.assertEqual(math.pow(2.3, 0.), 1.)
745 self.assertEqual(math.pow(-2.3, 0.), 1.)
746 self.assertEqual(math.pow(NAN, 0.), 1.)
747 self.assertEqual(math.pow(2.3, -0.), 1.)
748 self.assertEqual(math.pow(-2.3, -0.), 1.)
749 self.assertEqual(math.pow(NAN, -0.), 1.)
752 self.assertRaises(ValueError, math.pow, -1., 2.3)
753 self.assertRaises(ValueError, math.pow, -15., -3.1)
756 self.assertEqual(math.pow(1.9, NINF), 0.)
757 self.assertEqual(math.pow(1.1, NINF), 0.)
758 self.assertEqual(math.pow(0.9, NINF), INF)
759 self.assertEqual(math.pow(0.1, NINF), INF)
760 self.assertEqual(math.pow(-0.1, NINF), INF)
761 self.assertEqual(math.pow(-0.9, NINF), INF)
762 self.assertEqual(math.pow(-1.1, NINF), 0.)
763 self.assertEqual(math.pow(-1.9, NINF), 0.)
766 self.assertEqual(math.pow(1.9, INF), INF)
767 self.assertEqual(math.pow(1.1, INF), INF)
768 self.assertEqual(math.pow(0.9, INF), 0.)
769 self.assertEqual(math.pow(0.1, INF), 0.)
770 self.assertEqual(math.pow(-0.1, INF), 0.)
771 self.assertEqual(math.pow(-0.9, INF), 0.)
772 self.assertEqual(math.pow(-1.1, INF), INF)
773 self.assertEqual(math.pow(-1.9, INF), INF)
776 self.ftest('(-2.)**3.', math.pow(-2.0, 3.0), -8.0)
777 self.ftest('(-2.)**2.', math.pow(-2.0, 2.0), 4.0)
778 self.ftest('(-2.)**1.', math.pow(-2.0, 1.0), -2.0)
779 self.ftest('(-2.)**0.', math.pow(-2.0, 0.0), 1.0)
780 self.ftest('(-2.)**-0.', math.pow(-2.0, -0.0), 1.0)
781 self.ftest('(-2.)**-1.', math.pow(-2.0, -1.0), -0.5)
782 self.ftest('(-2.)**-2.', math.pow(-2.0, -2.0), 0.25)
783 self.ftest('(-2.)**-3.', math.pow(-2.0, -3.0), -0.125)
784 self.assertRaises(ValueError, math.pow, -2.0, -0.5)
785 self.assertRaises(ValueError, math.pow, -2.0, 0.5)
800 self.assertRaises(TypeError, math.radians)
801 self.ftest('radians(180)', math.radians(180), math.pi)
802 self.ftest('radians(90)', math.radians(90), math.pi/2)
803 self.ftest('radians(-45)', math.radians(-45), -math.pi/4)
806 self.assertRaises(TypeError, math.sin)
807 self.ftest('sin(0)', math.sin(0), 0)
808 self.ftest('sin(pi/2)', math.sin(math.pi/2), 1)
809 self.ftest('sin(-pi/2)', math.sin(-math.pi/2), -1)
811 self.assertTrue(math.isnan(math.sin(INF)))
812 self.assertTrue(math.isnan(math.sin(NINF)))
814 self.assertRaises(ValueError, math.sin, INF)
815 self.assertRaises(ValueError, math.sin, NINF)
816 self.assertTrue(math.isnan(math.sin(NAN)))
819 self.assertRaises(TypeError, math.sinh)
820 self.ftest('sinh(0)', math.sinh(0), 0)
821 self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1)
822 self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0)
823 self.assertEqual(math.sinh(INF), INF)
824 self.assertEqual(math.sinh(NINF), NINF)
825 self.assertTrue(math.isnan(math.sinh(NAN)))
828 self.assertRaises(TypeError, math.sqrt)
829 self.ftest('sqrt(0)', math.sqrt(0), 0)
830 self.ftest('sqrt(1)', math.sqrt(1), 1)
831 self.ftest('sqrt(4)', math.sqrt(4), 2)
832 self.assertEqual(math.sqrt(INF), INF)
833 self.assertRaises(ValueError, math.sqrt, NINF)
834 self.assertTrue(math.isnan(math.sqrt(NAN)))
837 self.assertRaises(TypeError, math.tan)
838 self.ftest('tan(0)', math.tan(0), 0)
839 self.ftest('tan(pi/4)', math.tan(math.pi/4), 1)
840 self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1)
842 self.assertTrue(math.isnan(math.tan(INF)))
843 self.assertTrue(math.isnan(math.tan(NINF)))
845 self.assertRaises(ValueError, math.tan, INF)
846 self.assertRaises(ValueError, math.tan, NINF)
847 self.assertTrue(math.isnan(math.tan(NAN)))
850 self.assertRaises(TypeError, math.tanh)
851 self.ftest('tanh(0)', math.tanh(0), 0)
852 self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
853 self.ftest('tanh(inf)', math.tanh(INF), 1)
854 self.ftest('tanh(-inf)', math.tanh(NINF), -1)
855 self.assertTrue(math.isnan(math.tanh(NAN)))
858 self.assertEqual(math.tanh(-0.), -0.)
859 self.assertEqual(math.copysign(1., math.tanh(-0.)),
860 math.copysign(1., -0.))
863 self.assertEqual(math.trunc(1), 1)
864 self.assertEqual(math.trunc(-1), -1)
865 self.assertEqual(type(math.trunc(1)), int)
866 self.assertEqual(type(math.trunc(1.5)), int)
867 self.assertEqual(math.trunc(1.5), 1)
868 self.assertEqual(math.trunc(-1.5), -1)
869 self.assertEqual(math.trunc(1.999999), 1)
870 self.assertEqual(math.trunc(-1.999999), -1)
871 self.assertEqual(math.trunc(-0.999999), -0)
872 self.assertEqual(math.trunc(-100.999), -100)
881 self.assertEqual(math.trunc(TestTrunc()), 23)
883 self.assertRaises(TypeError, math.trunc)
884 self.assertRaises(TypeError, math.trunc, 1, 2)
885 self.assertRaises((AttributeError, TypeError), math.trunc,
889 self.assertTrue(math.isnan(float("nan")))
890 self.assertTrue(math.isnan(float("inf")* 0.))
891 self.assertFalse(math.isnan(float("inf")))
892 self.assertFalse(math.isnan(0.))
893 self.assertFalse(math.isnan(1.))
896 self.assertTrue(math.isinf(float("inf")))
897 self.assertTrue(math.isinf(float("-inf")))
898 self.assertTrue(math.isinf(1E400))
899 self.assertTrue(math.isinf(-1E400))
900 self.assertFalse(math.isinf(float("nan")))
901 self.assertFalse(math.isinf(0.))
902 self.assertFalse(math.isinf(1.))
912 x = math.exp(-1000000000)
924 x = math.exp(1000000000)
935 x = math.sqrt(-1.0)
951 func = getattr(math, fn)
972 func = getattr(math, fn)
988 if math.isnan(expected) and math.isnan(got):
990 if not math.isnan(expected) and not math.isnan(got):