[pypy-commit] pypy py3.3: Added missing log2 in math module.

Arjun Naik noreply at buildbot.pypy.org
Sat Jul 26 12:32:30 CEST 2014


Author: Arjun Naik <arjun at arjunnaik.in>
Branch: py3.3
Changeset: r72489:342ebe4c4d7f
Date: 2014-07-26 11:16 +0200
http://bitbucket.org/pypy/pypy/changeset/342ebe4c4d7f/

Log:	Added missing log2 in math module.

diff --git a/pypy/module/math/__init__.py b/pypy/module/math/__init__.py
--- a/pypy/module/math/__init__.py
+++ b/pypy/module/math/__init__.py
@@ -23,6 +23,7 @@
        'frexp'          : 'interp_math.frexp',
        'degrees'        : 'interp_math.degrees',
        'log'            : 'interp_math.log',
+       'log2'           : 'interp_math.log2',
        'log10'          : 'interp_math.log10',
        'fmod'           : 'interp_math.fmod',
        'atan'           : 'interp_math.atan',
diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -228,6 +228,11 @@
             return math1(space, math.log, w_base)
     return _log_any(space, w_x, base)
 
+def log2(space, w_x):
+    """log2(x) -> the base 2 logarithm of x.
+    """
+    return _log_any(space, w_x, 2.0)
+
 def log10(space, w_x):
     """log10(x) -> the base 10 logarithm of x.
     """
diff --git a/pypy/module/math/test/test_math.py b/pypy/module/math/test/test_math.py
--- a/pypy/module/math/test/test_math.py
+++ b/pypy/module/math/test/test_math.py
@@ -148,6 +148,19 @@
         raises(ValueError, math.log1p, -1)
         raises(ValueError, math.log1p, -100)
 
+    def test_log2(self):
+        import math
+        self.ftest(math.log2(0.125), -3)
+        self.ftest(math.log2(0.5), -1)
+        self.ftest(math.log2(4), 2)
+
+    def test_log10(self):
+        import math
+        self.ftest(math.log10(0.1), -1)
+        self.ftest(math.log10(10), 1)
+        self.ftest(math.log10(100), 2)
+        self.ftest(math.log10(0.01), -2)
+
     def test_acosh(self):
         import math
         self.ftest(math.acosh(1), 0)


More information about the pypy-commit mailing list