summaryrefslogtreecommitdiff
path: root/Lib/test/test_math.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-04-21 13:08:03 +0000
committerChristian Heimes <christian@cheimes.de>2008-04-21 13:08:03 +0000
commite57950fbfef77f327d79a73955b42e3696ecf9f0 (patch)
tree67d0fdaadc4f912bc78626859b802b37ca1696dd /Lib/test/test_math.py
parent1a3239e94509ac236ee886ce64e6cb0c5a3fea9f (diff)
downloadcpython-git-e57950fbfef77f327d79a73955b42e3696ecf9f0.tar.gz
Merged revisions 62420-62421,62423-62424 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r62420 | mark.dickinson | 2008-04-20 20:30:05 +0200 (Sun, 20 Apr 2008) | 3 lines Even more fixes for alpha Tru64, this time for the phase and polar methods. ........ r62421 | mark.dickinson | 2008-04-20 22:38:48 +0200 (Sun, 20 Apr 2008) | 2 lines Add test for tanh(-0.) == -0. on IEEE 754 systems ........ r62423 | amaury.forgeotdarc | 2008-04-20 23:02:21 +0200 (Sun, 20 Apr 2008) | 3 lines Correct an apparent refleak in test_pkgutil: zipimport._zip_directory_cache contains info for all processed zip files, even when they are no longer used. ........ r62424 | mark.dickinson | 2008-04-20 23:39:04 +0200 (Sun, 20 Apr 2008) | 4 lines math.atan2 is misbehaving on Windows; this patch should fix the problem in the same way that the cmath.phase problems were fixed. ........
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r--Lib/test/test_math.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index 401fc1efc8..da8a0e9b9d 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -124,6 +124,59 @@ class MathTests(unittest.TestCase):
self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4)
self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2)
+ # math.atan2(0, x)
+ self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
+ self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi)
+ self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi)
+ self.assertEqual(math.atan2(0., 0.), 0.)
+ self.assertEqual(math.atan2(0., 2.3), 0.)
+ self.assertEqual(math.atan2(0., INF), 0.)
+ self.assert_(math.isnan(math.atan2(0., NAN)))
+ # math.atan2(-0, x)
+ self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi)
+ self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi)
+ self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi)
+ self.assertEqual(math.atan2(-0., 0.), -0.)
+ self.assertEqual(math.atan2(-0., 2.3), -0.)
+ self.assertEqual(math.atan2(-0., INF), -0.)
+ self.assert_(math.isnan(math.atan2(-0., NAN)))
+ # math.atan2(INF, x)
+ self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4)
+ self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2)
+ self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2)
+ self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2)
+ self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2)
+ self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4)
+ self.assert_(math.isnan(math.atan2(INF, NAN)))
+ # math.atan2(NINF, x)
+ self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4)
+ self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2)
+ self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2)
+ self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2)
+ self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2)
+ self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4)
+ self.assert_(math.isnan(math.atan2(NINF, NAN)))
+ # math.atan2(+finite, x)
+ self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi)
+ self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2)
+ self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2)
+ self.assertEqual(math.atan2(2.3, INF), 0.)
+ self.assert_(math.isnan(math.atan2(2.3, NAN)))
+ # math.atan2(-finite, x)
+ self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi)
+ self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2)
+ self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2)
+ self.assertEqual(math.atan2(-2.3, INF), -0.)
+ self.assert_(math.isnan(math.atan2(-2.3, NAN)))
+ # math.atan2(NAN, x)
+ self.assert_(math.isnan(math.atan2(NAN, NINF)))
+ self.assert_(math.isnan(math.atan2(NAN, -2.3)))
+ self.assert_(math.isnan(math.atan2(NAN, -0.)))
+ self.assert_(math.isnan(math.atan2(NAN, 0.)))
+ self.assert_(math.isnan(math.atan2(NAN, 2.3)))
+ self.assert_(math.isnan(math.atan2(NAN, INF)))
+ self.assert_(math.isnan(math.atan2(NAN, NAN)))
+
def testCeil(self):
self.assertRaises(TypeError, math.ceil)
self.assertEquals(int, type(math.ceil(0.5)))
@@ -575,6 +628,11 @@ class MathTests(unittest.TestCase):
self.ftest('tanh(inf)', math.tanh(INF), 1)
self.ftest('tanh(-inf)', math.tanh(NINF), -1)
self.assert_(math.isnan(math.tanh(NAN)))
+ # check that tanh(-0.) == -0. on IEEE 754 systems
+ if float.__getformat__("double").startswith("IEEE"):
+ self.assertEqual(math.tanh(-0.), -0.)
+ self.assertEqual(math.copysign(1., math.tanh(-0.)),
+ math.copysign(1., -0.))
def test_trunc(self):
self.assertEqual(math.trunc(1), 1)