pymath.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef Py_PYMATH_H
  2. #define Py_PYMATH_H
  3. /**************************************************************************
  4. Symbols and macros to supply platform-independent interfaces to mathematical
  5. functions and constants
  6. **************************************************************************/
  7. /* HUGE_VAL is supposed to expand to a positive double infinity. Python
  8. * uses Py_HUGE_VAL instead because some platforms are broken in this
  9. * respect. We used to embed code in pyport.h to try to worm around that,
  10. * but different platforms are broken in conflicting ways. If you're on
  11. * a platform where HUGE_VAL is defined incorrectly, fiddle your Python
  12. * config to #define Py_HUGE_VAL to something that works on your platform.
  13. */
  14. #ifndef Py_HUGE_VAL
  15. #define Py_HUGE_VAL HUGE_VAL
  16. #endif
  17. /* Py_NAN
  18. * A value that evaluates to a NaN. On IEEE 754 platforms INF*0 or
  19. * INF/INF works. Define Py_NO_NAN in pyconfig.h if your platform
  20. * doesn't support NaNs.
  21. */
  22. #if !defined(Py_NAN) && !defined(Py_NO_NAN)
  23. #if !defined(__INTEL_COMPILER)
  24. #define Py_NAN (Py_HUGE_VAL * 0.)
  25. #else /* __INTEL_COMPILER */
  26. #if defined(ICC_NAN_STRICT)
  27. #pragma float_control(push)
  28. #pragma float_control(precise, on)
  29. #pragma float_control(except, on)
  30. #if defined(_MSC_VER)
  31. __declspec(noinline)
  32. #else /* Linux */
  33. __attribute__((noinline))
  34. #endif /* _MSC_VER */
  35. static double __icc_nan()
  36. {
  37. return sqrt(-1.0);
  38. }
  39. #pragma float_control (pop)
  40. #define Py_NAN __icc_nan()
  41. #else /* ICC_NAN_RELAXED as default for Intel Compiler */
  42. static union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f};
  43. #define Py_NAN (__nan_store.__icc_nan)
  44. #endif /* ICC_NAN_STRICT */
  45. #endif /* __INTEL_COMPILER */
  46. #endif
  47. #endif /* Py_PYMATH_H */