File: libc_math.pyx

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (54 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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, modf, sin, sinf, sinl,
        tan, cosh, sinh, tanh, acosh, asinh, atanh, exp, log, log10, pow, sqrt)
cimport libc.math as libc_math


def test_pi():
    """
    >>> import math
    >>> test_pi() == math.pi
    True
    """
    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)
    0.0
    >>> from math import sin
    >>> [sin(k) == test_sin(k) for k in range(10)]
    [True, True, True, True, True, True, True, True, True, True]
    """
    return sin(x)


def test_sin_kwarg(x):
    """
    >>> test_sin_kwarg(0)
    0.0
    """
    return sin(x=x)


def test_modf(x):
    """
    >>> test_modf(2.5)
    (0.5, 2.0)
    """
    cdef double i
    cdef double f = modf(x, &i)
    return (f, i)