math.pxd 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # NumPy math library
  2. #
  3. # This exports the functionality of the NumPy core math library, aka npymath,
  4. # which provides implementations of C99 math functions and macros for system
  5. # with a C89 library (such as MSVC). npymath is available with NumPy >=1.3,
  6. # although some functions will require later versions. The spacing function is
  7. # not in C99, but comes from Fortran.
  8. #
  9. # On the Cython side, the npymath functions are available without the "npy_"
  10. # prefix that they have in C, to make this is a drop-in replacement for
  11. # libc.math. The same is true for the constants, where possible.
  12. #
  13. # See the NumPy documentation for linking instructions.
  14. #
  15. # Complex number support and NumPy 2.0 half-precision functions are currently
  16. # not exported.
  17. #
  18. # Author: Lars Buitinck
  19. cdef extern from "numpy/npy_math.h" nogil:
  20. # Floating-point classification
  21. long double NAN "NPY_NAN"
  22. long double INFINITY "NPY_INFINITY"
  23. long double PZERO "NPY_PZERO" # positive zero
  24. long double NZERO "NPY_NZERO" # negative zero
  25. # These four are actually macros and work on any floating-point type.
  26. int isinf "npy_isinf"(long double) # -1 / 0 / 1
  27. bint isfinite "npy_isfinite"(long double)
  28. bint isnan "npy_isnan"(long double)
  29. bint signbit "npy_signbit"(long double)
  30. # Math constants
  31. long double E "NPY_E"
  32. long double LOG2E "NPY_LOG2E" # ln(e) / ln(2)
  33. long double LOG10E "NPY_LOG10E" # ln(e) / ln(10)
  34. long double LOGE2 "NPY_LOGE2" # ln(2)
  35. long double LOGE10 "NPY_LOGE10" # ln(10)
  36. long double PI "NPY_PI"
  37. long double PI_2 "NPY_PI_2" # pi / 2
  38. long double PI_4 "NPY_PI_4" # pi / 4
  39. long double NPY_1_PI # 1 / pi; NPY_ because of ident syntax
  40. long double NPY_2_PI # 2 / pi
  41. long double EULER "NPY_EULER" # Euler constant (gamma, 0.57721)
  42. # Low-level floating point manipulation (NumPy >=1.4)
  43. float copysignf "npy_copysignf"(float, float)
  44. float nextafterf "npy_nextafterf"(float x, float y)
  45. float spacingf "npy_spacingf"(float x)
  46. double copysign "npy_copysign"(double, double)
  47. double nextafter "npy_nextafter"(double x, double y)
  48. double spacing "npy_spacing"(double x)
  49. long double copysignl "npy_copysignl"(long double, long double)
  50. long double nextafterl "npy_nextafterl"(long double x, long double y)
  51. long double spacingl "npy_spacingl"(long double x)
  52. # Float C99 functions
  53. float sinf "npy_sinf"(float x)
  54. float cosf "npy_cosf"(float x)
  55. float tanf "npy_tanf"(float x)
  56. float sinhf "npy_sinhf"(float x)
  57. float coshf "npy_coshf"(float x)
  58. float tanhf "npy_tanhf"(float x)
  59. float fabsf "npy_fabsf"(float x)
  60. float floorf "npy_floorf"(float x)
  61. float ceilf "npy_ceilf"(float x)
  62. float rintf "npy_rintf"(float x)
  63. float sqrtf "npy_sqrtf"(float x)
  64. float log10f "npy_log10f"(float x)
  65. float logf "npy_logf"(float x)
  66. float expf "npy_expf"(float x)
  67. float expm1f "npy_expm1f"(float x)
  68. float asinf "npy_asinf"(float x)
  69. float acosf "npy_acosf"(float x)
  70. float atanf "npy_atanf"(float x)
  71. float asinhf "npy_asinhf"(float x)
  72. float acoshf "npy_acoshf"(float x)
  73. float atanhf "npy_atanhf"(float x)
  74. float log1pf "npy_log1pf"(float x)
  75. float exp2f "npy_exp2f"(float x)
  76. float log2f "npy_log2f"(float x)
  77. float atan2f "npy_atan2f"(float x, float y)
  78. float hypotf "npy_hypotf"(float x, float y)
  79. float powf "npy_powf"(float x, float y)
  80. float fmodf "npy_fmodf"(float x, float y)
  81. float modff "npy_modff"(float x, float* y)
  82. # Long double C99 functions
  83. long double sinl "npy_sinl"(long double x)
  84. long double cosl "npy_cosl"(long double x)
  85. long double tanl "npy_tanl"(long double x)
  86. long double sinhl "npy_sinhl"(long double x)
  87. long double coshl "npy_coshl"(long double x)
  88. long double tanhl "npy_tanhl"(long double x)
  89. long double fabsl "npy_fabsl"(long double x)
  90. long double floorl "npy_floorl"(long double x)
  91. long double ceill "npy_ceill"(long double x)
  92. long double rintl "npy_rintl"(long double x)
  93. long double sqrtl "npy_sqrtl"(long double x)
  94. long double log10l "npy_log10l"(long double x)
  95. long double logl "npy_logl"(long double x)
  96. long double expl "npy_expl"(long double x)
  97. long double expm1l "npy_expm1l"(long double x)
  98. long double asinl "npy_asinl"(long double x)
  99. long double acosl "npy_acosl"(long double x)
  100. long double atanl "npy_atanl"(long double x)
  101. long double asinhl "npy_asinhl"(long double x)
  102. long double acoshl "npy_acoshl"(long double x)
  103. long double atanhl "npy_atanhl"(long double x)
  104. long double log1pl "npy_log1pl"(long double x)
  105. long double exp2l "npy_exp2l"(long double x)
  106. long double log2l "npy_log2l"(long double x)
  107. long double atan2l "npy_atan2l"(long double x, long double y)
  108. long double hypotl "npy_hypotl"(long double x, long double y)
  109. long double powl "npy_powl"(long double x, long double y)
  110. long double fmodl "npy_fmodl"(long double x, long double y)
  111. long double modfl "npy_modfl"(long double x, long double* y)
  112. # NumPy extensions
  113. float deg2radf "npy_deg2radf"(float x)
  114. float rad2degf "npy_rad2degf"(float x)
  115. float logaddexpf "npy_logaddexpf"(float x, float y)
  116. float logaddexp2f "npy_logaddexp2f"(float x, float y)
  117. double deg2rad "npy_deg2rad"(double x)
  118. double rad2deg "npy_rad2deg"(double x)
  119. double logaddexp "npy_logaddexp"(double x, double y)
  120. double logaddexp2 "npy_logaddexp2"(double x, double y)
  121. long double deg2radl "npy_deg2radl"(long double x)
  122. long double rad2degl "npy_rad2degl"(long double x)
  123. long double logaddexpl "npy_logaddexpl"(long double x, long double y)
  124. long double logaddexp2l "npy_logaddexp2l"(long double x, long double y)