summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_math.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-08 23:01:09 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-08 23:01:09 (GMT)
commitfa0e3d52d60e515beb7ae55690888d139aae205e (patch)
tree0b28b5bcdd2953aa2ebe0a1fe114c2a15f229b1c /Lib/test/test_math.py
parent3de49192aa1a76e211a231f662f1926f439cae04 (diff)
downloadcpython-fa0e3d52d60e515beb7ae55690888d139aae205e.zip
cpython-fa0e3d52d60e515beb7ae55690888d139aae205e.tar.gz
cpython-fa0e3d52d60e515beb7ae55690888d139aae205e.tar.bz2
Issue #11888: Add log2 function to math module. Patch written by Mark
Dickinson.
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r--Lib/test/test_math.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index 1bbc22d..3b80bb6 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -649,6 +649,28 @@ class MathTests(unittest.TestCase):
n= 2**90
self.assertAlmostEqual(math.log1p(n), math.log1p(float(n)))
+ @requires_IEEE_754
+ def testLog2(self):
+ self.assertRaises(TypeError, math.log2)
+ # Check that we get exact equality for log2 of powers of 2.
+ actual = [math.log2(2.0**n) for n in range(-324, 1024)]
+ expected = [float(n) for n in range(-324, 1024)]
+ self.assertEqual(actual, expected)
+
+ # Check some integer values
+ self.assertEqual(math.log2(1), 0.0)
+ self.assertEqual(math.log2(2), 1.0)
+ self.assertEqual(math.log2(4), 2.0)
+
+ # Large integer values
+ self.assertEqual(math.log2(2**1023), 1023.0)
+ self.assertEqual(math.log2(2**1024), 1024.0)
+ self.assertEqual(math.log2(2**2000), 2000.0)
+
+ self.assertRaises(ValueError, math.log2, -1.5)
+ self.assertRaises(ValueError, math.log2, NINF)
+ self.assertTrue(math.isnan(math.log2(NAN)))
+
def testLog10(self):
self.assertRaises(TypeError, math.log10)
self.ftest('log10(0.1)', math.log10(0.1), -1)