Implement libc.math and test it
authorOndrej Certik <ondrej@certik.cz>
Sat, 4 Dec 2010 02:24:33 +0000 (18:24 -0800)
committerOndrej Certik <ondrej@certik.cz>
Sat, 4 Dec 2010 02:32:47 +0000 (18:32 -0800)
Basic math.h constants and functions were added. Now when one wants to speedup
the following code::

    from math import sin, cos
    e = sin(5) + cos(6)

one can do::

    from libc.math cimport sin, cos
    e = sin(5) + cos(6)

Not all math.h features are wrapped (yet), but basic functions should work.

Signed-off-by: Ondrej Certik <ondrej@certik.cz>
Cython/Includes/libc/math.pxd [new file with mode: 0644]
tests/compile/libc_math.pyx [new file with mode: 0644]

diff --git a/Cython/Includes/libc/math.pxd b/Cython/Includes/libc/math.pxd
new file mode 100644 (file)
index 0000000..69bea8e
--- /dev/null
@@ -0,0 +1,37 @@
+cdef extern from "math.h":
+
+    enum: M_E
+    enum: M_LOG2E
+    enum: M_LOG10E
+    enum: M_LN2
+    enum: M_LN10
+    enum: M_PI
+    enum: M_PI_2
+    enum: M_PI_4
+    enum: M_1_PI
+    enum: M_2_PI
+    enum: M_2_SQRTPI
+    enum: M_SQRT2
+    enum: M_SQRT1_2
+
+    double acos(double x)
+    double asin(double x)
+    double atan(double x)
+    double atan2(double y, double x)
+    double cos(double x)
+    double sin(double x)
+    double tan(double x)
+
+    double cosh(double x)
+    double sinh(double x)
+    double tanh(double x)
+    double acosh(double x)
+    double asinh(double x)
+    double atanh(double x)
+
+    double exp(double x)
+    double log(double x)
+    double log10(double x)
+
+    double pow(double x, double y)
+    double sqrt(double x)
diff --git a/tests/compile/libc_math.pyx b/tests/compile/libc_math.pyx
new file mode 100644 (file)
index 0000000..08e5990
--- /dev/null
@@ -0,0 +1,4 @@
+from libc.math cimport (M_E, M_LOG2E, M_LOG10E, M_LN2, M_LN10, M_PI, M_PI_2,
+        M_PI_4, M_1_PI, M_2_PI, M_2_SQRTPI, M_SQRT2, M_SQRT1_2)
+from libc.math cimport (acos, asin, atan, atan2, cos, sin, tan, cosh, sinh,
+        tanh, acosh, asinh, atanh, exp, log, log10, pow, sqrt)