Author: Manuel Jacob <[email protected]>
Branch: py3.3
Changeset: r76172:f38ee37c81fa
Date: 2015-02-27 14:05 +0100
http://bitbucket.org/pypy/pypy/changeset/f38ee37c81fa/

Log:    Fix math.log2(2**1023) by implementing the base-2 special case in
        rbigint.

        This commit changes the rpython subdirectory, which it shouldn't
        because this is the py3.3 branch. But there already are differences
        in the rpython subdirectory between default and py3.3, which are
        related to this change. Unfortunately, all these changes can't just
        be applied to default, because it would change sematics of the
        Python 2.7 implementation. There should be a discussion about how
        to refactor this.

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -1218,6 +1218,9 @@
         # base is supposed to be positive or 0.0, which means we use e
         if base == 10.0:
             return _loghelper(math.log10, self)
+        if base == 2.0:
+            from rpython.rlib import rfloat
+            return _loghelper(rfloat.log2, self)
         ret = _loghelper(math.log, self)
         if base != 0.0:
             ret /= math.log(base)
diff --git a/rpython/rlib/test/test_rbigint.py 
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -672,6 +672,11 @@
                 else:
                     assert ulps_check(l, math.log(op)) is None
 
+    def test_log2(self):
+        assert rbigint.fromlong(1).log(2.0) == 0.0
+        assert rbigint.fromlong(2).log(2.0) == 1.0
+        assert rbigint.fromlong(2**1023).log(2.0) == 1023.0
+
 class TestInternalFunctions(object):
     def test__inplace_divrem1(self):
         # signs are not handled in the helpers!
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to