Back to index

python3.2  3.2.2
Public Member Functions
test.test_math.MathTests Class Reference

List of all members.

Public Member Functions

def ftest
def testConstants
def testAcos
def testAcosh
def testAsin
def testAsinh
def testAtan
def testAtanh
def testAtan2
def testCeil
def testCopysign
def testCos
def testCosh
def testDegrees
def testExp
def testFabs
def testFactorial
def testFloor
def testFmod
def testFrexp
def testFsum
def testHypot
def testLdexp
def testLog
def testLog1p
def testLog10
def testModf
def testPow
def testRadians
def testSin
def testSinh
def testSqrt
def testTan
def testTanh
def testTanhSign
def test_trunc
def testIsfinite
def testIsnan
def testIsinf
def test_exceptions
def test_testfile
def test_mtestfile

Detailed Description

Definition at line 177 of file test_math.py.


Member Function Documentation

def test.test_math.MathTests.ftest (   self,
  name,
  value,
  expected 
)

Definition at line 179 of file test_math.py.

00179 
00180     def ftest(self, name, value, expected):
00181         if abs(value-expected) > eps:
00182             # Use %r instead of %f so the error message
00183             # displays full precision. Otherwise discrepancies
00184             # in the last few bits will lead to very confusing
00185             # error messages
00186             self.fail('%s returned %r, expected %r' %
00187                       (name, value, expected))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 957 of file test_math.py.

00957 
00958         def test_exceptions(self):
00959             try:
00960                 x = math.exp(-1000000000)
00961             except:
00962                 # mathmodule.c is failing to weed out underflows from libm, or
00963                 # we've got an fp format with huge dynamic range
00964                 self.fail("underflowing exp() should not have raised "
00965                           "an exception")
00966             if x != 0:
00967                 self.fail("underflowing exp() should have returned 0")
00968 
00969             # If this fails, probably using a strict IEEE-754 conforming libm, and x
00970             # is +Inf afterwards.  But Python wants overflows detected by default.
00971             try:
00972                 x = math.exp(1000000000)
00973             except OverflowError:
00974                 pass
00975             else:
00976                 self.fail("overflowing exp() didn't trigger OverflowError")
00977 
00978             # If this fails, it could be a puzzle.  One odd possibility is that
00979             # mathmodule.c's macros are getting confused while comparing
00980             # Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE
00981             # as a result (and so raising OverflowError instead).
00982             try:
00983                 x = math.sqrt(-1.0)
00984             except ValueError:
00985                 pass
00986             else:
00987                 self.fail("sqrt(-1) didn't raise ValueError")

Here is the call graph for this function:

Definition at line 1012 of file test_math.py.

01012 
01013     def test_mtestfile(self):
01014         ALLOWED_ERROR = 20  # permitted error, in ulps
01015         fail_fmt = "{}:{}({!r}): expected {!r}, got {!r}"
01016 
01017         failures = []
01018         for id, fn, arg, expected, flags in parse_mtestfile(math_testcases):
01019             func = getattr(math, fn)
01020 
01021             if 'invalid' in flags or 'divide-by-zero' in flags:
01022                 expected = 'ValueError'
01023             elif 'overflow' in flags:
01024                 expected = 'OverflowError'
01025 
01026             try:
01027                 got = func(arg)
01028             except ValueError:
01029                 got = 'ValueError'
01030             except OverflowError:
01031                 got = 'OverflowError'
01032 
01033             accuracy_failure = None
01034             if isinstance(got, float) and isinstance(expected, float):
01035                 if math.isnan(expected) and math.isnan(got):
01036                     continue
01037                 if not math.isnan(expected) and not math.isnan(got):
01038                     if fn == 'lgamma':
01039                         # we use a weaker accuracy test for lgamma;
01040                         # lgamma only achieves an absolute error of
01041                         # a few multiples of the machine accuracy, in
01042                         # general.
01043                         accuracy_failure = acc_check(expected, got,
01044                                                   rel_err = 5e-15,
01045                                                   abs_err = 5e-15)
01046                     elif fn == 'erfc':
01047                         # erfc has less-than-ideal accuracy for large
01048                         # arguments (x ~ 25 or so), mainly due to the
01049                         # error involved in computing exp(-x*x).
01050                         #
01051                         # XXX Would be better to weaken this test only
01052                         # for large x, instead of for all x.
01053                         accuracy_failure = ulps_check(expected, got, 2000)
01054 
01055                     else:
01056                         accuracy_failure = ulps_check(expected, got, 20)
01057                     if accuracy_failure is None:
01058                         continue
01059 
01060             if isinstance(got, str) and isinstance(expected, str):
01061                 if got == expected:
01062                     continue
01063 
01064             fail_msg = fail_fmt.format(id, fn, arg, expected, got)
01065             if accuracy_failure is not None:
01066                 fail_msg += ' ({})'.format(accuracy_failure)
01067             failures.append(fail_msg)
01068 
01069         if failures:
01070             self.fail('Failures in test_mtestfile:\n  ' +
01071                       '\n  '.join(failures))
01072 

Here is the call graph for this function:

Definition at line 989 of file test_math.py.

00989 
00990     def test_testfile(self):
00991         for id, fn, ar, ai, er, ei, flags in parse_testfile(test_file):
00992             # Skip if either the input or result is complex, or if
00993             # flags is nonempty
00994             if ai != 0. or ei != 0. or flags:
00995                 continue
00996             if fn in ['rect', 'polar']:
00997                 # no real versions of rect, polar
00998                 continue
00999             func = getattr(math, fn)
01000             try:
01001                 result = func(ar)
01002             except ValueError as exc:
01003                 message = (("Unexpected ValueError: %s\n        " +
01004                            "in test %s:%s(%r)\n") % (exc.args[0], id, fn, ar))
01005                 self.fail(message)
01006             except OverflowError:
01007                 message = ("Unexpected OverflowError in " +
01008                            "test %s:%s(%r)\n" % (id, fn, ar))
01009                 self.fail(message)
01010             self.ftest("%s:%s(%r)" % (id, fn, ar), result, er)

Here is the call graph for this function:

Definition at line 900 of file test_math.py.

00900 
00901     def test_trunc(self):
00902         self.assertEqual(math.trunc(1), 1)
00903         self.assertEqual(math.trunc(-1), -1)
00904         self.assertEqual(type(math.trunc(1)), int)
00905         self.assertEqual(type(math.trunc(1.5)), int)
00906         self.assertEqual(math.trunc(1.5), 1)
00907         self.assertEqual(math.trunc(-1.5), -1)
00908         self.assertEqual(math.trunc(1.999999), 1)
00909         self.assertEqual(math.trunc(-1.999999), -1)
00910         self.assertEqual(math.trunc(-0.999999), -0)
00911         self.assertEqual(math.trunc(-100.999), -100)
00912 
00913         class TestTrunc(object):
00914             def __trunc__(self):
00915                 return 23
00916 
00917         class TestNoTrunc(object):
00918             pass
00919 
00920         self.assertEqual(math.trunc(TestTrunc()), 23)
00921 
00922         self.assertRaises(TypeError, math.trunc)
00923         self.assertRaises(TypeError, math.trunc, 1, 2)
00924         self.assertRaises(TypeError, math.trunc, TestNoTrunc())

Here is the call graph for this function:

Definition at line 192 of file test_math.py.

00192 
00193     def testAcos(self):
00194         self.assertRaises(TypeError, math.acos)
00195         self.ftest('acos(-1)', math.acos(-1), math.pi)
00196         self.ftest('acos(0)', math.acos(0), math.pi/2)
00197         self.ftest('acos(1)', math.acos(1), 0)
00198         self.assertRaises(ValueError, math.acos, INF)
00199         self.assertRaises(ValueError, math.acos, NINF)
00200         self.assertTrue(math.isnan(math.acos(NAN)))

Here is the call graph for this function:

Definition at line 201 of file test_math.py.

00201 
00202     def testAcosh(self):
00203         self.assertRaises(TypeError, math.acosh)
00204         self.ftest('acosh(1)', math.acosh(1), 0)
00205         self.ftest('acosh(2)', math.acosh(2), 1.3169578969248168)
00206         self.assertRaises(ValueError, math.acosh, 0)
00207         self.assertRaises(ValueError, math.acosh, -1)
00208         self.assertEqual(math.acosh(INF), INF)
00209         self.assertRaises(ValueError, math.acosh, NINF)
00210         self.assertTrue(math.isnan(math.acosh(NAN)))

Here is the call graph for this function:

Definition at line 211 of file test_math.py.

00211 
00212     def testAsin(self):
00213         self.assertRaises(TypeError, math.asin)
00214         self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
00215         self.ftest('asin(0)', math.asin(0), 0)
00216         self.ftest('asin(1)', math.asin(1), math.pi/2)
00217         self.assertRaises(ValueError, math.asin, INF)
00218         self.assertRaises(ValueError, math.asin, NINF)
00219         self.assertTrue(math.isnan(math.asin(NAN)))

Here is the call graph for this function:

Definition at line 220 of file test_math.py.

00220 
00221     def testAsinh(self):
00222         self.assertRaises(TypeError, math.asinh)
00223         self.ftest('asinh(0)', math.asinh(0), 0)
00224         self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305)
00225         self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305)
00226         self.assertEqual(math.asinh(INF), INF)
00227         self.assertEqual(math.asinh(NINF), NINF)
00228         self.assertTrue(math.isnan(math.asinh(NAN)))

Here is the call graph for this function:

Definition at line 229 of file test_math.py.

00229 
00230     def testAtan(self):
00231         self.assertRaises(TypeError, math.atan)
00232         self.ftest('atan(-1)', math.atan(-1), -math.pi/4)
00233         self.ftest('atan(0)', math.atan(0), 0)
00234         self.ftest('atan(1)', math.atan(1), math.pi/4)
00235         self.ftest('atan(inf)', math.atan(INF), math.pi/2)
00236         self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2)
00237         self.assertTrue(math.isnan(math.atan(NAN)))

Here is the call graph for this function:

Definition at line 249 of file test_math.py.

00249 
00250     def testAtan2(self):
00251         self.assertRaises(TypeError, math.atan2)
00252         self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2)
00253         self.ftest('atan2(-1, 1)', math.atan2(-1, 1), -math.pi/4)
00254         self.ftest('atan2(0, 1)', math.atan2(0, 1), 0)
00255         self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4)
00256         self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2)
00257 
00258         # math.atan2(0, x)
00259         self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
00260         self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi)
00261         self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi)
00262         self.assertEqual(math.atan2(0., 0.), 0.)
00263         self.assertEqual(math.atan2(0., 2.3), 0.)
00264         self.assertEqual(math.atan2(0., INF), 0.)
00265         self.assertTrue(math.isnan(math.atan2(0., NAN)))
00266         # math.atan2(-0, x)
00267         self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi)
00268         self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi)
00269         self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi)
00270         self.assertEqual(math.atan2(-0., 0.), -0.)
00271         self.assertEqual(math.atan2(-0., 2.3), -0.)
00272         self.assertEqual(math.atan2(-0., INF), -0.)
00273         self.assertTrue(math.isnan(math.atan2(-0., NAN)))
00274         # math.atan2(INF, x)
00275         self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4)
00276         self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2)
00277         self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2)
00278         self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2)
00279         self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2)
00280         self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4)
00281         self.assertTrue(math.isnan(math.atan2(INF, NAN)))
00282         # math.atan2(NINF, x)
00283         self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4)
00284         self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2)
00285         self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2)
00286         self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2)
00287         self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2)
00288         self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4)
00289         self.assertTrue(math.isnan(math.atan2(NINF, NAN)))
00290         # math.atan2(+finite, x)
00291         self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi)
00292         self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2)
00293         self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2)
00294         self.assertEqual(math.atan2(2.3, INF), 0.)
00295         self.assertTrue(math.isnan(math.atan2(2.3, NAN)))
00296         # math.atan2(-finite, x)
00297         self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi)
00298         self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2)
00299         self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2)
00300         self.assertEqual(math.atan2(-2.3, INF), -0.)
00301         self.assertTrue(math.isnan(math.atan2(-2.3, NAN)))
00302         # math.atan2(NAN, x)
00303         self.assertTrue(math.isnan(math.atan2(NAN, NINF)))
00304         self.assertTrue(math.isnan(math.atan2(NAN, -2.3)))
00305         self.assertTrue(math.isnan(math.atan2(NAN, -0.)))
00306         self.assertTrue(math.isnan(math.atan2(NAN, 0.)))
00307         self.assertTrue(math.isnan(math.atan2(NAN, 2.3)))
00308         self.assertTrue(math.isnan(math.atan2(NAN, INF)))
00309         self.assertTrue(math.isnan(math.atan2(NAN, NAN)))

Here is the call graph for this function:

Definition at line 238 of file test_math.py.

00238 
00239     def testAtanh(self):
00240         self.assertRaises(TypeError, math.atan)
00241         self.ftest('atanh(0)', math.atanh(0), 0)
00242         self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
00243         self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
00244         self.assertRaises(ValueError, math.atanh, 1)
00245         self.assertRaises(ValueError, math.atanh, -1)
00246         self.assertRaises(ValueError, math.atanh, INF)
00247         self.assertRaises(ValueError, math.atanh, NINF)
00248         self.assertTrue(math.isnan(math.atanh(NAN)))

Here is the call graph for this function:

Definition at line 310 of file test_math.py.

00310 
00311     def testCeil(self):
00312         self.assertRaises(TypeError, math.ceil)
00313         self.assertEqual(int, type(math.ceil(0.5)))
00314         self.ftest('ceil(0.5)', math.ceil(0.5), 1)
00315         self.ftest('ceil(1.0)', math.ceil(1.0), 1)
00316         self.ftest('ceil(1.5)', math.ceil(1.5), 2)
00317         self.ftest('ceil(-0.5)', math.ceil(-0.5), 0)
00318         self.ftest('ceil(-1.0)', math.ceil(-1.0), -1)
00319         self.ftest('ceil(-1.5)', math.ceil(-1.5), -1)
00320         #self.assertEqual(math.ceil(INF), INF)
00321         #self.assertEqual(math.ceil(NINF), NINF)
00322         #self.assertTrue(math.isnan(math.ceil(NAN)))
00323 
00324         class TestCeil:
00325             def __ceil__(self):
00326                 return 42
00327         class TestNoCeil:
00328             pass
00329         self.ftest('ceil(TestCeil())', math.ceil(TestCeil()), 42)
00330         self.assertRaises(TypeError, math.ceil, TestNoCeil())
00331 
00332         t = TestNoCeil()
00333         t.__ceil__ = lambda *args: args
00334         self.assertRaises(TypeError, math.ceil, t)
00335         self.assertRaises(TypeError, math.ceil, t, 0)

Here is the call graph for this function:

Definition at line 188 of file test_math.py.

00188 
00189     def testConstants(self):
00190         self.ftest('pi', math.pi, 3.1415926)
00191         self.ftest('e', math.e, 2.7182818)

Here is the call graph for this function:

Definition at line 337 of file test_math.py.

00337 
00338     def testCopysign(self):
00339         self.assertEqual(math.copysign(1, 42), 1.0)
00340         self.assertEqual(math.copysign(0., 42), 0.0)
00341         self.assertEqual(math.copysign(1., -42), -1.0)
00342         self.assertEqual(math.copysign(3, 0.), 3.0)
00343         self.assertEqual(math.copysign(4., -0.), -4.0)
00344 
00345         self.assertRaises(TypeError, math.copysign)
00346         # copysign should let us distinguish signs of zeros
00347         self.assertEqual(math.copysign(1., 0.), 1.)
00348         self.assertEqual(math.copysign(1., -0.), -1.)
00349         self.assertEqual(math.copysign(INF, 0.), INF)
00350         self.assertEqual(math.copysign(INF, -0.), NINF)
00351         self.assertEqual(math.copysign(NINF, 0.), INF)
00352         self.assertEqual(math.copysign(NINF, -0.), NINF)
00353         # and of infinities
00354         self.assertEqual(math.copysign(1., INF), 1.)
00355         self.assertEqual(math.copysign(1., NINF), -1.)
00356         self.assertEqual(math.copysign(INF, INF), INF)
00357         self.assertEqual(math.copysign(INF, NINF), NINF)
00358         self.assertEqual(math.copysign(NINF, INF), INF)
00359         self.assertEqual(math.copysign(NINF, NINF), NINF)
00360         self.assertTrue(math.isnan(math.copysign(NAN, 1.)))
00361         self.assertTrue(math.isnan(math.copysign(NAN, INF)))
00362         self.assertTrue(math.isnan(math.copysign(NAN, NINF)))
00363         self.assertTrue(math.isnan(math.copysign(NAN, NAN)))
00364         # copysign(INF, NAN) may be INF or it may be NINF, since
00365         # we don't know whether the sign bit of NAN is set on any
00366         # given platform.
00367         self.assertTrue(math.isinf(math.copysign(INF, NAN)))
00368         # similarly, copysign(2., NAN) could be 2. or -2.
00369         self.assertEqual(abs(math.copysign(2., NAN)), 2.)

Here is the call graph for this function:

Definition at line 370 of file test_math.py.

00370 
00371     def testCos(self):
00372         self.assertRaises(TypeError, math.cos)
00373         self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0)
00374         self.ftest('cos(0)', math.cos(0), 1)
00375         self.ftest('cos(pi/2)', math.cos(math.pi/2), 0)
00376         self.ftest('cos(pi)', math.cos(math.pi), -1)
00377         try:
00378             self.assertTrue(math.isnan(math.cos(INF)))
00379             self.assertTrue(math.isnan(math.cos(NINF)))
00380         except ValueError:
00381             self.assertRaises(ValueError, math.cos, INF)
00382             self.assertRaises(ValueError, math.cos, NINF)
00383         self.assertTrue(math.isnan(math.cos(NAN)))

Here is the call graph for this function:

Definition at line 384 of file test_math.py.

00384 
00385     def testCosh(self):
00386         self.assertRaises(TypeError, math.cosh)
00387         self.ftest('cosh(0)', math.cosh(0), 1)
00388         self.ftest('cosh(2)-2*cosh(1)**2', math.cosh(2)-2*math.cosh(1)**2, -1) # Thanks to Lambert
00389         self.assertEqual(math.cosh(INF), INF)
00390         self.assertEqual(math.cosh(NINF), INF)
00391         self.assertTrue(math.isnan(math.cosh(NAN)))

Here is the call graph for this function:

Definition at line 392 of file test_math.py.

00392 
00393     def testDegrees(self):
00394         self.assertRaises(TypeError, math.degrees)
00395         self.ftest('degrees(pi)', math.degrees(math.pi), 180.0)
00396         self.ftest('degrees(pi/2)', math.degrees(math.pi/2), 90.0)
00397         self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0)

Here is the call graph for this function:

Definition at line 398 of file test_math.py.

00398 
00399     def testExp(self):
00400         self.assertRaises(TypeError, math.exp)
00401         self.ftest('exp(-1)', math.exp(-1), 1/math.e)
00402         self.ftest('exp(0)', math.exp(0), 1)
00403         self.ftest('exp(1)', math.exp(1), math.e)
00404         self.assertEqual(math.exp(INF), INF)
00405         self.assertEqual(math.exp(NINF), 0.)
00406         self.assertTrue(math.isnan(math.exp(NAN)))

Here is the call graph for this function:

Definition at line 407 of file test_math.py.

00407 
00408     def testFabs(self):
00409         self.assertRaises(TypeError, math.fabs)
00410         self.ftest('fabs(-1)', math.fabs(-1), 1)
00411         self.ftest('fabs(0)', math.fabs(0), 0)
00412         self.ftest('fabs(1)', math.fabs(1), 1)

Here is the call graph for this function:

Definition at line 413 of file test_math.py.

00413 
00414     def testFactorial(self):
00415         self.assertEqual(math.factorial(0), 1)
00416         self.assertEqual(math.factorial(0.0), 1)
00417         total = 1
00418         for i in range(1, 1000):
00419             total *= i
00420             self.assertEqual(math.factorial(i), total)
00421             self.assertEqual(math.factorial(float(i)), total)
00422             self.assertEqual(math.factorial(i), py_factorial(i))
00423         self.assertRaises(ValueError, math.factorial, -1)
00424         self.assertRaises(ValueError, math.factorial, -1.0)
00425         self.assertRaises(ValueError, math.factorial, math.pi)
00426         self.assertRaises(OverflowError, math.factorial, sys.maxsize+1)
00427         self.assertRaises(OverflowError, math.factorial, 10e100)

Here is the call graph for this function:

Definition at line 428 of file test_math.py.

00428 
00429     def testFloor(self):
00430         self.assertRaises(TypeError, math.floor)
00431         self.assertEqual(int, type(math.floor(0.5)))
00432         self.ftest('floor(0.5)', math.floor(0.5), 0)
00433         self.ftest('floor(1.0)', math.floor(1.0), 1)
00434         self.ftest('floor(1.5)', math.floor(1.5), 1)
00435         self.ftest('floor(-0.5)', math.floor(-0.5), -1)
00436         self.ftest('floor(-1.0)', math.floor(-1.0), -1)
00437         self.ftest('floor(-1.5)', math.floor(-1.5), -2)
00438         # pow() relies on floor() to check for integers
00439         # This fails on some platforms - so check it here
00440         self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167)
00441         self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167)
00442         #self.assertEqual(math.ceil(INF), INF)
00443         #self.assertEqual(math.ceil(NINF), NINF)
00444         #self.assertTrue(math.isnan(math.floor(NAN)))
00445 
00446         class TestFloor:
00447             def __floor__(self):
00448                 return 42
00449         class TestNoFloor:
00450             pass
00451         self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42)
00452         self.assertRaises(TypeError, math.floor, TestNoFloor())
00453 
00454         t = TestNoFloor()
00455         t.__floor__ = lambda *args: args
00456         self.assertRaises(TypeError, math.floor, t)
00457         self.assertRaises(TypeError, math.floor, t, 0)

Here is the call graph for this function:

Definition at line 458 of file test_math.py.

00458 
00459     def testFmod(self):
00460         self.assertRaises(TypeError, math.fmod)
00461         self.ftest('fmod(10,1)', math.fmod(10,1), 0)
00462         self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0)
00463         self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1)
00464         self.ftest('fmod(-10,1)', math.fmod(-10,1), 0)
00465         self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0)
00466         self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
00467         self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
00468         self.assertTrue(math.isnan(math.fmod(1., NAN)))
00469         self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
00470         self.assertRaises(ValueError, math.fmod, 1., 0.)
00471         self.assertRaises(ValueError, math.fmod, INF, 1.)
00472         self.assertRaises(ValueError, math.fmod, NINF, 1.)
00473         self.assertRaises(ValueError, math.fmod, INF, 0.)
00474         self.assertEqual(math.fmod(3.0, INF), 3.0)
00475         self.assertEqual(math.fmod(-3.0, INF), -3.0)
00476         self.assertEqual(math.fmod(3.0, NINF), 3.0)
00477         self.assertEqual(math.fmod(-3.0, NINF), -3.0)
00478         self.assertEqual(math.fmod(0.0, 3.0), 0.0)
00479         self.assertEqual(math.fmod(0.0, NINF), 0.0)

Here is the call graph for this function:

Definition at line 480 of file test_math.py.

00480 
00481     def testFrexp(self):
00482         self.assertRaises(TypeError, math.frexp)
00483 
00484         def testfrexp(name, result, expected):
00485             (mant, exp), (emant, eexp) = result, expected
00486             if abs(mant-emant) > eps or exp != eexp:
00487                 self.fail('%s returned %r, expected %r'%\
00488                           (name, result, expected))
00489 
00490         testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1))
00491         testfrexp('frexp(0)', math.frexp(0), (0, 0))
00492         testfrexp('frexp(1)', math.frexp(1), (0.5, 1))
00493         testfrexp('frexp(2)', math.frexp(2), (0.5, 2))
00494 
00495         self.assertEqual(math.frexp(INF)[0], INF)
00496         self.assertEqual(math.frexp(NINF)[0], NINF)
00497         self.assertTrue(math.isnan(math.frexp(NAN)[0]))

Here is the call graph for this function:

Definition at line 501 of file test_math.py.

00501 
00502     def testFsum(self):
00503         # math.fsum relies on exact rounding for correct operation.
00504         # There's a known problem with IA32 floating-point that causes
00505         # inexact rounding in some situations, and will cause the
00506         # math.fsum tests below to fail; see issue #2937.  On non IEEE
00507         # 754 platforms, and on IEEE 754 platforms that exhibit the
00508         # problem described in issue #2937, we simply skip the whole
00509         # test.
00510 
00511         # Python version of math.fsum, for comparison.  Uses a
00512         # different algorithm based on frexp, ldexp and integer
00513         # arithmetic.
00514         from sys import float_info
00515         mant_dig = float_info.mant_dig
00516         etiny = float_info.min_exp - mant_dig
00517 
00518         def msum(iterable):
00519             """Full precision summation.  Compute sum(iterable) without any
00520             intermediate accumulation of error.  Based on the 'lsum' function
00521             at http://code.activestate.com/recipes/393090/
00522 
00523             """
00524             tmant, texp = 0, 0
00525             for x in iterable:
00526                 mant, exp = math.frexp(x)
00527                 mant, exp = int(math.ldexp(mant, mant_dig)), exp - mant_dig
00528                 if texp > exp:
00529                     tmant <<= texp-exp
00530                     texp = exp
00531                 else:
00532                     mant <<= exp-texp
00533                 tmant += mant
00534             # Round tmant * 2**texp to a float.  The original recipe
00535             # used float(str(tmant)) * 2.0**texp for this, but that's
00536             # a little unsafe because str -> float conversion can't be
00537             # relied upon to do correct rounding on all platforms.
00538             tail = max(len(bin(abs(tmant)))-2 - mant_dig, etiny - texp)
00539             if tail > 0:
00540                 h = 1 << (tail-1)
00541                 tmant = tmant // (2*h) + bool(tmant & h and tmant & 3*h-1)
00542                 texp += tail
00543             return math.ldexp(tmant, texp)
00544 
00545         test_values = [
00546             ([], 0.0),
00547             ([0.0], 0.0),
00548             ([1e100, 1.0, -1e100, 1e-100, 1e50, -1.0, -1e50], 1e-100),
00549             ([2.0**53, -0.5, -2.0**-54], 2.0**53-1.0),
00550             ([2.0**53, 1.0, 2.0**-100], 2.0**53+2.0),
00551             ([2.0**53+10.0, 1.0, 2.0**-100], 2.0**53+12.0),
00552             ([2.0**53-4.0, 0.5, 2.0**-54], 2.0**53-3.0),
00553             ([1./n for n in range(1, 1001)],
00554              float.fromhex('0x1.df11f45f4e61ap+2')),
00555             ([(-1.)**n/n for n in range(1, 1001)],
00556              float.fromhex('-0x1.62a2af1bd3624p-1')),
00557             ([1.7**(i+1)-1.7**i for i in range(1000)] + [-1.7**1000], -1.0),
00558             ([1e16, 1., 1e-16], 10000000000000002.0),
00559             ([1e16-2., 1.-2.**-53, -(1e16-2.), -(1.-2.**-53)], 0.0),
00560             # exercise code for resizing partials array
00561             ([2.**n - 2.**(n+50) + 2.**(n+52) for n in range(-1074, 972, 2)] +
00562              [-2.**1022],
00563              float.fromhex('0x1.5555555555555p+970')),
00564             ]
00565 
00566         for i, (vals, expected) in enumerate(test_values):
00567             try:
00568                 actual = math.fsum(vals)
00569             except OverflowError:
00570                 self.fail("test %d failed: got OverflowError, expected %r "
00571                           "for math.fsum(%.100r)" % (i, expected, vals))
00572             except ValueError:
00573                 self.fail("test %d failed: got ValueError, expected %r "
00574                           "for math.fsum(%.100r)" % (i, expected, vals))
00575             self.assertEqual(actual, expected)
00576 
00577         from random import random, gauss, shuffle
00578         for j in range(1000):
00579             vals = [7, 1e100, -7, -1e100, -9e-20, 8e-20] * 10
00580             s = 0
00581             for i in range(200):
00582                 v = gauss(0, random()) ** 7 - s
00583                 s += v
00584                 vals.append(v)
00585             shuffle(vals)
00586 
00587             s = msum(vals)
00588             self.assertEqual(msum(vals), math.fsum(vals))

Here is the call graph for this function:

Definition at line 589 of file test_math.py.

00589 
00590     def testHypot(self):
00591         self.assertRaises(TypeError, math.hypot)
00592         self.ftest('hypot(0,0)', math.hypot(0,0), 0)
00593         self.ftest('hypot(3,4)', math.hypot(3,4), 5)
00594         self.assertEqual(math.hypot(NAN, INF), INF)
00595         self.assertEqual(math.hypot(INF, NAN), INF)
00596         self.assertEqual(math.hypot(NAN, NINF), INF)
00597         self.assertEqual(math.hypot(NINF, NAN), INF)
00598         self.assertTrue(math.isnan(math.hypot(1.0, NAN)))
00599         self.assertTrue(math.isnan(math.hypot(NAN, -2.0)))

Here is the call graph for this function:

Definition at line 925 of file test_math.py.

00925 
00926     def testIsfinite(self):
00927         self.assertTrue(math.isfinite(0.0))
00928         self.assertTrue(math.isfinite(-0.0))
00929         self.assertTrue(math.isfinite(1.0))
00930         self.assertTrue(math.isfinite(-1.0))
00931         self.assertFalse(math.isfinite(float("nan")))
00932         self.assertFalse(math.isfinite(float("inf")))
00933         self.assertFalse(math.isfinite(float("-inf")))

Here is the call graph for this function:

Definition at line 941 of file test_math.py.

00941 
00942     def testIsinf(self):
00943         self.assertTrue(math.isinf(float("inf")))
00944         self.assertTrue(math.isinf(float("-inf")))
00945         self.assertTrue(math.isinf(1E400))
00946         self.assertTrue(math.isinf(-1E400))
00947         self.assertFalse(math.isinf(float("nan")))
00948         self.assertFalse(math.isinf(0.))
00949         self.assertFalse(math.isinf(1.))

Here is the call graph for this function:

Definition at line 934 of file test_math.py.

00934 
00935     def testIsnan(self):
00936         self.assertTrue(math.isnan(float("nan")))
00937         self.assertTrue(math.isnan(float("inf")* 0.))
00938         self.assertFalse(math.isnan(float("inf")))
00939         self.assertFalse(math.isnan(0.))
00940         self.assertFalse(math.isnan(1.))

Here is the call graph for this function:

Definition at line 600 of file test_math.py.

00600 
00601     def testLdexp(self):
00602         self.assertRaises(TypeError, math.ldexp)
00603         self.ftest('ldexp(0,1)', math.ldexp(0,1), 0)
00604         self.ftest('ldexp(1,1)', math.ldexp(1,1), 2)
00605         self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5)
00606         self.ftest('ldexp(-1,1)', math.ldexp(-1,1), -2)
00607         self.assertRaises(OverflowError, math.ldexp, 1., 1000000)
00608         self.assertRaises(OverflowError, math.ldexp, -1., 1000000)
00609         self.assertEqual(math.ldexp(1., -1000000), 0.)
00610         self.assertEqual(math.ldexp(-1., -1000000), -0.)
00611         self.assertEqual(math.ldexp(INF, 30), INF)
00612         self.assertEqual(math.ldexp(NINF, -213), NINF)
00613         self.assertTrue(math.isnan(math.ldexp(NAN, 0)))
00614 
00615         # large second argument
00616         for n in [10**5, 10**10, 10**20, 10**40]:
00617             self.assertEqual(math.ldexp(INF, -n), INF)
00618             self.assertEqual(math.ldexp(NINF, -n), NINF)
00619             self.assertEqual(math.ldexp(1., -n), 0.)
00620             self.assertEqual(math.ldexp(-1., -n), -0.)
00621             self.assertEqual(math.ldexp(0., -n), 0.)
00622             self.assertEqual(math.ldexp(-0., -n), -0.)
00623             self.assertTrue(math.isnan(math.ldexp(NAN, -n)))
00624 
00625             self.assertRaises(OverflowError, math.ldexp, 1., n)
00626             self.assertRaises(OverflowError, math.ldexp, -1., n)
00627             self.assertEqual(math.ldexp(0., n), 0.)
00628             self.assertEqual(math.ldexp(-0., n), -0.)
00629             self.assertEqual(math.ldexp(INF, n), INF)
00630             self.assertEqual(math.ldexp(NINF, n), NINF)
00631             self.assertTrue(math.isnan(math.ldexp(NAN, n)))

Here is the call graph for this function:

Definition at line 632 of file test_math.py.

00632 
00633     def testLog(self):
00634         self.assertRaises(TypeError, math.log)
00635         self.ftest('log(1/e)', math.log(1/math.e), -1)
00636         self.ftest('log(1)', math.log(1), 0)
00637         self.ftest('log(e)', math.log(math.e), 1)
00638         self.ftest('log(32,2)', math.log(32,2), 5)
00639         self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
00640         self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
00641         self.ftest('log(10**1000)', math.log(10**1000),
00642                    2302.5850929940457)
00643         self.assertRaises(ValueError, math.log, -1.5)
00644         self.assertRaises(ValueError, math.log, -10**1000)
00645         self.assertRaises(ValueError, math.log, NINF)
00646         self.assertEqual(math.log(INF), INF)
00647         self.assertTrue(math.isnan(math.log(NAN)))

Here is the call graph for this function:

Definition at line 653 of file test_math.py.

00653 
00654     def testLog10(self):
00655         self.assertRaises(TypeError, math.log10)
00656         self.ftest('log10(0.1)', math.log10(0.1), -1)
00657         self.ftest('log10(1)', math.log10(1), 0)
00658         self.ftest('log10(10)', math.log10(10), 1)
00659         self.ftest('log10(10**1000)', math.log10(10**1000), 1000.0)
00660         self.assertRaises(ValueError, math.log10, -1.5)
00661         self.assertRaises(ValueError, math.log10, -10**1000)
00662         self.assertRaises(ValueError, math.log10, NINF)
00663         self.assertEqual(math.log(INF), INF)
00664         self.assertTrue(math.isnan(math.log10(NAN)))

Here is the call graph for this function:

Definition at line 648 of file test_math.py.

00648 
00649     def testLog1p(self):
00650         self.assertRaises(TypeError, math.log1p)
00651         n= 2**90
00652         self.assertAlmostEqual(math.log1p(n), math.log1p(float(n)))

Here is the call graph for this function:

Definition at line 665 of file test_math.py.

00665 
00666     def testModf(self):
00667         self.assertRaises(TypeError, math.modf)
00668 
00669         def testmodf(name, result, expected):
00670             (v1, v2), (e1, e2) = result, expected
00671             if abs(v1-e1) > eps or abs(v2-e2):
00672                 self.fail('%s returned %r, expected %r'%\
00673                           (name, result, expected))
00674 
00675         testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0))
00676         testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))
00677 
00678         self.assertEqual(math.modf(INF), (0.0, INF))
00679         self.assertEqual(math.modf(NINF), (-0.0, NINF))
00680 
00681         modf_nan = math.modf(NAN)
00682         self.assertTrue(math.isnan(modf_nan[0]))
00683         self.assertTrue(math.isnan(modf_nan[1]))

Here is the call graph for this function:

Definition at line 684 of file test_math.py.

00684 
00685     def testPow(self):
00686         self.assertRaises(TypeError, math.pow)
00687         self.ftest('pow(0,1)', math.pow(0,1), 0)
00688         self.ftest('pow(1,0)', math.pow(1,0), 1)
00689         self.ftest('pow(2,1)', math.pow(2,1), 2)
00690         self.ftest('pow(2,-1)', math.pow(2,-1), 0.5)
00691         self.assertEqual(math.pow(INF, 1), INF)
00692         self.assertEqual(math.pow(NINF, 1), NINF)
00693         self.assertEqual((math.pow(1, INF)), 1.)
00694         self.assertEqual((math.pow(1, NINF)), 1.)
00695         self.assertTrue(math.isnan(math.pow(NAN, 1)))
00696         self.assertTrue(math.isnan(math.pow(2, NAN)))
00697         self.assertTrue(math.isnan(math.pow(0, NAN)))
00698         self.assertEqual(math.pow(1, NAN), 1)
00699 
00700         # pow(0., x)
00701         self.assertEqual(math.pow(0., INF), 0.)
00702         self.assertEqual(math.pow(0., 3.), 0.)
00703         self.assertEqual(math.pow(0., 2.3), 0.)
00704         self.assertEqual(math.pow(0., 2.), 0.)
00705         self.assertEqual(math.pow(0., 0.), 1.)
00706         self.assertEqual(math.pow(0., -0.), 1.)
00707         self.assertRaises(ValueError, math.pow, 0., -2.)
00708         self.assertRaises(ValueError, math.pow, 0., -2.3)
00709         self.assertRaises(ValueError, math.pow, 0., -3.)
00710         self.assertRaises(ValueError, math.pow, 0., NINF)
00711         self.assertTrue(math.isnan(math.pow(0., NAN)))
00712 
00713         # pow(INF, x)
00714         self.assertEqual(math.pow(INF, INF), INF)
00715         self.assertEqual(math.pow(INF, 3.), INF)
00716         self.assertEqual(math.pow(INF, 2.3), INF)
00717         self.assertEqual(math.pow(INF, 2.), INF)
00718         self.assertEqual(math.pow(INF, 0.), 1.)
00719         self.assertEqual(math.pow(INF, -0.), 1.)
00720         self.assertEqual(math.pow(INF, -2.), 0.)
00721         self.assertEqual(math.pow(INF, -2.3), 0.)
00722         self.assertEqual(math.pow(INF, -3.), 0.)
00723         self.assertEqual(math.pow(INF, NINF), 0.)
00724         self.assertTrue(math.isnan(math.pow(INF, NAN)))
00725 
00726         # pow(-0., x)
00727         self.assertEqual(math.pow(-0., INF), 0.)
00728         self.assertEqual(math.pow(-0., 3.), -0.)
00729         self.assertEqual(math.pow(-0., 2.3), 0.)
00730         self.assertEqual(math.pow(-0., 2.), 0.)
00731         self.assertEqual(math.pow(-0., 0.), 1.)
00732         self.assertEqual(math.pow(-0., -0.), 1.)
00733         self.assertRaises(ValueError, math.pow, -0., -2.)
00734         self.assertRaises(ValueError, math.pow, -0., -2.3)
00735         self.assertRaises(ValueError, math.pow, -0., -3.)
00736         self.assertRaises(ValueError, math.pow, -0., NINF)
00737         self.assertTrue(math.isnan(math.pow(-0., NAN)))
00738 
00739         # pow(NINF, x)
00740         self.assertEqual(math.pow(NINF, INF), INF)
00741         self.assertEqual(math.pow(NINF, 3.), NINF)
00742         self.assertEqual(math.pow(NINF, 2.3), INF)
00743         self.assertEqual(math.pow(NINF, 2.), INF)
00744         self.assertEqual(math.pow(NINF, 0.), 1.)
00745         self.assertEqual(math.pow(NINF, -0.), 1.)
00746         self.assertEqual(math.pow(NINF, -2.), 0.)
00747         self.assertEqual(math.pow(NINF, -2.3), 0.)
00748         self.assertEqual(math.pow(NINF, -3.), -0.)
00749         self.assertEqual(math.pow(NINF, NINF), 0.)
00750         self.assertTrue(math.isnan(math.pow(NINF, NAN)))
00751 
00752         # pow(-1, x)
00753         self.assertEqual(math.pow(-1., INF), 1.)
00754         self.assertEqual(math.pow(-1., 3.), -1.)
00755         self.assertRaises(ValueError, math.pow, -1., 2.3)
00756         self.assertEqual(math.pow(-1., 2.), 1.)
00757         self.assertEqual(math.pow(-1., 0.), 1.)
00758         self.assertEqual(math.pow(-1., -0.), 1.)
00759         self.assertEqual(math.pow(-1., -2.), 1.)
00760         self.assertRaises(ValueError, math.pow, -1., -2.3)
00761         self.assertEqual(math.pow(-1., -3.), -1.)
00762         self.assertEqual(math.pow(-1., NINF), 1.)
00763         self.assertTrue(math.isnan(math.pow(-1., NAN)))
00764 
00765         # pow(1, x)
00766         self.assertEqual(math.pow(1., INF), 1.)
00767         self.assertEqual(math.pow(1., 3.), 1.)
00768         self.assertEqual(math.pow(1., 2.3), 1.)
00769         self.assertEqual(math.pow(1., 2.), 1.)
00770         self.assertEqual(math.pow(1., 0.), 1.)
00771         self.assertEqual(math.pow(1., -0.), 1.)
00772         self.assertEqual(math.pow(1., -2.), 1.)
00773         self.assertEqual(math.pow(1., -2.3), 1.)
00774         self.assertEqual(math.pow(1., -3.), 1.)
00775         self.assertEqual(math.pow(1., NINF), 1.)
00776         self.assertEqual(math.pow(1., NAN), 1.)
00777 
00778         # pow(x, 0) should be 1 for any x
00779         self.assertEqual(math.pow(2.3, 0.), 1.)
00780         self.assertEqual(math.pow(-2.3, 0.), 1.)
00781         self.assertEqual(math.pow(NAN, 0.), 1.)
00782         self.assertEqual(math.pow(2.3, -0.), 1.)
00783         self.assertEqual(math.pow(-2.3, -0.), 1.)
00784         self.assertEqual(math.pow(NAN, -0.), 1.)
00785 
00786         # pow(x, y) is invalid if x is negative and y is not integral
00787         self.assertRaises(ValueError, math.pow, -1., 2.3)
00788         self.assertRaises(ValueError, math.pow, -15., -3.1)
00789 
00790         # pow(x, NINF)
00791         self.assertEqual(math.pow(1.9, NINF), 0.)
00792         self.assertEqual(math.pow(1.1, NINF), 0.)
00793         self.assertEqual(math.pow(0.9, NINF), INF)
00794         self.assertEqual(math.pow(0.1, NINF), INF)
00795         self.assertEqual(math.pow(-0.1, NINF), INF)
00796         self.assertEqual(math.pow(-0.9, NINF), INF)
00797         self.assertEqual(math.pow(-1.1, NINF), 0.)
00798         self.assertEqual(math.pow(-1.9, NINF), 0.)
00799 
00800         # pow(x, INF)
00801         self.assertEqual(math.pow(1.9, INF), INF)
00802         self.assertEqual(math.pow(1.1, INF), INF)
00803         self.assertEqual(math.pow(0.9, INF), 0.)
00804         self.assertEqual(math.pow(0.1, INF), 0.)
00805         self.assertEqual(math.pow(-0.1, INF), 0.)
00806         self.assertEqual(math.pow(-0.9, INF), 0.)
00807         self.assertEqual(math.pow(-1.1, INF), INF)
00808         self.assertEqual(math.pow(-1.9, INF), INF)
00809 
00810         # pow(x, y) should work for x negative, y an integer
00811         self.ftest('(-2.)**3.', math.pow(-2.0, 3.0), -8.0)
00812         self.ftest('(-2.)**2.', math.pow(-2.0, 2.0), 4.0)
00813         self.ftest('(-2.)**1.', math.pow(-2.0, 1.0), -2.0)
00814         self.ftest('(-2.)**0.', math.pow(-2.0, 0.0), 1.0)
00815         self.ftest('(-2.)**-0.', math.pow(-2.0, -0.0), 1.0)
00816         self.ftest('(-2.)**-1.', math.pow(-2.0, -1.0), -0.5)
00817         self.ftest('(-2.)**-2.', math.pow(-2.0, -2.0), 0.25)
00818         self.ftest('(-2.)**-3.', math.pow(-2.0, -3.0), -0.125)
00819         self.assertRaises(ValueError, math.pow, -2.0, -0.5)
00820         self.assertRaises(ValueError, math.pow, -2.0, 0.5)
00821 
00822         # the following tests have been commented out since they don't
00823         # really belong here:  the implementation of ** for floats is
00824         # independent of the implementation of math.pow
00825         #self.assertEqual(1**NAN, 1)
00826         #self.assertEqual(1**INF, 1)
00827         #self.assertEqual(1**NINF, 1)
00828         #self.assertEqual(1**0, 1)
00829         #self.assertEqual(1.**NAN, 1)
00830         #self.assertEqual(1.**INF, 1)
00831         #self.assertEqual(1.**NINF, 1)
00832         #self.assertEqual(1.**0, 1)

Here is the call graph for this function:

Definition at line 833 of file test_math.py.

00833 
00834     def testRadians(self):
00835         self.assertRaises(TypeError, math.radians)
00836         self.ftest('radians(180)', math.radians(180), math.pi)
00837         self.ftest('radians(90)', math.radians(90), math.pi/2)
00838         self.ftest('radians(-45)', math.radians(-45), -math.pi/4)

Here is the call graph for this function:

Definition at line 839 of file test_math.py.

00839 
00840     def testSin(self):
00841         self.assertRaises(TypeError, math.sin)
00842         self.ftest('sin(0)', math.sin(0), 0)
00843         self.ftest('sin(pi/2)', math.sin(math.pi/2), 1)
00844         self.ftest('sin(-pi/2)', math.sin(-math.pi/2), -1)
00845         try:
00846             self.assertTrue(math.isnan(math.sin(INF)))
00847             self.assertTrue(math.isnan(math.sin(NINF)))
00848         except ValueError:
00849             self.assertRaises(ValueError, math.sin, INF)
00850             self.assertRaises(ValueError, math.sin, NINF)
00851         self.assertTrue(math.isnan(math.sin(NAN)))

Here is the call graph for this function:

Definition at line 852 of file test_math.py.

00852 
00853     def testSinh(self):
00854         self.assertRaises(TypeError, math.sinh)
00855         self.ftest('sinh(0)', math.sinh(0), 0)
00856         self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1)
00857         self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0)
00858         self.assertEqual(math.sinh(INF), INF)
00859         self.assertEqual(math.sinh(NINF), NINF)
00860         self.assertTrue(math.isnan(math.sinh(NAN)))

Here is the call graph for this function:

Definition at line 861 of file test_math.py.

00861 
00862     def testSqrt(self):
00863         self.assertRaises(TypeError, math.sqrt)
00864         self.ftest('sqrt(0)', math.sqrt(0), 0)
00865         self.ftest('sqrt(1)', math.sqrt(1), 1)
00866         self.ftest('sqrt(4)', math.sqrt(4), 2)
00867         self.assertEqual(math.sqrt(INF), INF)
00868         self.assertRaises(ValueError, math.sqrt, NINF)
00869         self.assertTrue(math.isnan(math.sqrt(NAN)))

Here is the call graph for this function:

Definition at line 870 of file test_math.py.

00870 
00871     def testTan(self):
00872         self.assertRaises(TypeError, math.tan)
00873         self.ftest('tan(0)', math.tan(0), 0)
00874         self.ftest('tan(pi/4)', math.tan(math.pi/4), 1)
00875         self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1)
00876         try:
00877             self.assertTrue(math.isnan(math.tan(INF)))
00878             self.assertTrue(math.isnan(math.tan(NINF)))
00879         except:
00880             self.assertRaises(ValueError, math.tan, INF)
00881             self.assertRaises(ValueError, math.tan, NINF)
00882         self.assertTrue(math.isnan(math.tan(NAN)))

Here is the call graph for this function:

Definition at line 883 of file test_math.py.

00883 
00884     def testTanh(self):
00885         self.assertRaises(TypeError, math.tanh)
00886         self.ftest('tanh(0)', math.tanh(0), 0)
00887         self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
00888         self.ftest('tanh(inf)', math.tanh(INF), 1)
00889         self.ftest('tanh(-inf)', math.tanh(NINF), -1)
00890         self.assertTrue(math.isnan(math.tanh(NAN)))

Here is the call graph for this function:

Definition at line 894 of file test_math.py.

00894 
00895     def testTanhSign(self):
00896         # check that tanh(-0.) == -0. on IEEE 754 systems
00897         self.assertEqual(math.tanh(-0.), -0.)
00898         self.assertEqual(math.copysign(1., math.tanh(-0.)),
00899                          math.copysign(1., -0.))

Here is the call graph for this function:


The documentation for this class was generated from the following file: