[pypy-commit] pypy py3.5: like CPython, in 'log(int)', first try to cast the int to double, and

arigo pypy.commits at gmail.com
Tue Nov 15 02:15:22 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88377:a95a63f9b6b3
Date: 2016-11-15 08:14 +0100
http://bitbucket.org/pypy/pypy/changeset/a95a63f9b6b3/

Log:	like CPython, in 'log(int)', first try to cast the int to double,
	and only if that overflows use the special very-long-int algorithm.

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
@@ -189,12 +189,15 @@
 def _log_any(space, w_x, base):
     # base is supposed to be positive or 0.0, which means we use e
     try:
-        if space.isinstance_w(w_x, space.w_int):
+        try:
+            x = _get_double(space, w_x)
+        except OverflowError:
+            if not space.isinstance_w(w_x, space.w_int):
+                raise
             # special case to support log(extremely-large-long)
             num = space.bigint_w(w_x)
             result = num.log(base)
         else:
-            x = _get_double(space, w_x)
             if base == 10.0:
                 result = math.log10(x)
             elif base == 2.0:


More information about the pypy-commit mailing list