standalone_config.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2010 - 2021 Douglas Gregor
  3. // Copyright 2021 Matt Borland.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
  6. //
  7. // Used to support configuration options depending on standalone context
  8. // by providing either required support or disabling functionality
  9. #ifndef BOOST_MP_STANDALONE_CONFIG_HPP
  10. #define BOOST_MP_STANDALONE_CONFIG_HPP
  11. #include <climits>
  12. // Boost.Config is dependency free so it is considered a requirement to use Boost.Multiprecision in standalone mode
  13. #ifdef __has_include
  14. # if __has_include(<boost/config.hpp>)
  15. # include <boost/config.hpp>
  16. # include <boost/config/workaround.hpp>
  17. # else
  18. # error "Boost.Config is considered a requirement to use Boost.Multiprecision in standalone mode. A package is provided at https://github.com/boostorg/multiprecision/releases"
  19. # endif
  20. #else
  21. // Provides the less helpful fatal error: 'boost/config.hpp' file not found if not available
  22. # include <boost/config.hpp>
  23. # include <boost/config/workaround.hpp>
  24. #endif
  25. // Minimum language standard transition
  26. #ifdef _MSVC_LANG
  27. # if _MSVC_LANG < 201402L
  28. # pragma warning("The minimum language standard to use Boost.Math will be C++14 starting in July 2023 (Boost 1.82 release)");
  29. # endif
  30. #else
  31. # if __cplusplus < 201402L
  32. # warning "The minimum language standard to use Boost.Math will be C++14 starting in July 2023 (Boost 1.82 release)"
  33. # endif
  34. #endif
  35. // If any of the most frequently used boost headers are missing assume that standalone mode is supposed to be used
  36. #ifdef __has_include
  37. #if !__has_include(<boost/assert.hpp>) || !__has_include(<boost/lexical_cast.hpp>) || \
  38. !__has_include(<boost/throw_exception.hpp>) || !__has_include(<boost/predef/other/endian.h>)
  39. # ifndef BOOST_MP_STANDALONE
  40. # define BOOST_MP_STANDALONE
  41. # endif
  42. #endif
  43. #endif
  44. #ifndef BOOST_MP_STANDALONE
  45. #include <boost/integer.hpp>
  46. #include <boost/integer_traits.hpp>
  47. // Required typedefs for interoperability with standalone mode
  48. #if defined(BOOST_HAS_INT128) && defined(__cplusplus)
  49. namespace boost { namespace multiprecision {
  50. using int128_type = boost::int128_type;
  51. using uint128_type = boost::uint128_type;
  52. }}
  53. #endif
  54. #if defined(BOOST_HAS_FLOAT128) && defined(__cplusplus)
  55. namespace boost { namespace multiprecision {
  56. using float128_type = boost::float128_type;
  57. }}
  58. #endif
  59. // Boost.Math available by default
  60. #define BOOST_MP_MATH_AVAILABLE
  61. #else // Standalone mode
  62. #ifdef BOOST_MATH_STANDALONE
  63. # define BOOST_MP_MATH_AVAILABLE
  64. #endif
  65. #ifndef BOOST_MP_MATH_AVAILABLE
  66. # define BOOST_MATH_INSTRUMENT_CODE(x)
  67. #endif
  68. // Prevent Macro sub
  69. #ifndef BOOST_PREVENT_MACRO_SUBSTITUTION
  70. # define BOOST_PREVENT_MACRO_SUBSTITUTION
  71. #endif
  72. #if defined(BOOST_HAS_INT128) && defined(__cplusplus)
  73. namespace boost { namespace multiprecision {
  74. # ifdef __GNUC__
  75. __extension__ typedef __int128 int128_type;
  76. __extension__ typedef unsigned __int128 uint128_type;
  77. # else
  78. typedef __int128 int128_type;
  79. typedef unsigned __int128 uint128_type;
  80. # endif
  81. }}
  82. #endif
  83. // same again for __float128:
  84. #if defined(BOOST_HAS_FLOAT128) && defined(__cplusplus)
  85. namespace boost { namespace multiprecision {
  86. # ifdef __GNUC__
  87. __extension__ typedef __float128 float128_type;
  88. # else
  89. typedef __float128 float128_type;
  90. # endif
  91. }}
  92. #endif
  93. #endif // BOOST_MP_STANDALONE
  94. // Workarounds for numeric limits on old compilers
  95. #ifdef BOOST_HAS_INT128
  96. # ifndef INT128_MAX
  97. # define INT128_MAX static_cast<boost::multiprecision::int128_type>((static_cast<boost::multiprecision::uint128_type>(1) << ((__SIZEOF_INT128__ * __CHAR_BIT__) - 1)) - 1)
  98. # endif
  99. # ifndef INT128_MIN
  100. # define INT128_MIN (-INT128_MAX - 1)
  101. # endif
  102. # ifndef UINT128_MAX
  103. # define UINT128_MAX ((2 * static_cast<boost::multiprecision::uint128_type>(INT128_MAX)) + 1)
  104. # endif
  105. #endif
  106. #define BOOST_MP_CXX14_CONSTEXPR BOOST_CXX14_CONSTEXPR
  107. //
  108. // Early compiler versions trip over the constexpr code:
  109. //
  110. #if defined(__clang__) && (__clang_major__ < 5)
  111. #undef BOOST_MP_CXX14_CONSTEXPR
  112. #define BOOST_MP_CXX14_CONSTEXPR
  113. #endif
  114. #if defined(__apple_build_version__) && (__clang_major__ < 9)
  115. #undef BOOST_MP_CXX14_CONSTEXPR
  116. #define BOOST_MP_CXX14_CONSTEXPR
  117. #endif
  118. #if defined(BOOST_GCC) && (__GNUC__ < 6)
  119. #undef BOOST_MP_CXX14_CONSTEXPR
  120. #define BOOST_MP_CXX14_CONSTEXPR
  121. #endif
  122. #if defined(BOOST_INTEL)
  123. #undef BOOST_MP_CXX14_CONSTEXPR
  124. #define BOOST_MP_CXX14_CONSTEXPR
  125. #define BOOST_MP_NO_CONSTEXPR_DETECTION
  126. #endif
  127. #endif // BOOST_MP_STANDALONE_CONFIG_HPP