[pypy-svn] r48972 - in pypy/dist/pypy: rpython/test translator/cli/src translator/jvm/src/pypy

antocuni at codespeak.net antocuni at codespeak.net
Fri Nov 23 11:02:53 CET 2007


Author: antocuni
Date: Fri Nov 23 11:02:53 2007
New Revision: 48972

Modified:
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
   pypy/dist/pypy/translator/cli/src/ll_math.cs
   pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
Log:
- add a test for math.ldexp
- implement math.ldexp for jvm
- fix math.ldexp for cli (what is not tested etc. etc.)



Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py	Fri Nov 23 11:02:53 2007
@@ -161,6 +161,13 @@
         mantissa, exponent = math.frexp(10/3.0)        
         assert self.float_eq(res.item0, mantissa) and self.float_eq(res.item1, exponent)
 
+    def test_builtin_math_ldexp(self):
+        import math
+        def fn(a, b):
+            return math.ldexp(a, b)
+        assert self.interpret(fn, [1, 2]) == 4
+        self.interpret_raises(OverflowError, fn, [1, 100000])
+
     def test_builtin_math_modf(self):
         import math
         def fn(f):

Modified: pypy/dist/pypy/translator/cli/src/ll_math.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/ll_math.cs	(original)
+++ pypy/dist/pypy/translator/cli/src/ll_math.cs	Fri Nov 23 11:02:53 2007
@@ -108,7 +108,7 @@
 
             // Handle overflow
             if (e >= MEXP)
-                return 2.0*MAXNUM;
+                Helpers.raise_OverflowError();
 
             if (e < 1)
             {

Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java	(original)
+++ pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java	Fri Nov 23 11:02:53 2007
@@ -249,7 +249,7 @@
         try {
             return Double.parseDouble(s);
         } catch(NumberFormatException ex) {
-            interlink.throwValueError();
+            throwValueError();
             return 0.0; // not reached
         }
     }
@@ -976,6 +976,18 @@
         return x % y;
     }
 
+    public static double ll_math_ldexp(double v, int w) {
+        return check(v * Math.pow(2.0, w));
+    }
+
+    private static double check(double v) {
+        if (Double.isNaN(v))
+            throwValueError();
+        if (Double.isInfinite(v))
+            throwOverflowError();
+        return v;
+    }
+
     // ----------------------------------------------------------------------
     // Convenient Helpers for throwing exceptions
     //



More information about the Pypy-commit mailing list