pymath.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Symbols and macros to supply platform-independent interfaces to mathematical
  2. // functions and constants.
  3. #ifndef Py_PYMATH_H
  4. #define Py_PYMATH_H
  5. /* High precision definition of pi and e (Euler)
  6. * The values are taken from libc6's math.h.
  7. */
  8. #ifndef Py_MATH_PIl
  9. #define Py_MATH_PIl 3.1415926535897932384626433832795029L
  10. #endif
  11. #ifndef Py_MATH_PI
  12. #define Py_MATH_PI 3.14159265358979323846
  13. #endif
  14. #ifndef Py_MATH_El
  15. #define Py_MATH_El 2.7182818284590452353602874713526625L
  16. #endif
  17. #ifndef Py_MATH_E
  18. #define Py_MATH_E 2.7182818284590452354
  19. #endif
  20. /* Tau (2pi) to 40 digits, taken from tauday.com/tau-digits. */
  21. #ifndef Py_MATH_TAU
  22. #define Py_MATH_TAU 6.2831853071795864769252867665590057683943L
  23. #endif
  24. // Py_IS_NAN(X)
  25. // Return 1 if float or double arg is a NaN, else 0.
  26. #define Py_IS_NAN(X) isnan(X)
  27. // Py_IS_INFINITY(X)
  28. // Return 1 if float or double arg is an infinity, else 0.
  29. #define Py_IS_INFINITY(X) isinf(X)
  30. // Py_IS_FINITE(X)
  31. // Return 1 if float or double arg is neither infinite nor NAN, else 0.
  32. #define Py_IS_FINITE(X) isfinite(X)
  33. // Py_INFINITY: Value that evaluates to a positive double infinity.
  34. #ifndef Py_INFINITY
  35. # define Py_INFINITY ((double)INFINITY)
  36. #endif
  37. /* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically
  38. * this was not reliable and Python did not require IEEE floats and C99
  39. * conformity. Prefer Py_INFINITY for new code.
  40. */
  41. #ifndef Py_HUGE_VAL
  42. # define Py_HUGE_VAL HUGE_VAL
  43. #endif
  44. /* Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN). The sign is
  45. * undefined and normally not relevant, but e.g. fixed for float("nan").
  46. */
  47. #if !defined(Py_NAN)
  48. # define Py_NAN ((double)NAN)
  49. #endif
  50. #endif /* Py_PYMATH_H */