[pypy-svn] r15279 - in pypy/dist/pypy/rpython: . module

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Jul 28 19:26:57 CEST 2005


Author: cfbolz
Date: Thu Jul 28 19:26:55 2005
New Revision: 15279

Modified:
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/ll_math.py
Log:
added missing math functions to external function table

Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Thu Jul 28 19:26:55 2005
@@ -83,21 +83,24 @@
 declare(time.time   , float         , 'll_time/time')
 declare(time.clock  , float         , 'll_time/clock')
 declare(time.sleep  , noneannotation, 'll_time/sleep')
-declare(math.log10  , float         , 'll_math/log10')
-declare(math.log    , float         , 'll_math/log')
-declare(math.cos    , float         , 'll_math/cos')
-declare(math.sin    , float         , 'll_math/sin')
-declare(math.sinh   , float         , 'll_math/sinh')
-declare(math.cosh   , float         , 'll_math/cosh')
-declare(math.acos   , float         , 'll_math/acos')
-declare(math.sqrt   , float         , 'll_math/sqrt')
-declare(math.hypot  , float         , 'll_math/hypot')
-declare(math.ceil   , float         , 'll_math/ceil')
+
+# ___________________________
+# math functions
+
 declare(math.frexp  , frexpannotation, 'll_math/frexp')
 declare(math.atan2  , float         , 'll_math/atan2')
 declare(math.fmod   , float         ,  'll_math/fmod')
 declare(math.floor  , float         ,  'll_math/floor')
-declare(math.exp    , float         ,  'll_math/exp')
 declare(math.ldexp  , float         ,  'll_math/ldexp')
 declare(math.modf   , modfannotation, 'll_math/modf')
-declare(math.fabs    , float         , 'll_math/fabs')
+declare(math.hypot  , float         , 'll_math/hypot')
+
+# the following functions all take one float, return one float
+# and are part of math.h
+simple_math_functions = [
+    'acos', 'asin', 'atan', 'ceil', 'cos', 'cosh', 'exp', 'fabs',
+    'floor', 'log', 'log10', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
+    ]
+
+for name in simple_math_functions:
+    declare(getattr(math, name), float, 'll_math/%s' % name)

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	Thu Jul 28 19:26:55 2005
@@ -1,46 +1,19 @@
 from pypy.rpython import lltype
 
 import math
+import py
 
-def ll_math_cos(x):
-    return math.cos(x)
-ll_math_cos.suggested_primitive = True
-
-def ll_math_sin(x):
-    return math.sin(x)
-ll_math_sin.suggested_primitive = True
-
-def ll_math_acos(x):
-    return math.acos(x)
-ll_math_acos.suggested_primitive = True
-
-def ll_math_sinh(x):
-    return math.sinh(x)
-ll_math_sinh.suggested_primitive = True
-
-def ll_math_cosh(x):
-    return math.cosh(x)
-ll_math_cosh.suggested_primitive = True
-
-def ll_math_hypot(x, y):
-    return math.hypot(x, y)
-ll_math_hypot.suggested_primitive = True
-
-def ll_math_sqrt(x):
-    return math.sqrt(x)
-ll_math_sqrt.suggested_primitive = True
-
-def ll_math_log(x):
-    return math.log(x)
-ll_math_log.suggested_primitive = True
-
-def ll_math_log10(x):
-    return math.log10(x)
-ll_math_log10.suggested_primitive = True
-
-def ll_math_ceil(x):
-    return math.ceil(x)
-ll_math_ceil.suggested_primitive = True
+simple_math_functions = [
+    'acos', 'asin', 'atan', 'ceil', 'cos', 'cosh', 'exp', 'fabs',
+    'floor', 'log', 'log10', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
+    ]
+
+for name in simple_math_functions:
+    exec py.code.Source("""
+    def ll_math_%(name)s(x):
+        return math.%(name)s(x)
+    ll_math_%(name)s.suggested_primitive = True
+    """ % {"name": name}).compile()
 
 
 FREXP_RESULT = lltype.GcStruct('tuple2', ('item0', lltype.Float),
@@ -65,15 +38,9 @@
     return math.fmod(x, y)
 ll_math_fmod.suggested_primitive = True
 
-def ll_math_floor(x):
-    return math.floor(x)
-ll_math_floor.suggested_primitive = True
-
-def ll_math_exp(x):
-    return math.exp(x)
-
 def ll_math_ldexp(x, y):
     return math.ldexp(x, y)
+ll_math_ldexp.suggested_primitive = True
 
 MODF_RESULT = lltype.GcStruct('tuple2', ('item0', lltype.Float),
                        ('item1', lltype.Float))
@@ -89,6 +56,6 @@
     return ll_modf_result(fracpart, intpart)
 ll_math_modf.suggested_primitive = True
 
-def ll_math_fabs(x):
-    return math.fabs(x)
-ll_math_fabs.suggested_primitive = True
+def ll_math_hypot(x, y):
+    return math.hypot(x, y)
+ll_math_hypot.suggested_primitive = True



More information about the Pypy-commit mailing list