config.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. // Copyright (c) 2006-7 John Maddock
  2. // Copyright (c) 2021 Matt Borland
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_MATH_TOOLS_CONFIG_HPP
  7. #define BOOST_MATH_TOOLS_CONFIG_HPP
  8. #ifdef _MSC_VER
  9. #pragma once
  10. #endif
  11. #include <boost/math/tools/is_standalone.hpp>
  12. // Minimum language standard transition
  13. #ifdef _MSVC_LANG
  14. # if _MSVC_LANG < 201402L
  15. # pragma warning("The minimum language standard to use Boost.Math will be C++14 starting in July 2023 (Boost 1.82 release)");
  16. # endif
  17. #else
  18. # if __cplusplus < 201402L
  19. # warning "The minimum language standard to use Boost.Math will be C++14 starting in July 2023 (Boost 1.82 release)"
  20. # endif
  21. #endif
  22. #ifndef BOOST_MATH_STANDALONE
  23. #include <boost/config.hpp>
  24. #else // Things from boost/config that are required, and easy to replicate
  25. #define BOOST_PREVENT_MACRO_SUBSTITUTION
  26. #define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  27. #define BOOST_MATH_NO_DISTRIBUTION_CONCEPT_TESTS
  28. #define BOOST_MATH_NO_LEXICAL_CAST
  29. // Since Boost.Multiprecision is in active development some tests do not fully cooperate yet.
  30. #define BOOST_MATH_NO_MP_TESTS
  31. #if (__cplusplus > 201400L || _MSVC_LANG > 201400L)
  32. #define BOOST_CXX14_CONSTEXPR constexpr
  33. #else
  34. #define BOOST_CXX14_CONSTEXPR
  35. #define BOOST_NO_CXX14_CONSTEXPR
  36. #endif // BOOST_CXX14_CONSTEXPR
  37. #if (__cplusplus > 201700L || _MSVC_LANG > 201700L)
  38. #define BOOST_IF_CONSTEXPR if constexpr
  39. // Clang on mac provides the execution header with none of the functionality. TODO: Check back on this
  40. // https://en.cppreference.com/w/cpp/compiler_support "Standardization of Parallelism TS"
  41. #if !__has_include(<execution>) || (defined(__APPLE__) && defined(__clang__))
  42. #define BOOST_NO_CXX17_HDR_EXECUTION
  43. #endif
  44. #else
  45. #define BOOST_IF_CONSTEXPR if
  46. #define BOOST_NO_CXX17_IF_CONSTEXPR
  47. #define BOOST_NO_CXX17_HDR_EXECUTION
  48. #endif
  49. #if __cpp_lib_gcd_lcm >= 201606L
  50. #define BOOST_MATH_HAS_CXX17_NUMERIC
  51. #endif
  52. #define BOOST_JOIN(X, Y) BOOST_DO_JOIN(X, Y)
  53. #define BOOST_DO_JOIN(X, Y) BOOST_DO_JOIN2(X,Y)
  54. #define BOOST_DO_JOIN2(X, Y) X##Y
  55. #define BOOST_STRINGIZE(X) BOOST_DO_STRINGIZE(X)
  56. #define BOOST_DO_STRINGIZE(X) #X
  57. #ifdef BOOST_DISABLE_THREADS // No threads, do nothing
  58. // Detect thread support via STL implementation
  59. #elif defined(__has_include)
  60. # if !__has_include(<thread>) || !__has_include(<mutex>) || !__has_include(<future>) || !__has_include(<atomic>)
  61. # define BOOST_DISABLE_THREADS
  62. # else
  63. # define BOOST_HAS_THREADS
  64. # endif
  65. #else
  66. # define BOOST_HAS_THREADS // The default assumption is that the machine has threads
  67. #endif // Thread Support
  68. #ifdef BOOST_DISABLE_THREADS
  69. # define BOOST_NO_CXX11_HDR_ATOMIC
  70. # define BOOST_NO_CXX11_HDR_FUTURE
  71. # define BOOST_NO_CXX11_HDR_THREAD
  72. # define BOOST_NO_CXX11_THREAD_LOCAL
  73. #endif // BOOST_DISABLE_THREADS
  74. #ifdef __GNUC__
  75. # if !defined(__EXCEPTIONS) && !defined(BOOST_NO_EXCEPTIONS)
  76. # define BOOST_NO_EXCEPTIONS
  77. # endif
  78. //
  79. // Make sure we have some std lib headers included so we can detect __GXX_RTTI:
  80. //
  81. # include <algorithm> // for min and max
  82. # include <limits>
  83. # ifndef __GXX_RTTI
  84. # ifndef BOOST_NO_TYPEID
  85. # define BOOST_NO_TYPEID
  86. # endif
  87. # ifndef BOOST_NO_RTTI
  88. # define BOOST_NO_RTTI
  89. # endif
  90. # endif
  91. #endif
  92. #if !defined(BOOST_NOINLINE)
  93. # if defined(_MSC_VER)
  94. # define BOOST_NOINLINE __declspec(noinline)
  95. # elif defined(__GNUC__) && __GNUC__ > 3
  96. // Clang also defines __GNUC__ (as 4)
  97. # if defined(__CUDACC__)
  98. // nvcc doesn't always parse __noinline__,
  99. // see: https://svn.boost.org/trac/boost/ticket/9392
  100. # define BOOST_NOINLINE __attribute__ ((noinline))
  101. # elif defined(__HIP__)
  102. // See https://github.com/boostorg/config/issues/392
  103. # define BOOST_NOINLINE __attribute__ ((noinline))
  104. # else
  105. # define BOOST_NOINLINE __attribute__ ((__noinline__))
  106. # endif
  107. # else
  108. # define BOOST_NOINLINE
  109. # endif
  110. #endif
  111. #if !defined(BOOST_FORCEINLINE)
  112. # if defined(_MSC_VER)
  113. # define BOOST_FORCEINLINE __forceinline
  114. # elif defined(__GNUC__) && __GNUC__ > 3
  115. // Clang also defines __GNUC__ (as 4)
  116. # define BOOST_FORCEINLINE inline __attribute__ ((__always_inline__))
  117. # else
  118. # define BOOST_FORCEINLINE inline
  119. # endif
  120. #endif
  121. #endif // BOOST_MATH_STANDALONE
  122. // Support compilers with P0024R2 implemented without linking TBB
  123. // https://en.cppreference.com/w/cpp/compiler_support
  124. #if !defined(BOOST_NO_CXX17_HDR_EXECUTION) && defined(BOOST_HAS_THREADS)
  125. # define BOOST_MATH_EXEC_COMPATIBLE
  126. #endif
  127. // C++23
  128. #if __cplusplus > 202002L || _MSVC_LANG > 202002L
  129. # if __GNUC__ >= 13
  130. // libstdc++3 only defines to/from_chars for std::float128_t when one of these defines are set
  131. // otherwise we're right out of luck...
  132. # if defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128) || defined(_GLIBCXX_HAVE_FLOAT128_MATH)
  133. # include <cstring> // std::strlen is used with from_chars
  134. # include <charconv>
  135. # include <stdfloat>
  136. # define BOOST_MATH_USE_CHARCONV_FOR_CONVERSION
  137. # endif
  138. # endif
  139. #endif
  140. #include <algorithm> // for min and max
  141. #include <limits>
  142. #include <cmath>
  143. #include <climits>
  144. #include <cfloat>
  145. #include <boost/math/tools/user.hpp>
  146. #if (defined(__NetBSD__) || defined(__EMSCRIPTEN__)\
  147. || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \
  148. && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  149. //# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  150. #endif
  151. #ifdef __IBMCPP__
  152. //
  153. // For reasons I don't understand, the tests with IMB's compiler all
  154. // pass at long double precision, but fail with real_concept, those tests
  155. // are disabled for now. (JM 2012).
  156. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  157. # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  158. #endif // BOOST_MATH_NO_REAL_CONCEPT_TESTS
  159. #endif
  160. #ifdef sun
  161. // Any use of __float128 in program startup code causes a segfault (tested JM 2015, Solaris 11).
  162. # define BOOST_MATH_DISABLE_FLOAT128
  163. #endif
  164. #ifdef __HAIKU__
  165. //
  166. // Not sure what's up with the math detection on Haiku, but linking fails with
  167. // float128 code enabled, and we don't have an implementation of __expl, so
  168. // disabling long double functions for now as well.
  169. # define BOOST_MATH_DISABLE_FLOAT128
  170. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  171. #endif
  172. #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  173. //
  174. // Darwin's rather strange "double double" is rather hard to
  175. // support, it should be possible given enough effort though...
  176. //
  177. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  178. #endif
  179. #if !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) && (LDBL_MANT_DIG == 106) && (LDBL_MIN_EXP > DBL_MIN_EXP)
  180. //
  181. // Generic catch all case for gcc's "double-double" long double type.
  182. // We do not support this as it's not even remotely IEEE conforming:
  183. //
  184. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  185. #endif
  186. #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  187. //
  188. // Intel compiler prior to version 10 has sporadic problems
  189. // calling the long double overloads of the std lib math functions:
  190. // calling ::powl is OK, but std::pow(long double, long double)
  191. // may segfault depending upon the value of the arguments passed
  192. // and the specific Linux distribution.
  193. //
  194. // We'll be conservative and disable long double support for this compiler.
  195. //
  196. // Comment out this #define and try building the tests to determine whether
  197. // your Intel compiler version has this issue or not.
  198. //
  199. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  200. #endif
  201. #if defined(unix) && defined(__INTEL_COMPILER)
  202. //
  203. // Intel compiler has sporadic issues compiling std::fpclassify depending on
  204. // the exact OS version used. Use our own code for this as we know it works
  205. // well on Intel processors:
  206. //
  207. #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
  208. #endif
  209. #if defined(_MSC_VER) && !defined(_WIN32_WCE)
  210. // Better safe than sorry, our tests don't support hardware exceptions:
  211. # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
  212. #endif
  213. #ifdef __IBMCPP__
  214. # define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
  215. #endif
  216. #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
  217. # define BOOST_MATH_USE_C99
  218. #endif
  219. #if (defined(__hpux) && !defined(__hppa))
  220. # define BOOST_MATH_USE_C99
  221. #endif
  222. #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
  223. # define BOOST_MATH_USE_C99
  224. #endif
  225. #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
  226. # define BOOST_MATH_USE_C99
  227. #endif
  228. #if defined(__CYGWIN__) || defined(__HP_aCC) || defined(__INTEL_COMPILER) \
  229. || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
  230. || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\
  231. || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  232. # define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
  233. #endif
  234. #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x590)
  235. namespace boost { namespace math { namespace tools { namespace detail {
  236. template <typename T>
  237. struct type {};
  238. template <typename T, T n>
  239. struct non_type {};
  240. }}}} // Namespace boost, math tools, detail
  241. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::math::tools::detail::type<t>* = 0
  242. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::math::tools::detail::type<t>*
  243. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::math::tools::detail::non_type<t, v>* = 0
  244. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::math::tools::detail::non_type<t, v>*
  245. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
  246. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  247. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
  248. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  249. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
  250. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  251. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
  252. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  253. #else
  254. // no workaround needed: expand to nothing
  255. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  256. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  257. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  258. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  259. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
  260. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  261. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  262. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  263. #endif // __SUNPRO_CC
  264. #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)
  265. // Sun's compiler emits a hard error if a constant underflows,
  266. // as does aCC on PA-RISC, while gcc issues a large number of warnings:
  267. # define BOOST_MATH_SMALL_CONSTANT(x) 0.0
  268. #else
  269. # define BOOST_MATH_SMALL_CONSTANT(x) x
  270. #endif
  271. //
  272. // Tune performance options for specific compilers:
  273. //
  274. #ifdef _MSC_VER
  275. # define BOOST_MATH_POLY_METHOD 2
  276. #if _MSC_VER <= 1900
  277. # define BOOST_MATH_RATIONAL_METHOD 1
  278. #else
  279. # define BOOST_MATH_RATIONAL_METHOD 2
  280. #endif
  281. #if _MSC_VER > 1900
  282. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  283. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  284. #endif
  285. #elif defined(__INTEL_COMPILER)
  286. # define BOOST_MATH_POLY_METHOD 2
  287. # define BOOST_MATH_RATIONAL_METHOD 1
  288. #elif defined(__GNUC__)
  289. #if __GNUC__ < 4
  290. # define BOOST_MATH_POLY_METHOD 3
  291. # define BOOST_MATH_RATIONAL_METHOD 3
  292. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  293. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  294. #else
  295. # define BOOST_MATH_POLY_METHOD 3
  296. # define BOOST_MATH_RATIONAL_METHOD 3
  297. #endif
  298. #elif defined(__clang__)
  299. #if __clang__ > 6
  300. # define BOOST_MATH_POLY_METHOD 3
  301. # define BOOST_MATH_RATIONAL_METHOD 3
  302. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  303. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  304. #endif
  305. #endif
  306. //
  307. // noexcept support:
  308. //
  309. #include <type_traits>
  310. #define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value)
  311. #define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value)
  312. //
  313. // The maximum order of polynomial that will be evaluated
  314. // via an unrolled specialisation:
  315. //
  316. #ifndef BOOST_MATH_MAX_POLY_ORDER
  317. # define BOOST_MATH_MAX_POLY_ORDER 20
  318. #endif
  319. //
  320. // Set the method used to evaluate polynomials and rationals:
  321. //
  322. #ifndef BOOST_MATH_POLY_METHOD
  323. # define BOOST_MATH_POLY_METHOD 2
  324. #endif
  325. #ifndef BOOST_MATH_RATIONAL_METHOD
  326. # define BOOST_MATH_RATIONAL_METHOD 1
  327. #endif
  328. //
  329. // decide whether to store constants as integers or reals:
  330. //
  331. #ifndef BOOST_MATH_INT_TABLE_TYPE
  332. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
  333. #endif
  334. #ifndef BOOST_MATH_INT_VALUE_SUFFIX
  335. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
  336. #endif
  337. //
  338. // And then the actual configuration:
  339. //
  340. #if defined(BOOST_MATH_STANDALONE) && defined(_GLIBCXX_USE_FLOAT128) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && !defined(__STRICT_ANSI__) \
  341. && !defined(BOOST_MATH_DISABLE_FLOAT128) && !defined(BOOST_MATH_USE_FLOAT128)
  342. # define BOOST_MATH_USE_FLOAT128
  343. #elif defined(BOOST_HAS_FLOAT128) && !defined(BOOST_MATH_USE_FLOAT128)
  344. # define BOOST_MATH_USE_FLOAT128
  345. #endif
  346. #ifdef BOOST_MATH_USE_FLOAT128
  347. //
  348. // Only enable this when the compiler really is GCC as clang and probably
  349. // intel too don't support __float128 yet :-(
  350. //
  351. # if defined(__INTEL_COMPILER) && defined(__GNUC__)
  352. # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
  353. # define BOOST_MATH_FLOAT128_TYPE __float128
  354. # endif
  355. # elif defined(__GNUC__)
  356. # define BOOST_MATH_FLOAT128_TYPE __float128
  357. # endif
  358. # ifndef BOOST_MATH_FLOAT128_TYPE
  359. # define BOOST_MATH_FLOAT128_TYPE _Quad
  360. # endif
  361. #endif
  362. //
  363. // Check for WinCE with no iostream support:
  364. //
  365. #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
  366. # define BOOST_MATH_NO_LEXICAL_CAST
  367. #endif
  368. //
  369. // Helper macro for controlling the FP behaviour:
  370. //
  371. #ifndef BOOST_MATH_CONTROL_FP
  372. # define BOOST_MATH_CONTROL_FP
  373. #endif
  374. //
  375. // Helper macro for using statements:
  376. //
  377. #define BOOST_MATH_STD_USING_CORE \
  378. using std::abs;\
  379. using std::acos;\
  380. using std::cos;\
  381. using std::fmod;\
  382. using std::modf;\
  383. using std::tan;\
  384. using std::asin;\
  385. using std::cosh;\
  386. using std::frexp;\
  387. using std::pow;\
  388. using std::tanh;\
  389. using std::atan;\
  390. using std::exp;\
  391. using std::ldexp;\
  392. using std::sin;\
  393. using std::atan2;\
  394. using std::fabs;\
  395. using std::log;\
  396. using std::sinh;\
  397. using std::ceil;\
  398. using std::floor;\
  399. using std::log10;\
  400. using std::sqrt;
  401. #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
  402. namespace boost{ namespace math{
  403. namespace tools
  404. {
  405. template <class T>
  406. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T)
  407. {
  408. return (std::max)((std::max)(a, b), c);
  409. }
  410. template <class T>
  411. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T)
  412. {
  413. return (std::max)((std::max)(a, b), (std::max)(c, d));
  414. }
  415. } // namespace tools
  416. template <class T>
  417. void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T)
  418. {
  419. }
  420. namespace detail{
  421. template <class T>
  422. struct is_integer_for_rounding
  423. {
  424. static constexpr bool value = std::is_integral<T>::value || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer);
  425. };
  426. }
  427. }} // namespace boost namespace math
  428. #ifdef __GLIBC_PREREQ
  429. # if __GLIBC_PREREQ(2,14)
  430. # define BOOST_MATH_HAVE_FIXED_GLIBC
  431. # endif
  432. #endif
  433. #if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__))
  434. //
  435. // This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445
  436. // Basically powl and expl can return garbage when the result is small and certain exception flags are set
  437. // on entrance to these functions. This appears to have been fixed in Glibc 2.14 (May 2011).
  438. // Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4
  439. //
  440. #include <cfenv>
  441. # ifdef FE_ALL_EXCEPT
  442. namespace boost{ namespace math{
  443. namespace detail
  444. {
  445. struct fpu_guard
  446. {
  447. fpu_guard()
  448. {
  449. fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
  450. feclearexcept(FE_ALL_EXCEPT);
  451. }
  452. ~fpu_guard()
  453. {
  454. fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
  455. }
  456. private:
  457. fexcept_t m_flags;
  458. };
  459. } // namespace detail
  460. }} // namespaces
  461. # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
  462. # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
  463. # else
  464. # define BOOST_FPU_EXCEPTION_GUARD
  465. # define BOOST_MATH_INSTRUMENT_FPU
  466. # endif
  467. #else // All other platforms.
  468. # define BOOST_FPU_EXCEPTION_GUARD
  469. # define BOOST_MATH_INSTRUMENT_FPU
  470. #endif
  471. #ifdef BOOST_MATH_INSTRUMENT
  472. # include <iostream>
  473. # include <iomanip>
  474. # include <typeinfo>
  475. # define BOOST_MATH_INSTRUMENT_CODE(x) \
  476. std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
  477. # define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(#name << " = " << name)
  478. #else
  479. # define BOOST_MATH_INSTRUMENT_CODE(x)
  480. # define BOOST_MATH_INSTRUMENT_VARIABLE(name)
  481. #endif
  482. //
  483. // Thread local storage:
  484. //
  485. #ifndef BOOST_DISABLE_THREADS
  486. # define BOOST_MATH_THREAD_LOCAL thread_local
  487. #else
  488. # define BOOST_MATH_THREAD_LOCAL
  489. #endif
  490. //
  491. // Some mingw flavours have issues with thread_local and types with non-trivial destructors
  492. // See https://sourceforge.net/p/mingw-w64/bugs/527/
  493. //
  494. #if (defined(__MINGW32__) && (__GNUC__ < 9) && !defined(__clang__))
  495. # define BOOST_MATH_NO_THREAD_LOCAL_WITH_NON_TRIVIAL_TYPES
  496. #endif
  497. //
  498. // Can we have constexpr tables?
  499. //
  500. #if (!defined(BOOST_NO_CXX14_CONSTEXPR)) || (defined(_MSC_VER) && _MSC_VER >= 1910)
  501. #define BOOST_MATH_HAVE_CONSTEXPR_TABLES
  502. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr
  503. #else
  504. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION
  505. #endif
  506. #endif // BOOST_MATH_TOOLS_CONFIG_HPP