[pypy-svn] r15281 - in pypy/dist/pypy/translator/c: . src test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Jul 28 19:33:16 CEST 2005
Author: cfbolz
Date: Thu Jul 28 19:33:14 2005
New Revision: 15281
Modified:
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:
added C implementations for all neccessary math functions plus a test
Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py (original)
+++ pypy/dist/pypy/translator/c/extfunc.py Thu Jul 28 19:33:14 2005
@@ -17,18 +17,26 @@
ll_os .ll_os_stat: 'LL_os_stat',
ll_os .ll_os_fstat: 'LL_os_fstat',
ll_time.ll_time_clock: 'LL_time_clock',
- ll_math.ll_math_ceil: 'LL_math_ceil',
ll_math.ll_math_frexp: 'LL_math_frexp',
ll_math.ll_math_atan2: 'LL_math_atan2',
ll_math.ll_math_fmod : 'LL_math_fmod',
- ll_math.ll_math_floor: 'LL_math_floor',
- ll_math.ll_math_exp: 'LL_math_exp',
ll_math.ll_math_ldexp: 'LL_math_ldexp',
- ll_math.ll_math_log10: 'LL_math_log10',
- ll_math.ll_math_log: 'LL_math_log',
ll_math.ll_math_modf: 'LL_math_modf',
}
+#______________________________________________________
+# insert 'simple' math functions into EXTERNALs table:
+
+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:
+ EXTERNALS[getattr(ll_math, 'll_math_%s' % name)] = 'LL_math_%s' % name
+
+#______________________________________________________
+
def predeclare_common_types(db, rtyper):
# Common types
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 Thu Jul 28 19:33:14 2005
@@ -12,9 +12,6 @@
/* XXX completely ignoring exceptions/error checking for now */
-double LL_math_ceil(double x) {
- return ceil(x);
-}
RPyFREXP_RESULT* LL_math_frexp(double x) {
int expo;
@@ -29,28 +26,80 @@
double LL_math_fmod(double x, double y) {
return fmod(x, y);
}
-double LL_math_floor(double x) {
- return floor(x);
+
+double LL_math_ldexp(double x, long y) {
+ return ldexp(x, (int) y);
+}
+
+
+RPyMODF_RESULT* LL_math_modf(double x) {
+ double intpart;
+ double fracpart = modf(x, &intpart);
+ return ll_modf_result(fracpart, intpart);
+}
+
+/* simple math function */
+
+double LL_math_acos(double x) {
+ return acos(x);
+}
+
+double LL_math_asin(double x) {
+ return asin(x);
+}
+
+double LL_math_atan(double x) {
+ return atan(x);
+}
+
+double LL_math_ceil(double x) {
+ return ceil(x);
+}
+
+double LL_math_cos(double x) {
+ return cos(x);
}
+
+double LL_math_cosh(double x) {
+ return cosh(x);
+}
+
double LL_math_exp(double x) {
- return exp(x);
+ return exp(x);
}
-double LL_math_ldexp(double x, long y) {
- return ldexp(x, (int) y);
+
+double LL_math_fabs(double x) {
+ return fabs(x);
+}
+
+double LL_math_floor(double x) {
+ return floor(x);
}
double LL_math_log(double x) {
- return log(x);
+ return log(x);
}
double LL_math_log10(double x) {
- return log10(x);
+ return log10(x);
}
+double LL_math_sin(double x) {
+ return sin(x);
+}
-RPyMODF_RESULT* LL_math_modf(double x) {
- double intpart;
- double fracpart = modf(x, &intpart);
- return ll_modf_result(fracpart, intpart);
+double LL_math_sinh(double x) {
+ return sinh(x);
}
+double LL_math_sqrt(double x) {
+ return sqrt(x);
+}
+
+double LL_math_tan(double x) {
+ return tan(x);
+}
+
+double LL_math_tanh(double x) {
+ return tanh(x);
+}
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 Thu Jul 28 19:33:14 2005
@@ -87,13 +87,6 @@
res = f1()
assert res == os.getcwd()
-def test_math_exp():
- from math import exp
- def fn(f):
- return exp(f)
- f = compile(fn, [float])
- assert f(1.0) == exp(1.0)
-
def test_math_frexp():
from math import frexp
def fn(x):
@@ -108,12 +101,26 @@
f = compile(fn, [float])
assert f(10.123) == modf(10.123)
-def test_math_log():
- from math import log10, log
+simple_math_functions = [
+ 'acos', 'asin', 'atan', 'ceil', 'cos', 'cosh', 'exp', 'fabs',
+ 'floor', 'log', 'log10', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
+ ]
+
+def math_function_test(funcname):
+ import random
+ import math
+ mathfn = getattr(math, funcname)
+ print funcname,
def fn(x):
- return log10(x) + log(x)
+ return mathfn(x)
f = compile(fn, [float])
- assert f(32675312.32123) == fn(32675312.32123)
+ for x in [0.12334, 0.3, 0.5, 0.9883]:
+ print x
+ assert f(x) == mathfn(x)
+
+def test_simple_math_functions():
+ for funcname in simple_math_functions:
+ yield math_function_test, funcname
def test_os_path_exists():
tmpfile = str(udir.join('test_os_path_exists.TMP'))
@@ -136,3 +143,4 @@
return os.path.isdir(directory)
f = compile(fn, [])
assert f() == False
+
More information about the Pypy-commit
mailing list