[pypy-svn] r75855 - in pypy/branch/fast-forward/pypy/module/math: . test

benjamin at codespeak.net benjamin at codespeak.net
Mon Jul 5 20:41:08 CEST 2010


Author: benjamin
Date: Mon Jul  5 20:41:07 2010
New Revision: 75855

Modified:
   pypy/branch/fast-forward/pypy/module/math/interp_math.py
   pypy/branch/fast-forward/pypy/module/math/test/test_math.py
Log:
passing a large long to ldexp changes it to LONG_MAX

Modified: pypy/branch/fast-forward/pypy/module/math/interp_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/interp_math.py	(original)
+++ pypy/branch/fast-forward/pypy/module/math/interp_math.py	Mon Jul  5 20:41:07 2010
@@ -1,4 +1,5 @@
 import math
+import sys
 
 from pypy.rlib import rarithmetic
 from pypy.interpreter.error import OperationError
@@ -84,11 +85,25 @@
     return math1(space, math.cosh, x)
 cosh.unwrap_spec = [ObjSpace, float]
 
-def ldexp(space, x,  i): 
+def ldexp(space, x,  w_i): 
     """ldexp(x, i) -> x * (2**i)
     """
-    return math2(space, math.ldexp, x,  i)
-ldexp.unwrap_spec = [ObjSpace, float, int]
+    if (space.isinstance_w(w_i, space.w_int) or
+        space.isinstance_w(w_i, space.w_long)):
+        try:
+            exp = space.int_w(w_i)
+        except OperationError, e:
+            if not e.match(space, space.w_OverflowError):
+                raise
+            if space.is_true(space.lt(w_i, space.wrap(0))):
+                exp = -sys.maxint
+            else:
+                exp = sys.maxint
+    else:
+        raise OperationError(space.w_TypeError,
+                             space.wrap("integer required for second argument"))
+    return math2(space, math.ldexp, x, exp)
+ldexp.unwrap_spec = [ObjSpace, float, W_Root]
 
 def hypot(space, x, y): 
     """hypot(x,y)

Modified: pypy/branch/fast-forward/pypy/module/math/test/test_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/test/test_math.py	(original)
+++ pypy/branch/fast-forward/pypy/module/math/test/test_math.py	Mon Jul  5 20:41:07 2010
@@ -36,6 +36,10 @@
                     raise AssertionError("%s(%s): got %s" % (
                         fnname, ', '.join(map(str, args)), got))
 
+    def test_ldexp(self):
+        import math
+        assert math.ldexp(float("inf"), -10**20) == float("inf")
+
     def test_fsum(self):
         # Python version of math.fsum, for comparison.  Uses a
         # different algorithm based on frexp, ldexp and integer



More information about the Pypy-commit mailing list