config.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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__) \
  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(__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(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  69. //
  70. // Intel compiler prior to version 10 has sporadic problems
  71. // calling the long double overloads of the std lib math functions:
  72. // calling ::powl is OK, but std::pow(long double, long double)
  73. // may segfault depending upon the value of the arguments passed
  74. // and the specific Linux distribution.
  75. //
  76. // We'll be conservative and disable long double support for this compiler.
  77. //
  78. // Comment out this #define and try building the tests to determine whether
  79. // your Intel compiler version has this issue or not.
  80. //
  81. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  82. #endif
  83. #if defined(unix) && defined(__INTEL_COMPILER)
  84. //
  85. // Intel compiler has sporadic issues compiling std::fpclassify depending on
  86. // the exact OS version used. Use our own code for this as we know it works
  87. // well on Intel processors:
  88. //
  89. #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
  90. #endif
  91. #if defined(BOOST_MSVC) && !defined(_WIN32_WCE)
  92. // Better safe than sorry, our tests don't support hardware exceptions:
  93. # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
  94. #endif
  95. #ifdef __IBMCPP__
  96. # define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
  97. #endif
  98. #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
  99. # define BOOST_MATH_USE_C99
  100. #endif
  101. #if (defined(__hpux) && !defined(__hppa))
  102. # define BOOST_MATH_USE_C99
  103. #endif
  104. #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
  105. # define BOOST_MATH_USE_C99
  106. #endif
  107. #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
  108. # define BOOST_MATH_USE_C99
  109. #endif
  110. #if defined(__CYGWIN__) || defined(__HP_aCC) || defined(BOOST_INTEL) \
  111. || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
  112. || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\
  113. || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  114. # define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
  115. #endif
  116. #if BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
  117. # include "boost/type.hpp"
  118. # include "boost/non_type.hpp"
  119. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::type<t>* = 0
  120. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type<t>*
  121. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type<t, v>* = 0
  122. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type<t, v>*
  123. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
  124. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  125. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
  126. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  127. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
  128. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  129. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
  130. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  131. #else
  132. // no workaround needed: expand to nothing
  133. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  134. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  135. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  136. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  137. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
  138. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  139. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  140. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  141. #endif // __SUNPRO_CC
  142. #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)
  143. // Sun's compiler emits a hard error if a constant underflows,
  144. // as does aCC on PA-RISC, while gcc issues a large number of warnings:
  145. # define BOOST_MATH_SMALL_CONSTANT(x) 0.0
  146. #else
  147. # define BOOST_MATH_SMALL_CONSTANT(x) x
  148. #endif
  149. #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
  150. //
  151. // Define if constants too large for a float cause "bad"
  152. // values to be stored in the data, rather than infinity
  153. // or a suitably large value.
  154. //
  155. # define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  156. #endif
  157. //
  158. // Tune performance options for specific compilers:
  159. //
  160. #ifdef BOOST_MSVC
  161. # define BOOST_MATH_POLY_METHOD 2
  162. #if BOOST_MSVC <= 1900
  163. # define BOOST_MATH_RATIONAL_METHOD 1
  164. #else
  165. # define BOOST_MATH_RATIONAL_METHOD 2
  166. #endif
  167. #if BOOST_MSVC > 1900
  168. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  169. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  170. #endif
  171. #elif defined(BOOST_INTEL)
  172. # define BOOST_MATH_POLY_METHOD 2
  173. # define BOOST_MATH_RATIONAL_METHOD 1
  174. #elif defined(__GNUC__)
  175. #if __GNUC__ < 4
  176. # define BOOST_MATH_POLY_METHOD 3
  177. # define BOOST_MATH_RATIONAL_METHOD 3
  178. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  179. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  180. #else
  181. # define BOOST_MATH_POLY_METHOD 3
  182. # define BOOST_MATH_RATIONAL_METHOD 3
  183. #endif
  184. #elif defined(__clang__)
  185. #if __clang__ > 6
  186. # define BOOST_MATH_POLY_METHOD 3
  187. # define BOOST_MATH_RATIONAL_METHOD 3
  188. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  189. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  190. #endif
  191. #endif
  192. #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
  193. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  194. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  195. #endif
  196. //
  197. // constexpr support, early GCC implementations can't cope so disable
  198. // constexpr for them:
  199. //
  200. #if !defined(__clang__) && defined(__GNUC__)
  201. #if (__GNUC__ * 100 + __GNUC_MINOR__) < 490
  202. # define BOOST_MATH_DISABLE_CONSTEXPR
  203. #endif
  204. #endif
  205. #ifdef BOOST_MATH_DISABLE_CONSTEXPR
  206. # define BOOST_MATH_CONSTEXPR
  207. #else
  208. # define BOOST_MATH_CONSTEXPR BOOST_CONSTEXPR
  209. #endif
  210. //
  211. // noexcept support:
  212. //
  213. #ifndef BOOST_NO_CXX11_NOEXCEPT
  214. #ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
  215. #include <type_traits>
  216. # define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value)
  217. # define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value)
  218. #else
  219. #include <boost/type_traits/is_floating_point.hpp>
  220. # define BOOST_MATH_NOEXCEPT(T) noexcept(boost::is_floating_point<T>::value)
  221. # define BOOST_MATH_IS_FLOAT(T) (boost::is_floating_point<T>::value)
  222. #endif
  223. #else
  224. # define BOOST_MATH_NOEXCEPT(T)
  225. # define BOOST_MATH_IS_FLOAT(T) false
  226. #endif
  227. //
  228. // The maximum order of polynomial that will be evaluated
  229. // via an unrolled specialisation:
  230. //
  231. #ifndef BOOST_MATH_MAX_POLY_ORDER
  232. # define BOOST_MATH_MAX_POLY_ORDER 20
  233. #endif
  234. //
  235. // Set the method used to evaluate polynomials and rationals:
  236. //
  237. #ifndef BOOST_MATH_POLY_METHOD
  238. # define BOOST_MATH_POLY_METHOD 2
  239. #endif
  240. #ifndef BOOST_MATH_RATIONAL_METHOD
  241. # define BOOST_MATH_RATIONAL_METHOD 1
  242. #endif
  243. //
  244. // decide whether to store constants as integers or reals:
  245. //
  246. #ifndef BOOST_MATH_INT_TABLE_TYPE
  247. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
  248. #endif
  249. #ifndef BOOST_MATH_INT_VALUE_SUFFIX
  250. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
  251. #endif
  252. //
  253. // And then the actual configuration:
  254. //
  255. #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__) \
  256. && !defined(BOOST_MATH_DISABLE_FLOAT128) || defined(BOOST_MATH_USE_FLOAT128)
  257. //
  258. // Only enable this when the compiler really is GCC as clang and probably
  259. // intel too don't support __float128 yet :-(
  260. //
  261. #ifndef BOOST_MATH_USE_FLOAT128
  262. # define BOOST_MATH_USE_FLOAT128
  263. #endif
  264. # if defined(BOOST_INTEL) && defined(BOOST_INTEL_CXX_VERSION) && (BOOST_INTEL_CXX_VERSION >= 1310) && defined(__GNUC__)
  265. # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
  266. # define BOOST_MATH_FLOAT128_TYPE __float128
  267. # endif
  268. # elif defined(__GNUC__)
  269. # define BOOST_MATH_FLOAT128_TYPE __float128
  270. # endif
  271. # ifndef BOOST_MATH_FLOAT128_TYPE
  272. # define BOOST_MATH_FLOAT128_TYPE _Quad
  273. # endif
  274. #endif
  275. //
  276. // Check for WinCE with no iostream support:
  277. //
  278. #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
  279. # define BOOST_MATH_NO_LEXICAL_CAST
  280. #endif
  281. //
  282. // Helper macro for controlling the FP behaviour:
  283. //
  284. #ifndef BOOST_MATH_CONTROL_FP
  285. # define BOOST_MATH_CONTROL_FP
  286. #endif
  287. //
  288. // Helper macro for using statements:
  289. //
  290. #define BOOST_MATH_STD_USING_CORE \
  291. using std::abs;\
  292. using std::acos;\
  293. using std::cos;\
  294. using std::fmod;\
  295. using std::modf;\
  296. using std::tan;\
  297. using std::asin;\
  298. using std::cosh;\
  299. using std::frexp;\
  300. using std::pow;\
  301. using std::tanh;\
  302. using std::atan;\
  303. using std::exp;\
  304. using std::ldexp;\
  305. using std::sin;\
  306. using std::atan2;\
  307. using std::fabs;\
  308. using std::log;\
  309. using std::sinh;\
  310. using std::ceil;\
  311. using std::floor;\
  312. using std::log10;\
  313. using std::sqrt;
  314. #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
  315. namespace boost{ namespace math{
  316. namespace tools
  317. {
  318. template <class T>
  319. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T)
  320. {
  321. return (std::max)((std::max)(a, b), c);
  322. }
  323. template <class T>
  324. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T)
  325. {
  326. return (std::max)((std::max)(a, b), (std::max)(c, d));
  327. }
  328. } // namespace tools
  329. template <class T>
  330. void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T)
  331. {
  332. }
  333. namespace detail{
  334. template <class T>
  335. struct is_integer_for_rounding
  336. {
  337. static const bool value = boost::is_integral<T>::value
  338. #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
  339. || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer)
  340. #endif
  341. ;
  342. };
  343. }
  344. }} // namespace boost namespace math
  345. #ifdef __GLIBC_PREREQ
  346. # if __GLIBC_PREREQ(2,14)
  347. # define BOOST_MATH_HAVE_FIXED_GLIBC
  348. # endif
  349. #endif
  350. #if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H)
  351. //
  352. // This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445
  353. // Basically powl and expl can return garbage when the result is small and certain exception flags are set
  354. // on entrance to these functions. This appears to have been fixed in Glibc 2.14 (May 2011).
  355. // Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4
  356. //
  357. #include <boost/detail/fenv.hpp>
  358. # ifdef FE_ALL_EXCEPT
  359. namespace boost{ namespace math{
  360. namespace detail
  361. {
  362. struct fpu_guard
  363. {
  364. fpu_guard()
  365. {
  366. fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
  367. feclearexcept(FE_ALL_EXCEPT);
  368. }
  369. ~fpu_guard()
  370. {
  371. fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
  372. }
  373. private:
  374. fexcept_t m_flags;
  375. };
  376. } // namespace detail
  377. }} // namespaces
  378. # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
  379. # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
  380. # else
  381. # define BOOST_FPU_EXCEPTION_GUARD
  382. # define BOOST_MATH_INSTRUMENT_FPU
  383. # endif
  384. #else // All other platforms.
  385. # define BOOST_FPU_EXCEPTION_GUARD
  386. # define BOOST_MATH_INSTRUMENT_FPU
  387. #endif
  388. #ifdef BOOST_MATH_INSTRUMENT
  389. # include <iostream>
  390. # include <iomanip>
  391. # include <typeinfo>
  392. # define BOOST_MATH_INSTRUMENT_CODE(x) \
  393. std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
  394. # define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
  395. #else
  396. # define BOOST_MATH_INSTRUMENT_CODE(x)
  397. # define BOOST_MATH_INSTRUMENT_VARIABLE(name)
  398. #endif
  399. //
  400. // Thread local storage:
  401. //
  402. #if !defined(BOOST_NO_CXX11_THREAD_LOCAL) && !defined(BOOST_INTEL)
  403. # define BOOST_MATH_THREAD_LOCAL thread_local
  404. #else
  405. # define BOOST_MATH_THREAD_LOCAL
  406. #endif
  407. //
  408. // Can we have constexpr tables?
  409. //
  410. #if (!defined(BOOST_NO_CXX11_HDR_ARRAY) && !defined(BOOST_NO_CXX14_CONSTEXPR)) || BOOST_WORKAROUND(BOOST_MSVC, >= 1910)
  411. #define BOOST_MATH_HAVE_CONSTEXPR_TABLES
  412. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr
  413. #else
  414. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION
  415. #endif
  416. #endif // BOOST_MATH_TOOLS_CONFIG_HPP