[pypy-svn] r29749 - in pypy/dist/pypy/rpython: . lltypesystem/module module ootypesystem/module test

antocuni at codespeak.net antocuni at codespeak.net
Fri Jul 7 16:43:37 CEST 2006


Author: antocuni
Date: Fri Jul  7 16:42:52 2006
New Revision: 29749

Added:
   pypy/dist/pypy/rpython/lltypesystem/module/ll_math.py   (contents, props changed)
   pypy/dist/pypy/rpython/ootypesystem/module/ll_math.py   (contents, props changed)
Modified:
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/ll_math.py
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
Log:
(antocuni, arigo)

Make ll_math.modf and ll_math.frexp typesystem-specific, and test them.



Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Fri Jul  7 16:42:52 2006
@@ -162,13 +162,13 @@
 
 def frexpannotation(*args):
     from pypy.annotation.model import SomeInteger, SomeTuple, SomeFloat
-    from pypy.rpython.module.ll_math import ll_frexp_result
+    from pypy.rpython.lltypesystem.module.ll_math import ll_frexp_result
     record_call(ll_frexp_result, (SomeFloat(), SomeInteger()), 'MATH_FREXP')
     return SomeTuple((SomeFloat(), SomeInteger()))
 
 def modfannotation(*args):
     from pypy.annotation.model import SomeTuple, SomeFloat
-    from pypy.rpython.module.ll_math import ll_modf_result
+    from pypy.rpython.lltypesystem.module.ll_math import ll_modf_result
     record_call(ll_modf_result, (SomeFloat(), SomeFloat()), 'MATH_MODF')
     return SomeTuple((SomeFloat(), SomeFloat()))
 

Added: pypy/dist/pypy/rpython/lltypesystem/module/ll_math.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/lltypesystem/module/ll_math.py	Fri Jul  7 16:42:52 2006
@@ -0,0 +1,32 @@
+import math
+
+from pypy.rpython.lltypesystem import lltype, rtupletype
+from pypy.tool.staticmethods import ClassMethods
+
+FREXP_RESULT = rtupletype.TUPLE_TYPE([lltype.Float, lltype.Signed]).TO
+MODF_RESULT = rtupletype.TUPLE_TYPE([lltype.Float, lltype.Float]).TO
+
+def ll_frexp_result(mantissa, exponent):
+    tup = lltype.malloc(FREXP_RESULT)
+    tup.item0 = mantissa
+    tup.item1 = exponent
+    return tup
+
+def ll_modf_result(fracpart, intpart):
+    tup = lltype.malloc(MODF_RESULT)
+    tup.item0 = fracpart
+    tup.item1 = intpart
+    return tup
+
+class Implementation:
+    __metaclass__ = ClassMethods
+
+    def ll_math_frexp(cls, x):
+        mantissa, exponent = math.frexp(x)
+        return ll_frexp_result(mantissa, exponent)
+    ll_math_frexp.suggested_primitive = True
+
+    def ll_math_modf(cls, x):
+        fracpart, intpart = math.modf(x)
+        return ll_modf_result(fracpart, intpart)
+    ll_math_modf.suggested_primitive = True

Modified: pypy/dist/pypy/rpython/module/ll_math.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_math.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_math.py	Fri Jul  7 16:42:52 2006
@@ -1,5 +1,3 @@
-from pypy.rpython.lltypesystem import lltype, rtupletype
-
 import math
 import py
 
@@ -19,19 +17,6 @@
     return math.pow(x, y)
 ll_math_pow.suggested_primitive = True
 
-FREXP_RESULT = rtupletype.TUPLE_TYPE([lltype.Float, lltype.Signed]).TO
-
-def ll_frexp_result(mantissa, exponent):
-    tup = lltype.malloc(FREXP_RESULT)
-    tup.item0 = mantissa
-    tup.item1 = exponent
-    return tup
-    
-def ll_math_frexp(x):
-    mantissa, exponent = math.frexp(x)
-    return ll_frexp_result(mantissa, exponent)
-ll_math_frexp.suggested_primitive = True
-
 def ll_math_atan2(x, y):
     return math.atan2(x, y)
 ll_math_atan2.suggested_primitive = True
@@ -44,19 +29,6 @@
     return math.ldexp(x, y)
 ll_math_ldexp.suggested_primitive = True
 
-MODF_RESULT = rtupletype.TUPLE_TYPE([lltype.Float, lltype.Float]).TO
-
-def ll_modf_result(fracpart, intpart):
-    tup = lltype.malloc(MODF_RESULT)
-    tup.item0 = fracpart
-    tup.item1 = intpart
-    return tup
-
-def ll_math_modf(x):
-    fracpart, intpart = math.modf(x)
-    return ll_modf_result(fracpart, intpart)
-ll_math_modf.suggested_primitive = True
-
 def ll_math_hypot(x, y):
     return math.hypot(x, y)
 ll_math_hypot.suggested_primitive = True

Added: pypy/dist/pypy/rpython/ootypesystem/module/ll_math.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/ootypesystem/module/ll_math.py	Fri Jul  7 16:42:52 2006
@@ -0,0 +1,32 @@
+import math
+
+from pypy.rpython.ootypesystem import ootype
+from pypy.tool.staticmethods import ClassMethods
+
+FREXP_RESULT = ootype.Record({"item0": ootype.Float, "item1": ootype.Signed})
+MODF_RESULT = ootype.Record({"item0": ootype.Float, "item1": ootype.Float})
+
+def ll_frexp_result(mantissa, exponent):
+    tup = ootype.new(FREXP_RESULT)
+    tup.item0 = mantissa
+    tup.item1 = exponent
+    return tup
+
+def ll_modf_result(fracpart, intpart):
+    tup = ootype.new(MODF_RESULT)
+    tup.item0 = fracpart
+    tup.item1 = intpart
+    return tup
+
+class Implementation:
+    __metaclass__ = ClassMethods
+
+    def ll_math_frexp(cls, x):
+        mantissa, exponent = math.frexp(x)
+        return ll_frexp_result(mantissa, exponent)
+    ll_math_frexp.suggested_primitive = True
+
+    def ll_math_modf(cls, x):
+        fracpart, intpart = math.modf(x)
+        return ll_modf_result(fracpart, intpart)
+    ll_math_modf.suggested_primitive = True

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 Jul  7 16:42:52 2006
@@ -132,6 +132,19 @@
                 ry = 100 * float(i-10) +0.1
                 assert fn(rv,ry) == self.interpret(fn, (rv, ry))
 
+    def test_builtin_math_frexp(self):
+        import math
+        def fn(f):
+            return math.frexp(f)
+        res = self.interpret(fn, [10/3.0])
+        assert (res.item0, res.item1) == math.frexp(10/3.0)
+
+    def test_builtin_math_modf(self):
+        import math
+        def fn(f):
+            return math.modf(f)
+        res = self.interpret(fn, [10/3.0])
+        assert (res.item0, res.item1) == math.modf(10/3.0)
 
     def test_os_getcwd(self):
         import os



More information about the Pypy-commit mailing list