config.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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. #ifndef __CUDACC_RTC__
  12. #include <boost/math/tools/is_standalone.hpp>
  13. // Minimum language standard transition
  14. #ifdef _MSVC_LANG
  15. # if _MSVC_LANG < 201402L
  16. # pragma message("Boost.Math requires C++14");
  17. # endif
  18. # if _MSC_VER == 1900
  19. # pragma message("MSVC 14.0 has broken C++14 constexpr support. Support for this compiler will be removed in Boost 1.86")
  20. # endif
  21. #else
  22. # if __cplusplus < 201402L
  23. # warning "Boost.Math requires C++14"
  24. # endif
  25. #endif
  26. #ifndef BOOST_MATH_STANDALONE
  27. #include <boost/config.hpp>
  28. // The following are all defined as standalone macros as well
  29. // If Boost.Config is available just use those definitions because they are more fine-grained
  30. // Could be defined in TR1
  31. #ifndef BOOST_MATH_PREVENT_MACRO_SUBSTITUTION
  32. # define BOOST_MATH_PREVENT_MACRO_SUBSTITUTION BOOST_PREVENT_MACRO_SUBSTITUTION
  33. #endif
  34. #define BOOST_MATH_CXX14_CONSTEXPR BOOST_CXX14_CONSTEXPR
  35. #ifdef BOOST_NO_CXX14_CONSTEXPR
  36. # define BOOST_MATH_NO_CXX14_CONSTEXPR
  37. #endif
  38. #define BOOST_MATH_IF_CONSTEXPR BOOST_IF_CONSTEXPR
  39. #ifdef BOOST_NO_CXX17_IF_CONSTEXPR
  40. # define BOOST_MATH_NO_CXX17_IF_CONSTEXPR
  41. #endif
  42. #ifdef BOOST_NO_CXX17_HDR_EXECUTION
  43. # define BOOST_MATH_NO_CXX17_HDR_EXECUTION
  44. #endif
  45. #ifdef BOOST_HAS_THREADS
  46. # define BOOST_MATH_HAS_THREADS
  47. #endif
  48. #ifdef BOOST_DISABLE_THREADS
  49. # define BOOST_MATH_DISABLE_THREADS
  50. #endif
  51. #ifdef BOOST_NO_CXX11_THREAD_LOCAL
  52. # define BOOST_MATH_NO_CXX11_THREAD_LOCAL
  53. #endif
  54. #ifdef BOOST_NO_EXCEPTIONS
  55. # define BOOST_MATH_NO_EXCEPTIONS
  56. #endif
  57. #ifdef BOOST_NO_TYPEID
  58. # define BOOST_MATH_NO_TYPEID
  59. #endif
  60. #ifdef BOOST_NO_RTTI
  61. # define BOOST_MATH_NO_RTTI
  62. #endif
  63. #define BOOST_MATH_NOINLINE BOOST_NOINLINE
  64. #define BOOST_MATH_FORCEINLINE BOOST_FORCEINLINE
  65. #define BOOST_MATH_JOIN(X, Y) BOOST_JOIN(X, Y)
  66. #define BOOST_MATH_STRINGIZE(X) BOOST_STRINGIZE(X)
  67. #else // Things from boost/config that are required, and easy to replicate
  68. #define BOOST_MATH_PREVENT_MACRO_SUBSTITUTION
  69. #define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  70. #define BOOST_MATH_NO_DISTRIBUTION_CONCEPT_TESTS
  71. #define BOOST_MATH_NO_LEXICAL_CAST
  72. // Since Boost.Multiprecision is in active development some tests do not fully cooperate yet.
  73. #define BOOST_MATH_NO_MP_TESTS
  74. #if ((__cplusplus > 201400L) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201400L)))
  75. #define BOOST_MATH_CXX14_CONSTEXPR constexpr
  76. #else
  77. #define BOOST_MATH_CXX14_CONSTEXPR
  78. #define BOOST_MATH_NO_CXX14_CONSTEXPR
  79. #endif // BOOST_MATH_CXX14_CONSTEXPR
  80. #if ((__cplusplus > 201700L) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201700L)))
  81. #define BOOST_MATH_IF_CONSTEXPR if constexpr
  82. // Clang on mac provides the execution header with none of the functionality. TODO: Check back on this
  83. // https://en.cppreference.com/w/cpp/compiler_support "Standardization of Parallelism TS"
  84. # if !__has_include(<execution>) || (defined(__APPLE__) && defined(__clang__))
  85. # define BOOST_MATH_NO_CXX17_HDR_EXECUTION
  86. # endif
  87. #else
  88. # define BOOST_MATH_IF_CONSTEXPR if
  89. # define BOOST_MATH_NO_CXX17_IF_CONSTEXPR
  90. # define BOOST_MATH_NO_CXX17_HDR_EXECUTION
  91. #endif
  92. #if (defined(__cpp_lib_gcd_lcm) && (__cpp_lib_gcd_lcm >= 201606L))
  93. #define BOOST_MATH_HAS_CXX17_NUMERIC
  94. #endif
  95. #define BOOST_MATH_JOIN(X, Y) BOOST_MATH_DO_JOIN(X, Y)
  96. #define BOOST_MATH_DO_JOIN(X, Y) BOOST_MATH_DO_JOIN2(X,Y)
  97. #define BOOST_MATH_DO_JOIN2(X, Y) X##Y
  98. #define BOOST_MATH_STRINGIZE(X) BOOST_MATH_DO_STRINGIZE(X)
  99. #define BOOST_MATH_DO_STRINGIZE(X) #X
  100. #ifdef BOOST_MATH_DISABLE_THREADS // No threads, do nothing
  101. // Detect thread support via STL implementation
  102. #elif defined(__has_include)
  103. # if !__has_include(<thread>) || !__has_include(<mutex>) || !__has_include(<future>) || !__has_include(<atomic>)
  104. # define BOOST_MATH_DISABLE_THREADS
  105. # else
  106. # define BOOST_MATH_HAS_THREADS
  107. # endif
  108. #else
  109. # define BOOST_MATH_HAS_THREADS // The default assumption is that the machine has threads
  110. #endif // Thread Support
  111. #ifdef BOOST_MATH_DISABLE_THREADS
  112. # define BOOST_MATH_NO_CXX11_THREAD_LOCAL
  113. #endif // BOOST_MATH_DISABLE_THREADS
  114. #ifdef __GNUC__
  115. # if !defined(__EXCEPTIONS) && !defined(BOOST_MATH_NO_EXCEPTIONS)
  116. # define BOOST_MATH_NO_EXCEPTIONS
  117. # endif
  118. //
  119. // Make sure we have some std lib headers included so we can detect __GXX_RTTI:
  120. //
  121. # include <algorithm> // for min and max
  122. # include <limits>
  123. # ifndef __GXX_RTTI
  124. # ifndef BOOST_MATH_NO_TYPEID
  125. # define BOOST_MATH_NO_TYPEID
  126. # endif
  127. # ifndef BOOST_MATH_NO_RTTI
  128. # define BOOST_MATH_NO_RTTI
  129. # endif
  130. # endif
  131. #endif
  132. #if !defined(BOOST_MATH_NOINLINE)
  133. # if defined(_MSC_VER)
  134. # define BOOST_MATH_NOINLINE __declspec(noinline)
  135. # elif defined(__GNUC__) && __GNUC__ > 3
  136. // Clang also defines __GNUC__ (as 4)
  137. # if defined(__CUDACC__)
  138. // nvcc doesn't always parse __noinline__,
  139. // see: https://svn.boost.org/trac/boost/ticket/9392
  140. # define BOOST_MATH_NOINLINE __attribute__ ((noinline))
  141. # elif defined(__HIP__)
  142. // See https://github.com/boostorg/config/issues/392
  143. # define BOOST_MATH_NOINLINE __attribute__ ((noinline))
  144. # else
  145. # define BOOST_MATH_NOINLINE __attribute__ ((__noinline__))
  146. # endif
  147. # else
  148. # define BOOST_MATH_NOINLINE
  149. # endif
  150. #endif
  151. #if !defined(BOOST_MATH_FORCEINLINE)
  152. # if defined(_MSC_VER)
  153. # define BOOST_MATH_FORCEINLINE __forceinline
  154. # elif defined(__GNUC__) && __GNUC__ > 3
  155. // Clang also defines __GNUC__ (as 4)
  156. # define BOOST_MATH_FORCEINLINE inline __attribute__ ((__always_inline__))
  157. # else
  158. # define BOOST_MATH_FORCEINLINE inline
  159. # endif
  160. #endif
  161. #endif // BOOST_MATH_STANDALONE
  162. // Support compilers with P0024R2 implemented without linking TBB
  163. // https://en.cppreference.com/w/cpp/compiler_support
  164. #if !defined(BOOST_MATH_NO_CXX17_HDR_EXECUTION) && defined(BOOST_MATH_HAS_THREADS)
  165. # define BOOST_MATH_EXEC_COMPATIBLE
  166. #endif
  167. // C++23
  168. #if __cplusplus > 202002L || (defined(_MSVC_LANG) &&_MSVC_LANG > 202002L)
  169. # if defined(__GNUC__) && __GNUC__ >= 13
  170. // libstdc++3 only defines to/from_chars for std::float128_t when one of these defines are set
  171. // otherwise we're right out of luck...
  172. # if defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128) || defined(_GLIBCXX_HAVE_FLOAT128_MATH)
  173. # include <cstring> // std::strlen is used with from_chars
  174. # include <charconv>
  175. # include <stdfloat>
  176. # define BOOST_MATH_USE_CHARCONV_FOR_CONVERSION
  177. # endif
  178. # endif
  179. #endif
  180. #include <algorithm> // for min and max
  181. #include <limits>
  182. #include <cmath>
  183. #include <climits>
  184. #include <cfloat>
  185. #include <boost/math/tools/user.hpp>
  186. #if (defined(__NetBSD__)\
  187. || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \
  188. && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  189. //# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  190. #endif
  191. #if defined(__EMSCRIPTEN__) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  192. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  193. #endif
  194. #ifdef __IBMCPP__
  195. //
  196. // For reasons I don't understand, the tests with IMB's compiler all
  197. // pass at long double precision, but fail with real_concept, those tests
  198. // are disabled for now. (JM 2012).
  199. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  200. # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  201. #endif // BOOST_MATH_NO_REAL_CONCEPT_TESTS
  202. #endif
  203. #ifdef sun
  204. // Any use of __float128 in program startup code causes a segfault (tested JM 2015, Solaris 11).
  205. # define BOOST_MATH_DISABLE_FLOAT128
  206. #endif
  207. #ifdef __HAIKU__
  208. //
  209. // Not sure what's up with the math detection on Haiku, but linking fails with
  210. // float128 code enabled, and we don't have an implementation of __expl, so
  211. // disabling long double functions for now as well.
  212. # define BOOST_MATH_DISABLE_FLOAT128
  213. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  214. #endif
  215. #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  216. //
  217. // Darwin's rather strange "double double" is rather hard to
  218. // support, it should be possible given enough effort though...
  219. //
  220. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  221. #endif
  222. #if !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) && (LDBL_MANT_DIG == 106) && (LDBL_MIN_EXP > DBL_MIN_EXP)
  223. //
  224. // Generic catch all case for gcc's "double-double" long double type.
  225. // We do not support this as it's not even remotely IEEE conforming:
  226. //
  227. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  228. #endif
  229. #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  230. //
  231. // Intel compiler prior to version 10 has sporadic problems
  232. // calling the long double overloads of the std lib math functions:
  233. // calling ::powl is OK, but std::pow(long double, long double)
  234. // may segfault depending upon the value of the arguments passed
  235. // and the specific Linux distribution.
  236. //
  237. // We'll be conservative and disable long double support for this compiler.
  238. //
  239. // Comment out this #define and try building the tests to determine whether
  240. // your Intel compiler version has this issue or not.
  241. //
  242. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  243. #endif
  244. #if defined(unix) && defined(__INTEL_COMPILER)
  245. //
  246. // Intel compiler has sporadic issues compiling std::fpclassify depending on
  247. // the exact OS version used. Use our own code for this as we know it works
  248. // well on Intel processors:
  249. //
  250. #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
  251. #endif
  252. #if defined(_MSC_VER) && !defined(_WIN32_WCE)
  253. // Better safe than sorry, our tests don't support hardware exceptions:
  254. # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
  255. #endif
  256. #ifdef __IBMCPP__
  257. # define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
  258. #endif
  259. #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
  260. # define BOOST_MATH_USE_C99
  261. #endif
  262. #if (defined(__hpux) && !defined(__hppa))
  263. # define BOOST_MATH_USE_C99
  264. #endif
  265. #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
  266. # define BOOST_MATH_USE_C99
  267. #endif
  268. #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
  269. # define BOOST_MATH_USE_C99
  270. #endif
  271. #if defined(__CYGWIN__) || defined(__HP_aCC) || defined(__INTEL_COMPILER) \
  272. || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
  273. || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\
  274. || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  275. # define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
  276. #endif
  277. #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x590)
  278. namespace boost { namespace math { namespace tools { namespace detail {
  279. template <typename T>
  280. struct type {};
  281. template <typename T, T n>
  282. struct non_type {};
  283. }}}} // Namespace boost, math tools, detail
  284. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::math::tools::detail::type<t>* = 0
  285. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::math::tools::detail::type<t>*
  286. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::math::tools::detail::non_type<t, v>* = 0
  287. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::math::tools::detail::non_type<t, v>*
  288. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
  289. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  290. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
  291. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  292. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
  293. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  294. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
  295. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  296. #else
  297. // no workaround needed: expand to nothing
  298. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  299. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  300. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  301. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  302. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
  303. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  304. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  305. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  306. #endif // __SUNPRO_CC
  307. #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)
  308. // Sun's compiler emits a hard error if a constant underflows,
  309. // as does aCC on PA-RISC, while gcc issues a large number of warnings:
  310. # define BOOST_MATH_SMALL_CONSTANT(x) 0.0
  311. #else
  312. # define BOOST_MATH_SMALL_CONSTANT(x) x
  313. #endif
  314. //
  315. // Tune performance options for specific compilers,
  316. // but check at each step that nothing has been previously defined by the user first
  317. //
  318. #ifdef _MSC_VER
  319. # ifndef BOOST_MATH_POLY_METHOD
  320. # define BOOST_MATH_POLY_METHOD 2
  321. # endif
  322. #if _MSC_VER <= 1900
  323. # ifndef BOOST_MATH_POLY_METHOD
  324. # define BOOST_MATH_RATIONAL_METHOD 1
  325. # endif
  326. #else
  327. # ifndef BOOST_MATH_RATIONAL_METHOD
  328. # define BOOST_MATH_RATIONAL_METHOD 2
  329. # endif
  330. #endif
  331. #if _MSC_VER > 1900
  332. # ifndef BOOST_MATH_INT_TABLE_TYPE
  333. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  334. # endif
  335. # ifndef BOOST_MATH_INT_VALUE_SUFFIX
  336. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  337. # endif
  338. #endif
  339. #elif defined(__INTEL_COMPILER)
  340. # ifndef BOOST_MATH_POLY_METHOD
  341. # define BOOST_MATH_POLY_METHOD 2
  342. # endif
  343. # ifndef BOOST_MATH_RATIONAL_METHOD
  344. # define BOOST_MATH_RATIONAL_METHOD 1
  345. # endif
  346. #elif defined(__GNUC__)
  347. # ifndef BOOST_MATH_POLY_METHOD
  348. # define BOOST_MATH_POLY_METHOD 3
  349. # endif
  350. # ifndef BOOST_MATH_RATIONAL_METHOD
  351. # define BOOST_MATH_RATIONAL_METHOD 3
  352. # endif
  353. #elif defined(__clang__)
  354. #if __clang__ > 6
  355. # ifndef BOOST_MATH_POLY_METHOD
  356. # define BOOST_MATH_POLY_METHOD 3
  357. # endif
  358. # ifndef BOOST_MATH_RATIONAL_METHOD
  359. # define BOOST_MATH_RATIONAL_METHOD 3
  360. # endif
  361. # ifndef BOOST_MATH_INT_TABLE_TYPE
  362. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  363. # endif
  364. # ifndef BOOST_MATH_INT_VALUE_SUFFIX
  365. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  366. # endif
  367. #endif
  368. #endif
  369. //
  370. // noexcept support:
  371. //
  372. #include <type_traits>
  373. #define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value)
  374. #define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value)
  375. //
  376. // The maximum order of polynomial that will be evaluated
  377. // via an unrolled specialisation:
  378. //
  379. #ifndef BOOST_MATH_MAX_POLY_ORDER
  380. # define BOOST_MATH_MAX_POLY_ORDER 20
  381. #endif
  382. //
  383. // Set the method used to evaluate polynomials and rationals:
  384. //
  385. #ifndef BOOST_MATH_POLY_METHOD
  386. # define BOOST_MATH_POLY_METHOD 2
  387. #endif
  388. #ifndef BOOST_MATH_RATIONAL_METHOD
  389. # define BOOST_MATH_RATIONAL_METHOD 1
  390. #endif
  391. //
  392. // decide whether to store constants as integers or reals:
  393. //
  394. #ifndef BOOST_MATH_INT_TABLE_TYPE
  395. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
  396. #endif
  397. #ifndef BOOST_MATH_INT_VALUE_SUFFIX
  398. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
  399. #endif
  400. //
  401. // And then the actual configuration:
  402. //
  403. #if defined(BOOST_MATH_STANDALONE) && defined(_GLIBCXX_USE_FLOAT128) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && !defined(__STRICT_ANSI__) \
  404. && !defined(BOOST_MATH_DISABLE_FLOAT128) && !defined(BOOST_MATH_USE_FLOAT128)
  405. # define BOOST_MATH_USE_FLOAT128
  406. #elif defined(BOOST_HAS_FLOAT128) && !defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_MATH_DISABLE_FLOAT128)
  407. # define BOOST_MATH_USE_FLOAT128
  408. #endif
  409. #ifdef BOOST_MATH_USE_FLOAT128
  410. //
  411. // Only enable this when the compiler really is GCC as clang and probably
  412. // intel too don't support __float128 yet :-(
  413. //
  414. # if defined(__INTEL_COMPILER) && defined(__GNUC__)
  415. # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
  416. # define BOOST_MATH_FLOAT128_TYPE __float128
  417. # endif
  418. # elif defined(__GNUC__)
  419. # define BOOST_MATH_FLOAT128_TYPE __float128
  420. # endif
  421. # ifndef BOOST_MATH_FLOAT128_TYPE
  422. # define BOOST_MATH_FLOAT128_TYPE _Quad
  423. # endif
  424. #endif
  425. //
  426. // Check for WinCE with no iostream support:
  427. //
  428. #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
  429. # define BOOST_MATH_NO_LEXICAL_CAST
  430. #endif
  431. //
  432. // Helper macro for controlling the FP behaviour:
  433. //
  434. #ifndef BOOST_MATH_CONTROL_FP
  435. # define BOOST_MATH_CONTROL_FP
  436. #endif
  437. //
  438. // Helper macro for using statements:
  439. //
  440. #define BOOST_MATH_STD_USING_CORE \
  441. using std::abs;\
  442. using std::acos;\
  443. using std::cos;\
  444. using std::fmod;\
  445. using std::modf;\
  446. using std::tan;\
  447. using std::asin;\
  448. using std::cosh;\
  449. using std::frexp;\
  450. using std::pow;\
  451. using std::tanh;\
  452. using std::atan;\
  453. using std::exp;\
  454. using std::ldexp;\
  455. using std::sin;\
  456. using std::atan2;\
  457. using std::fabs;\
  458. using std::log;\
  459. using std::sinh;\
  460. using std::ceil;\
  461. using std::floor;\
  462. using std::log10;\
  463. using std::sqrt;\
  464. using std::log2;\
  465. using std::ilogb;
  466. #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
  467. namespace boost{ namespace math{
  468. namespace tools
  469. {
  470. template <class T>
  471. inline T max BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T)
  472. {
  473. return (std::max)((std::max)(a, b), c);
  474. }
  475. template <class T>
  476. inline T max BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T)
  477. {
  478. return (std::max)((std::max)(a, b), (std::max)(c, d));
  479. }
  480. } // namespace tools
  481. template <class T>
  482. void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T)
  483. {
  484. }
  485. namespace detail{
  486. template <class T>
  487. struct is_integer_for_rounding
  488. {
  489. static constexpr bool value = std::is_integral<T>::value || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer);
  490. };
  491. }
  492. }} // namespace boost namespace math
  493. #ifdef __GLIBC_PREREQ
  494. # if __GLIBC_PREREQ(2,14)
  495. # define BOOST_MATH_HAVE_FIXED_GLIBC
  496. # endif
  497. #endif
  498. #if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__))
  499. //
  500. // This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445
  501. // Basically powl and expl can return garbage when the result is small and certain exception flags are set
  502. // on entrance to these functions. This appears to have been fixed in Glibc 2.14 (May 2011).
  503. // Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4
  504. //
  505. #include <cfenv>
  506. # ifdef FE_ALL_EXCEPT
  507. namespace boost{ namespace math{
  508. namespace detail
  509. {
  510. struct fpu_guard
  511. {
  512. fpu_guard()
  513. {
  514. fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
  515. feclearexcept(FE_ALL_EXCEPT);
  516. }
  517. ~fpu_guard()
  518. {
  519. fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
  520. }
  521. private:
  522. fexcept_t m_flags;
  523. };
  524. } // namespace detail
  525. }} // namespaces
  526. # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
  527. # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
  528. # else
  529. # define BOOST_FPU_EXCEPTION_GUARD
  530. # define BOOST_MATH_INSTRUMENT_FPU
  531. # endif
  532. #else // All other platforms.
  533. # define BOOST_FPU_EXCEPTION_GUARD
  534. # define BOOST_MATH_INSTRUMENT_FPU
  535. #endif
  536. #ifdef BOOST_MATH_INSTRUMENT
  537. # include <iostream>
  538. # include <iomanip>
  539. # include <typeinfo>
  540. # define BOOST_MATH_INSTRUMENT_CODE(x) \
  541. std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
  542. # define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(#name << " = " << name)
  543. #else
  544. # define BOOST_MATH_INSTRUMENT_CODE(x)
  545. # define BOOST_MATH_INSTRUMENT_VARIABLE(name)
  546. #endif
  547. //
  548. // Thread local storage:
  549. //
  550. #ifndef BOOST_MATH_DISABLE_THREADS
  551. # define BOOST_MATH_THREAD_LOCAL thread_local
  552. #else
  553. # define BOOST_MATH_THREAD_LOCAL
  554. #endif
  555. //
  556. // Some mingw flavours have issues with thread_local and types with non-trivial destructors
  557. // See https://sourceforge.net/p/mingw-w64/bugs/527/
  558. //
  559. // When running windows-2022 or 2025 we see this issue again with GCC 12 and 14
  560. //
  561. #if (defined(__MINGW32__) && ((__GNUC__ < 9) || (__GNUC__ >= 12)) && !defined(__clang__))
  562. # define BOOST_MATH_NO_THREAD_LOCAL_WITH_NON_TRIVIAL_TYPES
  563. #endif
  564. //
  565. // Can we have constexpr tables?
  566. //
  567. #if (!defined(BOOST_MATH_NO_CXX14_CONSTEXPR)) || (defined(_MSC_VER) && _MSC_VER >= 1910)
  568. #define BOOST_MATH_HAVE_CONSTEXPR_TABLES
  569. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr
  570. #else
  571. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION
  572. #endif
  573. //
  574. // CUDA support:
  575. //
  576. #ifdef __CUDACC__
  577. // We have to get our include order correct otherwise you get compilation failures
  578. #include <cuda.h>
  579. #include <cuda_runtime.h>
  580. #include <cuda/std/type_traits>
  581. #include <cuda/std/utility>
  582. #include <cuda/std/cstdint>
  583. #include <cuda/std/array>
  584. #include <cuda/std/tuple>
  585. #include <cuda/std/complex>
  586. # define BOOST_MATH_CUDA_ENABLED __host__ __device__
  587. # define BOOST_MATH_HAS_GPU_SUPPORT
  588. # ifndef BOOST_MATH_ENABLE_CUDA
  589. # define BOOST_MATH_ENABLE_CUDA
  590. # endif
  591. // Device code can not handle exceptions
  592. # ifndef BOOST_MATH_NO_EXCEPTIONS
  593. # define BOOST_MATH_NO_EXCEPTIONS
  594. # endif
  595. // We want to use force inline from CUDA instead of the host compiler
  596. # undef BOOST_MATH_FORCEINLINE
  597. # define BOOST_MATH_FORCEINLINE __forceinline__
  598. #elif defined(BOOST_MATH_ENABLE_SYCL)
  599. # define BOOST_MATH_SYCL_ENABLED SYCL_EXTERNAL
  600. # define BOOST_MATH_HAS_GPU_SUPPORT
  601. # ifndef BOOST_MATH_NO_EXCEPTIONS
  602. # define BOOST_MATH_NO_EXCEPTIONS
  603. # endif
  604. // spir64 does not support long double
  605. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  606. # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  607. # undef BOOST_MATH_FORCEINLINE
  608. # define BOOST_MATH_FORCEINLINE inline
  609. #endif
  610. #ifndef BOOST_MATH_CUDA_ENABLED
  611. # define BOOST_MATH_CUDA_ENABLED
  612. #endif
  613. #ifndef BOOST_MATH_SYCL_ENABLED
  614. # define BOOST_MATH_SYCL_ENABLED
  615. #endif
  616. // Not all functions that allow CUDA allow SYCL (e.g. Recursion is disallowed by SYCL)
  617. # define BOOST_MATH_GPU_ENABLED BOOST_MATH_CUDA_ENABLED BOOST_MATH_SYCL_ENABLED
  618. // Additional functions that need replaced/marked up
  619. #ifdef BOOST_MATH_HAS_GPU_SUPPORT
  620. template <class T>
  621. BOOST_MATH_GPU_ENABLED constexpr void gpu_safe_swap(T& a, T& b) { T t(a); a = b; b = t; }
  622. template <class T>
  623. BOOST_MATH_GPU_ENABLED constexpr T gpu_safe_min(const T& a, const T& b) { return a < b ? a : b; }
  624. template <class T>
  625. BOOST_MATH_GPU_ENABLED constexpr T gpu_safe_max(const T& a, const T& b) { return a > b ? a : b; }
  626. #define BOOST_MATH_GPU_SAFE_SWAP(a, b) gpu_safe_swap(a, b)
  627. #define BOOST_MATH_GPU_SAFE_MIN(a, b) gpu_safe_min(a, b)
  628. #define BOOST_MATH_GPU_SAFE_MAX(a, b) gpu_safe_max(a, b)
  629. #else
  630. #define BOOST_MATH_GPU_SAFE_SWAP(a, b) std::swap(a, b)
  631. #define BOOST_MATH_GPU_SAFE_MIN(a, b) (std::min)(a, b)
  632. #define BOOST_MATH_GPU_SAFE_MAX(a, b) (std::max)(a, b)
  633. #endif
  634. // Static variables are not allowed with CUDA or C++20 modules
  635. // See if we can inline them instead
  636. #if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L
  637. # define BOOST_MATH_INLINE_CONSTEXPR inline constexpr
  638. # define BOOST_MATH_STATIC static
  639. # ifndef BOOST_MATH_HAS_GPU_SUPPORT
  640. # define BOOST_MATH_STATIC_LOCAL_VARIABLE static
  641. # else
  642. # define BOOST_MATH_STATIC_LOCAL_VARIABLE
  643. # endif
  644. #else
  645. # ifndef BOOST_MATH_HAS_GPU_SUPPORT
  646. # define BOOST_MATH_INLINE_CONSTEXPR static constexpr
  647. # define BOOST_MATH_STATIC static
  648. # define BOOST_MATH_STATIC_LOCAL_VARIABLE
  649. # else
  650. # define BOOST_MATH_INLINE_CONSTEXPR constexpr
  651. # define BOOST_MATH_STATIC constexpr
  652. # define BOOST_MATH_STATIC_LOCAL_VARIABLE static
  653. # endif
  654. #endif
  655. #define BOOST_MATH_FP_NAN FP_NAN
  656. #define BOOST_MATH_FP_INFINITE FP_INFINITE
  657. #define BOOST_MATH_FP_ZERO FP_ZERO
  658. #define BOOST_MATH_FP_SUBNORMAL FP_SUBNORMAL
  659. #define BOOST_MATH_FP_NORMAL FP_NORMAL
  660. #else // Special section for CUDA NVRTC to ensure we consume no STL headers
  661. #ifndef BOOST_MATH_STANDALONE
  662. # define BOOST_MATH_STANDALONE
  663. #endif
  664. #define BOOST_MATH_HAS_NVRTC
  665. #define BOOST_MATH_ENABLE_CUDA
  666. #define BOOST_MATH_HAS_GPU_SUPPORT
  667. #define BOOST_MATH_GPU_ENABLED __host__ __device__
  668. #define BOOST_MATH_CUDA_ENABLED __host__ __device__
  669. #define BOOST_MATH_STATIC static
  670. #define BOOST_MATH_STATIC_LOCAL_VARIABLE
  671. #define BOOST_MATH_NOEXCEPT(T) noexcept(boost::math::is_floating_point_v<T>)
  672. #define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)
  673. #define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)
  674. #define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T)
  675. #define BOOST_MATH_BIG_CONSTANT(T, N, V) static_cast<T>(V)
  676. #define BOOST_MATH_FORCEINLINE __forceinline__
  677. #define BOOST_MATH_STD_USING
  678. #define BOOST_MATH_IF_CONSTEXPR if
  679. #define BOOST_MATH_IS_FLOAT(T) (boost::math::is_floating_point<T>::value)
  680. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr
  681. #define BOOST_MATH_NO_EXCEPTIONS
  682. #define BOOST_MATH_PREVENT_MACRO_SUBSTITUTION
  683. // This should be defined to nothing but since it is not specifically a math macro
  684. // we need to undef before proceeding
  685. #ifdef BOOST_FPU_EXCEPTION_GUARD
  686. # undef BOOST_FPU_EXCEPTION_GUARD
  687. #endif
  688. #define BOOST_FPU_EXCEPTION_GUARD
  689. template <class T>
  690. BOOST_MATH_GPU_ENABLED constexpr void gpu_safe_swap(T& a, T& b) { T t(a); a = b; b = t; }
  691. #define BOOST_MATH_GPU_SAFE_SWAP(a, b) gpu_safe_swap(a, b)
  692. #define BOOST_MATH_GPU_SAFE_MIN(a, b) (::min)(a, b)
  693. #define BOOST_MATH_GPU_SAFE_MAX(a, b) (::max)(a, b)
  694. #define BOOST_MATH_FP_NAN 0
  695. #define BOOST_MATH_FP_INFINITE 1
  696. #define BOOST_MATH_FP_ZERO 2
  697. #define BOOST_MATH_FP_SUBNORMAL 3
  698. #define BOOST_MATH_FP_NORMAL 4
  699. #define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
  700. #define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
  701. #if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L
  702. # define BOOST_MATH_INLINE_CONSTEXPR inline constexpr
  703. #else
  704. # define BOOST_MATH_INLINE_CONSTEXPR constexpr
  705. #endif
  706. #define BOOST_MATH_INSTRUMENT_VARIABLE(x)
  707. #define BOOST_MATH_INSTRUMENT_CODE(x)
  708. #endif // NVRTC
  709. #endif // BOOST_MATH_TOOLS_CONFIG_HPP