Commit 608641ca authored by Stefan Behnel's avatar Stefan Behnel

add "e" and "pi" aliases to libc.math declarations to bring it closer to a...

add "e" and "pi" aliases to libc.math declarations to bring it closer to a drop-in replacement for Python's math module
parent f121eebd
......@@ -24,6 +24,9 @@ Features added
* for-loop iteration over "std::string".
* ``libc/math.pxd`` provides ``e`` and ``pi`` as alias constants to simplify
usage as a drop-in replacement for Python's math module.
Bugs fixed
----------
......
cdef extern from "math.h" nogil:
double M_E
double e "M_E" # as in Python's math module
double M_LOG2E
double M_LOG10E
double M_LN2
double M_LN10
double M_PI
double pi "M_PI" # as in Python's math module
double M_PI_2
double M_PI_4
double M_1_PI
......@@ -16,6 +18,7 @@ cdef extern from "math.h" nogil:
# C99 constants
float INFINITY
float NAN
# note: not providing "nan" and "inf" aliases here as nan() is a function in C
double HUGE_VAL
float HUGE_VALF
long double HUGE_VALL
......
# mode: run
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)
cimport libc.math as libc_math
def test_pi():
"""
......@@ -11,6 +15,16 @@ def test_pi():
"""
return M_PI
def test_renamed_constants(math):
"""
>>> import math
>>> test_renamed_constants(math)
"""
assert libc_math.M_E == libc_math.e == math.e
assert libc_math.M_PI == libc_math.pi == math.pi
def test_sin(x):
"""
>>> test_sin(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment