ImathPlatform.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright Contributors to the OpenEXR Project.
  4. //
  5. //
  6. // This file contains functions and constants which aren't
  7. // provided by the system libraries, compilers, or includes on
  8. // certain platforms.
  9. //
  10. #ifndef INCLUDED_IMATHPLATFORM_H
  11. #define INCLUDED_IMATHPLATFORM_H
  12. /// @cond Doxygen_Suppress
  13. #include <math.h>
  14. #include "ImathNamespace.h"
  15. #ifdef __cplusplus
  16. IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
  17. //
  18. // Helpful macros for checking which C++ standard we are compiling with.
  19. //
  20. #if (__cplusplus >= 202002L)
  21. # define IMATH_CPLUSPLUS_VERSION 20
  22. #elif (__cplusplus >= 201703L)
  23. # define IMATH_CPLUSPLUS_VERSION 17
  24. #elif (__cplusplus >= 201402L) || (defined(_MSC_VER) && _MSC_VER >= 1914)
  25. # define IMATH_CPLUSPLUS_VERSION 14
  26. #elif (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1900)
  27. # define IMATH_CPLUSPLUS_VERSION 11
  28. #else
  29. # error "This version of Imath is meant to work only with C++11 and above"
  30. #endif
  31. //
  32. // Constexpr C++14 conditional definition
  33. //
  34. #if (IMATH_CPLUSPLUS_VERSION >= 14)
  35. #define IMATH_CONSTEXPR14 constexpr
  36. #else
  37. #define IMATH_CONSTEXPR14 /* can not be constexpr before c++14 */
  38. #endif
  39. #endif // __cplusplus
  40. #ifndef M_PI
  41. # define M_PI 3.14159265358979323846
  42. #endif
  43. #ifndef M_PI_2
  44. # define M_PI_2 1.57079632679489661923 // pi/2
  45. #endif
  46. //-----------------------------------------------------------------------------
  47. //
  48. // Some, but not all, C++ compilers support the C99 restrict
  49. // keyword or some variant of it, for example, __restrict.
  50. //
  51. //-----------------------------------------------------------------------------
  52. #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) || defined(__INTEL_COMPILER)
  53. # define IMATH_RESTRICT __restrict
  54. #else
  55. # define IMATH_RESTRICT
  56. #endif
  57. #ifdef __cplusplus
  58. IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
  59. #endif // __cplusplus
  60. /// @endcond
  61. #endif // INCLUDED_IMATHPLATFORM_H