config.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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 unserstand, 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. # define BOOST_MATH_RATIONAL_METHOD 1
  163. #elif defined(BOOST_INTEL)
  164. # define BOOST_MATH_POLY_METHOD 2
  165. # define BOOST_MATH_RATIONAL_METHOD 1
  166. #elif defined(__GNUC__)
  167. #if __GNUC__ < 4
  168. # define BOOST_MATH_POLY_METHOD 3
  169. # define BOOST_MATH_RATIONAL_METHOD 3
  170. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  171. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  172. #else
  173. # define BOOST_MATH_POLY_METHOD 3
  174. # define BOOST_MATH_RATIONAL_METHOD 1
  175. #endif
  176. #endif
  177. #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
  178. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  179. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  180. #endif
  181. //
  182. // constexpr support, early GCC implementations can't cope so disable
  183. // constexpr for them:
  184. //
  185. #if !defined(__clang__) && defined(__GNUC__)
  186. #if (__GNUC__ * 100 + __GNUC_MINOR__) < 490
  187. # define BOOST_MATH_DISABLE_CONSTEXPR
  188. #endif
  189. #endif
  190. #ifdef BOOST_MATH_DISABLE_CONSTEXPR
  191. # define BOOST_MATH_CONSTEXPR
  192. #else
  193. # define BOOST_MATH_CONSTEXPR BOOST_CONSTEXPR
  194. #endif
  195. //
  196. // noexcept support:
  197. //
  198. #ifndef BOOST_NO_CXX11_NOEXCEPT
  199. #ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
  200. #include <type_traits>
  201. # define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value)
  202. # define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value)
  203. #else
  204. #include <boost/type_traits/is_floating_point.hpp>
  205. # define BOOST_MATH_NOEXCEPT(T) noexcept(boost::is_floating_point<T>::value)
  206. # define BOOST_MATH_IS_FLOAT(T) (boost::is_floating_point<T>::value)
  207. #endif
  208. #else
  209. # define BOOST_MATH_NOEXCEPT(T)
  210. # define BOOST_MATH_IS_FLOAT(T) false
  211. #endif
  212. //
  213. // The maximum order of polynomial that will be evaluated
  214. // via an unrolled specialisation:
  215. //
  216. #ifndef BOOST_MATH_MAX_POLY_ORDER
  217. # define BOOST_MATH_MAX_POLY_ORDER 20
  218. #endif
  219. //
  220. // Set the method used to evaluate polynomials and rationals:
  221. //
  222. #ifndef BOOST_MATH_POLY_METHOD
  223. # define BOOST_MATH_POLY_METHOD 2
  224. #endif
  225. #ifndef BOOST_MATH_RATIONAL_METHOD
  226. # define BOOST_MATH_RATIONAL_METHOD 1
  227. #endif
  228. //
  229. // decide whether to store constants as integers or reals:
  230. //
  231. #ifndef BOOST_MATH_INT_TABLE_TYPE
  232. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
  233. #endif
  234. #ifndef BOOST_MATH_INT_VALUE_SUFFIX
  235. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
  236. #endif
  237. //
  238. // And then the actual configuration:
  239. //
  240. #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__) \
  241. && !defined(BOOST_MATH_DISABLE_FLOAT128) || defined(BOOST_MATH_USE_FLOAT128)
  242. //
  243. // Only enable this when the compiler really is GCC as clang and probably
  244. // intel too don't support __float128 yet :-(
  245. //
  246. #ifndef BOOST_MATH_USE_FLOAT128
  247. # define BOOST_MATH_USE_FLOAT128
  248. #endif
  249. # if defined(BOOST_INTEL) && defined(BOOST_INTEL_CXX_VERSION) && (BOOST_INTEL_CXX_VERSION >= 1310) && defined(__GNUC__)
  250. # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
  251. # define BOOST_MATH_FLOAT128_TYPE __float128
  252. # endif
  253. # elif defined(__GNUC__)
  254. # define BOOST_MATH_FLOAT128_TYPE __float128
  255. # endif
  256. # ifndef BOOST_MATH_FLOAT128_TYPE
  257. # define BOOST_MATH_FLOAT128_TYPE _Quad
  258. # endif
  259. #endif
  260. //
  261. // Check for WinCE with no iostream support:
  262. //
  263. #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
  264. # define BOOST_MATH_NO_LEXICAL_CAST
  265. #endif
  266. //
  267. // Helper macro for controlling the FP behaviour:
  268. //
  269. #ifndef BOOST_MATH_CONTROL_FP
  270. # define BOOST_MATH_CONTROL_FP
  271. #endif
  272. //
  273. // Helper macro for using statements:
  274. //
  275. #define BOOST_MATH_STD_USING_CORE \
  276. using std::abs;\
  277. using std::acos;\
  278. using std::cos;\
  279. using std::fmod;\
  280. using std::modf;\
  281. using std::tan;\
  282. using std::asin;\
  283. using std::cosh;\
  284. using std::frexp;\
  285. using std::pow;\
  286. using std::tanh;\
  287. using std::atan;\
  288. using std::exp;\
  289. using std::ldexp;\
  290. using std::sin;\
  291. using std::atan2;\
  292. using std::fabs;\
  293. using std::log;\
  294. using std::sinh;\
  295. using std::ceil;\
  296. using std::floor;\
  297. using std::log10;\
  298. using std::sqrt;
  299. #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
  300. namespace boost{ namespace math{
  301. namespace tools
  302. {
  303. template <class T>
  304. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T)
  305. {
  306. return (std::max)((std::max)(a, b), c);
  307. }
  308. template <class T>
  309. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T)
  310. {
  311. return (std::max)((std::max)(a, b), (std::max)(c, d));
  312. }
  313. } // namespace tools
  314. template <class T>
  315. void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T)
  316. {
  317. }
  318. namespace detail{
  319. template <class T>
  320. struct is_integer_for_rounding
  321. {
  322. static const bool value = boost::is_integral<T>::value
  323. #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
  324. || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer)
  325. #endif
  326. ;
  327. };
  328. }
  329. }} // namespace boost namespace math
  330. #ifdef __GLIBC_PREREQ
  331. # if __GLIBC_PREREQ(2,14)
  332. # define BOOST_MATH_HAVE_FIXED_GLIBC
  333. # endif
  334. #endif
  335. #if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H)
  336. //
  337. // This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445
  338. // Basically powl and expl can return garbage when the result is small and certain exception flags are set
  339. // on entrance to these functions. This appears to have been fixed in Glibc 2.14 (May 2011).
  340. // Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4
  341. //
  342. #include <boost/detail/fenv.hpp>
  343. # ifdef FE_ALL_EXCEPT
  344. namespace boost{ namespace math{
  345. namespace detail
  346. {
  347. struct fpu_guard
  348. {
  349. fpu_guard()
  350. {
  351. fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
  352. feclearexcept(FE_ALL_EXCEPT);
  353. }
  354. ~fpu_guard()
  355. {
  356. fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
  357. }
  358. private:
  359. fexcept_t m_flags;
  360. };
  361. } // namespace detail
  362. }} // namespaces
  363. # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
  364. # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
  365. # else
  366. # define BOOST_FPU_EXCEPTION_GUARD
  367. # define BOOST_MATH_INSTRUMENT_FPU
  368. # endif
  369. #else // All other platforms.
  370. # define BOOST_FPU_EXCEPTION_GUARD
  371. # define BOOST_MATH_INSTRUMENT_FPU
  372. #endif
  373. #ifdef BOOST_MATH_INSTRUMENT
  374. # include <iostream>
  375. # include <iomanip>
  376. # include <typeinfo>
  377. # define BOOST_MATH_INSTRUMENT_CODE(x) \
  378. std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
  379. # define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
  380. #else
  381. # define BOOST_MATH_INSTRUMENT_CODE(x)
  382. # define BOOST_MATH_INSTRUMENT_VARIABLE(name)
  383. #endif
  384. //
  385. // Thread local storage:
  386. //
  387. #if !defined(BOOST_NO_CXX11_THREAD_LOCAL) && !defined(BOOST_INTEL)
  388. # define BOOST_MATH_THREAD_LOCAL thread_local
  389. #else
  390. # define BOOST_MATH_THREAD_LOCAL
  391. #endif
  392. //
  393. // Can we have constexpr tables?
  394. //
  395. #if (!defined(BOOST_NO_CXX11_HDR_ARRAY) && !defined(BOOST_NO_CXX14_CONSTEXPR)) || BOOST_WORKAROUND(BOOST_MSVC, >= 1910)
  396. #define BOOST_MATH_HAVE_CONSTEXPR_TABLES
  397. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr
  398. #else
  399. #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION
  400. #endif
  401. #endif // BOOST_MATH_TOOLS_CONFIG_HPP