config.hpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. // Copyright (c) 2006-7 John Maddock
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_TOOLS_CONFIG_HPP
  6. #define BOOST_MATH_TOOLS_CONFIG_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #endif
  10. #include <boost/config.hpp>
  11. #include <boost/predef/architecture/x86.h>
  12. #include <boost/cstdint.hpp> // for boost::uintmax_t
  13. #include <boost/detail/workaround.hpp>
  14. #include <boost/type_traits/is_integral.hpp>
  15. #include <algorithm> // for min and max
  16. #include <boost/config/no_tr1/cmath.hpp>
  17. #include <climits>
  18. #include <cfloat>
  19. #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
  20. # include <math.h>
  21. #endif
  22. #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
  23. # include <limits>
  24. #endif
  25. #include <boost/math/tools/user.hpp>
  26. #if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__EMSCRIPTEN__)\
  27. || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \
  28. && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  29. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  30. #endif
  31. #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
  32. //
  33. // Borland post 5.8.2 uses Dinkumware's std C lib which
  34. // doesn't have true long double precision. Earlier
  35. // versions are problematic too:
  36. //
  37. # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  38. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  39. # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
  40. # include <float.h>
  41. #endif
  42. #ifdef __IBMCPP__
  43. //
  44. // For reasons I don't understand, the tests with IMB's compiler all
  45. // pass at long double precision, but fail with real_concept, those tests
  46. // are disabled for now. (JM 2012).
  47. # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  48. #endif
  49. #ifdef sun
  50. // Any use of __float128 in program startup code causes a segfault (tested JM 2015, Solaris 11).
  51. # define BOOST_MATH_DISABLE_FLOAT128
  52. #endif
  53. #ifdef __HAIKU__
  54. //
  55. // Not sure what's up with the math detection on Haiku, but linking fails with
  56. // float128 code enabled, and we don't have an implementation of __expl, so
  57. // disabling long double functions for now as well.
  58. # define BOOST_MATH_DISABLE_FLOAT128
  59. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  60. #endif
  61. #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  62. //
  63. // Darwin's rather strange "double double" is rather hard to
  64. // support, it should be possible given enough effort though...
  65. //
  66. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  67. #endif
  68. #if !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) && (LDBL_MANT_DIG == 106) && (LDBL_MIN_EXP > DBL_MIN_EXP)
  69. //
  70. // Generic catch all case for gcc's "double-double" long double type.
  71. // We do not support this as it's not even remotely IEEE conforming:
  72. //
  73. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  74. #endif
  75. #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  76. //
  77. // Intel compiler prior to version 10 has sporadic problems
  78. // calling the long double overloads of the std lib math functions:
  79. // calling ::powl is OK, but std::pow(long double, long double)
  80. // may segfault depending upon the value of the arguments passed
  81. // and the specific Linux distribution.
  82. //
  83. // We'll be conservative and disable long double support for this compiler.
  84. //
  85. // Comment out this #define and try building the tests to determine whether
  86. // your Intel compiler version has this issue or not.
  87. //
  88. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  89. #endif
  90. #if defined(unix) && defined(__INTEL_COMPILER)
  91. //
  92. // Intel compiler has sporadic issues compiling std::fpclassify depending on
  93. // the exact OS version used. Use our own code for this as we know it works
  94. // well on Intel processors:
  95. //
  96. #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
  97. #endif
  98. #if defined(BOOST_MSVC) && !defined(_WIN32_WCE)
  99. // Better safe than sorry, our tests don't support hardware exceptions:
  100. # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
  101. #endif
  102. #ifdef __IBMCPP__
  103. # define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
  104. #endif
  105. #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
  106. # define BOOST_MATH_USE_C99
  107. #endif
  108. #if (defined(__hpux) && !defined(__hppa))
  109. # define BOOST_MATH_USE_C99
  110. #endif
  111. #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
  112. # define BOOST_MATH_USE_C99
  113. #endif
  114. #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
  115. # define BOOST_MATH_USE_C99
  116. #endif
  117. #if defined(__CYGWIN__) || defined(__HP_aCC) || defined(BOOST_INTEL) \
  118. || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
  119. || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\
  120. || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  121. # define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
  122. #endif
  123. #if BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
  124. # include "boost/type.hpp"
  125. # include "boost/non_type.hpp"
  126. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::type<t>* = 0
  127. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type<t>*
  128. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type<t, v>* = 0
  129. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type<t, v>*
  130. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
  131. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  132. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
  133. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  134. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
  135. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  136. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
  137. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  138. #else
  139. // no workaround needed: expand to nothing
  140. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  141. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  142. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  143. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  144. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
  145. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  146. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  147. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  148. #endif // __SUNPRO_CC
  149. #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)
  150. // Sun's compiler emits a hard error if a constant underflows,
  151. // as does aCC on PA-RISC, while gcc issues a large number of warnings:
  152. # define BOOST_MATH_SMALL_CONSTANT(x) 0.0
  153. #else
  154. # define BOOST_MATH_SMALL_CONSTANT(x) x
  155. #endif
  156. #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
  157. //
  158. // Define if constants too large for a float cause "bad"
  159. // values to be stored in the data, rather than infinity
  160. // or a suitably large value.
  161. //
  162. # define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  163. #endif
  164. //
  165. // Tune performance options for specific compilers:
  166. //
  167. #ifdef BOOST_MSVC
  168. # define BOOST_MATH_POLY_METHOD 2
  169. #if BOOST_MSVC <= 1900
  170. # define BOOST_MATH_RATIONAL_METHOD 1
  171. #else
  172. # define BOOST_MATH_RATIONAL_METHOD 2
  173. #endif
  174. #if BOOST_MSVC > 1900
  175. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  176. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  177. #endif
  178. #elif defined(BOOST_INTEL)
  179. # define BOOST_MATH_POLY_METHOD 2
  180. # define BOOST_MATH_RATIONAL_METHOD 1
  181. #elif defined(__GNUC__)
  182. #if __GNUC__ < 4
  183. # define BOOST_MATH_POLY_METHOD 3
  184. # define BOOST_MATH_RATIONAL_METHOD 3
  185. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  186. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  187. #else
  188. # define BOOST_MATH_POLY_METHOD 3
  189. # define BOOST_MATH_RATIONAL_METHOD 3
  190. #endif
  191. #elif defined(__clang__)
  192. #if __clang__ > 6
  193. # define BOOST_MATH_POLY_METHOD 3
  194. # define BOOST_MATH_RATIONAL_METHOD 3
  195. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  196. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  197. #endif
  198. #endif
  199. #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
  200. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  201. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  202. #endif
  203. //
  204. // constexpr support, early GCC implementations can't cope so disable
  205. // constexpr for them:
  206. //
  207. #if !defined(__clang__) && defined(__GNUC__)
  208. #if (__GNUC__ * 100 + __GNUC_MINOR__) < 490
  209. # define BOOST_MATH_DISABLE_CONSTEXPR
  210. #endif
  211. #endif
  212. #ifdef BOOST_MATH_DISABLE_CONSTEXPR
  213. # define BOOST_MATH_CONSTEXPR
  214. #else
  215. # define BOOST_MATH_CONSTEXPR BOOST_CONSTEXPR
  216. #endif
  217. //
  218. // noexcept support:
  219. //
  220. #ifndef BOOST_NO_CXX11_NOEXCEPT
  221. #ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
  222. #include <type_traits>
  223. # define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value)
  224. # define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value)
  225. #else
  226. #include <boost/type_traits/is_floating_point.hpp>
  227. # define BOOST_MATH_NOEXCEPT(T) noexcept(boost::is_floating_point<T>::value)
  228. # define BOOST_MATH_IS_FLOAT(T) (boost::is_floating_point<T>::value)
  229. #endif
  230. #else
  231. # define BOOST_MATH_NOEXCEPT(T)
  232. # define BOOST_MATH_IS_FLOAT(T) false
  233. #endif
  234. //
  235. // The maximum order of polynomial that will be evaluated
  236. // via an unrolled specialisation:
  237. //
  238. #ifndef BOOST_MATH_MAX_POLY_ORDER
  239. # define BOOST_MATH_MAX_POLY_ORDER 20
  240. #endif
  241. //
  242. // Set the method used to evaluate polynomials and rationals:
  243. //
  244. #ifndef BOOST_MATH_POLY_METHOD
  245. # define BOOST_MATH_POLY_METHOD 2
  246. #endif
  247. #ifndef BOOST_MATH_RATIONAL_METHOD
  248. # define BOOST_MATH_RATIONAL_METHOD 1
  249. #endif
  250. //
  251. // decide whether to store constants as integers or reals:
  252. //
  253. #ifndef BOOST_MATH_INT_TABLE_TYPE
  254. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
  255. #endif
  256. #ifndef BOOST_MATH_INT_VALUE_SUFFIX
  257. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
  258. #endif
  259. //
  260. // And then the actual configuration:
  261. //
  262. #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__) \
  263. && !defined(BOOST_MATH_DISABLE_FLOAT128) || defined(BOOST_MATH_USE_FLOAT128)
  264. //
  265. // Only enable this when the compiler really is GCC as clang and probably
  266. // intel too don't support __float128 yet :-(
  267. //
  268. #ifndef BOOST_MATH_USE_FLOAT128
  269. # define BOOST_MATH_USE_FLOAT128
  270. #endif
  271. # if defined(BOOST_INTEL) && defined(BOOST_INTEL_CXX_VERSION) && (BOOST_INTEL_CXX_VERSION >= 1310) && defined(__GNUC__)
  272. # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
  273. # define BOOST_MATH_FLOAT128_TYPE __float128
  274. # endif
  275. # elif defined(__GNUC__)
  276. # define BOOST_MATH_FLOAT128_TYPE __float128
  277. # endif
  278. # ifndef BOOST_MATH_FLOAT128_TYPE
  279. # define BOOST_MATH_FLOAT128_TYPE _Quad
  280. # endif
  281. #endif
  282. //
  283. // Check for WinCE with no iostream support:
  284. //
  285. #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
  286. # define BOOST_MATH_NO_LEXICAL_CAST
  287. #endif
  288. //
  289. // Helper macro for controlling the FP behaviour:
  290. //
  291. #ifndef BOOST_MATH_CONTROL_FP
  292. # define BOOST_MATH_CONTROL_FP
  293. #endif
  294. //
  295. // Helper macro for using statements:
  296. //
  297. #define BOOST_MATH_STD_USING_CORE \
  298. using std::abs;\
  299. using std::acos;\
  300. using std::cos;\
  301. using std::fmod;\
  302. using std::modf;\
  303. using std::tan;\
  304. using std::asin;\
  305. using std::cosh;\
  306. using std::frexp;\
  307. using std::pow;\
  308. using std::tanh;\
  309. using std::atan;\
  310. using std::exp;\
  311. using std::ldexp;\
  312. using std::sin;\
  313. using std::atan2;\
  314. using std::fabs;\
  315. using std::log;\
  316. using std::sinh;\
  317. using std::ceil;\
  318. using std::floor;\
  319. using std::log10;\
  320. using std::sqrt;
  321. #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
  322. namespace boost{ namespace math{
  323. namespace tools
  324. {
  325. template <class T>
  326. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T)
  327. {
  328. return (std::max)((std::max)(a, b), c);
  329. }
  330. template <class T>
  331. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T)
  332. {
  333. return (std::max)((std::max)(a, b), (std::max)(c, d));
  334. }
  335. } // namespace tools
  336. template <class T>
  337. void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T)
  338. {
  339. }
  340. namespace detail{
  341. template <class T>
  342. struct is_integer_for_rounding
  343. {
  344. static const bool value = boost::is_integral<T>::value
  345. #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
  346. || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer)
  347. #endif
  348. ;
  349. };
  350. }
  351. }} // namespace boost namespace math
  352. #ifdef __GLIBC_PREREQ
  353. # if __GLIBC_PREREQ(2,14)
  354. # define BOOST_MATH_HAVE_FIXED_GLIBC
  355. # endif
  356. #endif
  357. #if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H)
  358. //
  359. // This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445
  360. // Basically powl and expl can return garbage when the result is small and certain exception flags are set
  361. // on entrance to these functions. This appears to have been fixed in Glibc 2.14 (May 2011).
  362. // Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4
  363. //
  364. #include <boost/detail/fenv.hpp>
  365. # ifdef FE_ALL_EXCEPT
  366. namespace boost{ namespace math{
  367. namespace detail
  368. {
  369. struct fpu_guard
  370. {
  371. fpu_guard()
  372. {
  373. fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
  374. feclearexcept(FE_ALL_EXCEPT);
  375. }
  376. ~fpu_guard()
  377. {
  378. fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
  379. }
  380. private:
  381. fexcept_t m_flags;
  382. };
  383. } // namespace detail
  384. }} // namespaces
  385. # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
  386. # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
  387. # else
  388. # define BOOST_FPU_EXCEPTION_GUARD
  389. # define BOOST_MATH_INSTRUMENT_FPU
  390. # endif
  391. #else // All other platforms.
  392. # define BOOST_FPU_EXCEPTION_GUARD
  393. # define BOOST_MATH_INSTRUMENT_FPU
  394. #endif
  395. #ifdef BOOST_MATH_INSTRUMENT
  396. # include <iostream>
  397. # include <iomanip>
  398. # include <typeinfo>
  399. # define BOOST_MATH_INSTRUMENT_CODE(x) \
  400. std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
  401. # define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
  402. #else
  403. # define BOOST_MATH_INSTRUMENT_CODE(x)
  404. # define BOOST_MATH_INSTRUMENT_VARIABLE(name)
  405. #endif
  406. //
  407. // Thread local storage:
  408. //
  409. #if !defined(BOOST_NO_CXX11_THREAD_LOCAL) && !defined(BOOST_INTEL)
  410. # define BOOST_MATH_THREAD_LOCAL thread_local
  411. #else
  412. # define BOOST_MATH_THREAD_LOCAL
  413. #endif
  414. //
  415. // Some mingw flavours have issues with thread_local and types with non-trivial destructors
  416. // See https://sourceforge.net/p/mingw-w64/bugs/527/
  417. //
  418. #if !defined(BOOST_NO_CXX11_THREAD_LOCAL) && (defined(__MINGW32__) || defined(__MINGW64__)) && !defined(_REENTRANT) && !defined(__clang__)
  419. # define BOOST_MATH_NO_THREAD_LOCAL_WITH_NON_TRIVIAL_TYPES
  420. #endif
  421. //
  422. // Can we have constexpr tables?
  423. //
  424. #if (!defined(BOOST_NO_CXX11_HDR_ARRAY) && !defined(BOOST_NO_CXX14_CONSTEXPR)) || BOOST_WORKAROUND(BOOST_MSVC, >= 1910)
  425. #define BOOST_MATH_HAVE_CONSTEXPR_TABLES
  426. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr
  427. #else
  428. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION
  429. #endif
  430. #endif // BOOST_MATH_TOOLS_CONFIG_HPP