[pypy-svn] r15936 - in pypy/dist/pypy: rpython rpython/module rpython/module/test translator/c translator/c/src translator/c/test

pedronis at codespeak.net pedronis at codespeak.net
Wed Aug 10 19:55:13 CEST 2005


Author: pedronis
Date: Wed Aug 10 19:55:08 2005
New Revision: 15936

Modified:
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/ll_math.py
   pypy/dist/pypy/rpython/module/test/test_ll_math.py
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/ll_math.h
   pypy/dist/pypy/translator/c/test/test_extfunc.py
Log:
math.pow backend support



Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Wed Aug 10 19:55:08 2005
@@ -100,6 +100,7 @@
 declare(math.ldexp  , float         ,  'll_math/ldexp')
 declare(math.modf   , modfannotation, 'll_math/modf')
 declare(math.hypot  , float         , 'll_math/hypot')
+declare(math.pow    , float         , 'll_math/pow')
 
 # the following functions all take one float, return one float
 # and are part of math.h

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	Wed Aug 10 19:55:08 2005
@@ -15,6 +15,9 @@
     ll_math_%(name)s.suggested_primitive = True
     """ % {"name": name}).compile()
 
+def ll_math_pow(x, y):
+    return math.pow(x, y)
+ll_math_pow.suggested_primitive = True
 
 FREXP_RESULT = lltype.GcStruct('tuple2', ('item0', lltype.Float),
                                ('item1', lltype.Signed))

Modified: pypy/dist/pypy/rpython/module/test/test_ll_math.py
==============================================================================
--- pypy/dist/pypy/rpython/module/test/test_ll_math.py	(original)
+++ pypy/dist/pypy/rpython/module/test/test_ll_math.py	Wed Aug 10 19:55:08 2005
@@ -36,3 +36,7 @@
 def test_ll_math_fabs():
     assert ll_math_fabs(math.pi/3) == math.fabs(math.pi/3)
     assert ll_math_fabs(-math.pi/3) == math.fabs(-math.pi/3)
+
+def test_ll_math_pow():
+    assert ll_math_pow(2.0, 3.0) == math.pow(2.0, 3.0)
+    assert ll_math_pow(3.0, 2.0) == math.pow(3.0, 2.0)

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Wed Aug 10 19:55:08 2005
@@ -24,6 +24,7 @@
     ll_time.ll_time_clock: 'LL_time_clock',
     ll_time.ll_time_sleep: 'LL_time_sleep',
     ll_time.ll_time_time:  'LL_time_time',
+    ll_math.ll_math_pow:   'LL_math_pow',
     ll_math.ll_math_frexp: 'LL_math_frexp',
     ll_math.ll_math_atan2: 'LL_math_atan2',
     ll_math.ll_math_fmod : 'LL_math_fmod',

Modified: pypy/dist/pypy/translator/c/src/ll_math.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_math.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_math.h	Wed Aug 10 19:55:08 2005
@@ -11,6 +11,10 @@
 /* XXX completely ignoring exceptions/error checking for now */
 
 
+double LL_math_pow(double x, double y) {
+  return pow(x, y);
+}
+
 RPyFREXP_RESULT* LL_math_frexp(double x) {
   int expo;
   double m = frexp(x, &expo);

Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py	Wed Aug 10 19:55:08 2005
@@ -141,6 +141,19 @@
     res = f1()
     assert res == os.strerror(2)
 
+def test_math_pow():
+    import math
+    def fn(x, y):
+        return math.pow(x, y)
+    f = compile(fn, [float, float])
+    assert f(2.0, 3.0) == math.pow(2.0, 3.0)
+    assert f(3.0, 2.0) == math.pow(3.0, 2.0)
+    assert f(2.3, 0.0) == math.pow(2.3, 0.0)
+    assert f(2.3, -1.0) == math.pow(2.3, -1.0)
+    assert f(2.3, -2.0) == math.pow(2.3, -2.0)
+    assert f(2.3, 0.5) == math.pow(2.3, 0.5)
+    assert f(4.0, 0.5) == math.pow(4.0, 0.5)    
+
 def test_math_frexp():
     from math import frexp
     def fn(x):



More information about the Pypy-commit mailing list