[pypy-svn] pypy cmath: (lac, arigo)

arigo commits-noreply at bitbucket.org
Mon Jan 17 17:38:20 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: cmath
Changeset: r40784:e2ac26f4eec5
Date: 2011-01-17 17:38 +0100
http://bitbucket.org/pypy/pypy/changeset/e2ac26f4eec5/

Log:	(lac, arigo)

	Implement log(x, y) in addition to log(x).

diff --git a/pypy/module/cmath/test/test_cmath.py b/pypy/module/cmath/test/test_cmath.py
--- a/pypy/module/cmath/test/test_cmath.py
+++ b/pypy/module/cmath/test/test_cmath.py
@@ -20,6 +20,7 @@
         cls.space = gettestobjspace(usemodules=['cmath'])
 
     def test_sign(self):
+        import math
         z = eval("-0j")
         assert z == -0j
         assert math.copysign(1., z.real) == 1.
@@ -39,6 +40,11 @@
         assert math.isinf(z.real) and z.real > 0.0
         assert z.imag == 0.0 and math.copysign(1., z.imag) == -1.
 
+    def test_log(self):
+        import cmath, math
+        z = cmath.log(100j, 10j)
+        assert abs(z - (1.6824165174565446-0.46553647994440367j)) < 1e-10
+
 
 def parse_testfile(fname):
     """Parse a file with test values

diff --git a/pypy/module/cmath/interp_cmath.py b/pypy/module/cmath/interp_cmath.py
--- a/pypy/module/cmath/interp_cmath.py
+++ b/pypy/module/cmath/interp_cmath.py
@@ -1,7 +1,7 @@
 import math
 from math import fabs
 from pypy.rlib.rarithmetic import copysign, asinh, log1p
-from pypy.interpreter.gateway import ObjSpace, W_Root
+from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped
 from pypy.module.cmath import Module, names_and_docstrings
 from pypy.module.cmath.constant import DBL_MIN, CM_SCALE_UP, CM_SCALE_DOWN
 from pypy.module.cmath.constant import CM_LARGE_DOUBLE, M_LN2, DBL_MANT_DIG
@@ -266,3 +266,14 @@
             real = math.log(h)
     imag = math.atan2(y, x)
     return (real, imag)
+
+
+_inner_wrapped_log = wrapped_log
+
+def wrapped_log(space, w_z, w_base=NoneNotWrapped):
+    w_logz = _inner_wrapped_log(space, w_z)
+    if w_base is not None:
+        w_logbase = _inner_wrapped_log(space, w_base)
+        return space.truediv(w_logz, w_logbase)
+    else:
+        return w_logz


More information about the Pypy-commit mailing list