config.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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/cstdint.hpp> // for boost::uintmax_t
  12. #include <boost/detail/workaround.hpp>
  13. #include <algorithm> // for min and max
  14. #include <boost/config/no_tr1/cmath.hpp>
  15. #include <climits>
  16. #include <cfloat>
  17. #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
  18. # include <math.h>
  19. #endif
  20. #include <boost/math/tools/user.hpp>
  21. #if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \
  22. || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \
  23. && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  24. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  25. #endif
  26. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  27. //
  28. // Borland post 5.8.2 uses Dinkumware's std C lib which
  29. // doesn't have true long double precision. Earlier
  30. // versions are problematic too:
  31. //
  32. # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  33. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  34. # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
  35. # include <float.h>
  36. #endif
  37. #ifdef __IBMCPP__
  38. //
  39. // For reasons I don't unserstand, the tests with IMB's compiler all
  40. // pass at long double precision, but fail with real_concept, those tests
  41. // are disabled for now. (JM 2012).
  42. # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
  43. #endif
  44. #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  45. //
  46. // Darwin's rather strange "double double" is rather hard to
  47. // support, it should be possible given enough effort though...
  48. //
  49. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  50. #endif
  51. #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  52. //
  53. // Intel compiler prior to version 10 has sporadic problems
  54. // calling the long double overloads of the std lib math functions:
  55. // calling ::powl is OK, but std::pow(long double, long double)
  56. // may segfault depending upon the value of the arguments passed
  57. // and the specific Linux distribution.
  58. //
  59. // We'll be conservative and disable long double support for this compiler.
  60. //
  61. // Comment out this #define and try building the tests to determine whether
  62. // your Intel compiler version has this issue or not.
  63. //
  64. # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  65. #endif
  66. #if defined(unix) && defined(__INTEL_COMPILER)
  67. //
  68. // Intel compiler has sporadic issues compiling std::fpclassify depending on
  69. // the exact OS version used. Use our own code for this as we know it works
  70. // well on Intel processors:
  71. //
  72. #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
  73. #endif
  74. #if defined(BOOST_MSVC) && !defined(_WIN32_WCE)
  75. // Better safe than sorry, our tests don't support hardware exceptions:
  76. # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
  77. #endif
  78. #ifdef __IBMCPP__
  79. # define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
  80. #endif
  81. #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
  82. # define BOOST_MATH_USE_C99
  83. #endif
  84. #if (defined(__hpux) && !defined(__hppa))
  85. # define BOOST_MATH_USE_C99
  86. #endif
  87. #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
  88. # define BOOST_MATH_USE_C99
  89. #endif
  90. #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
  91. # define BOOST_MATH_USE_C99
  92. #endif
  93. #if defined(__CYGWIN__) || defined(__HP_aCC) || defined(BOOST_INTEL) \
  94. || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
  95. || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\
  96. || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  97. # define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
  98. #endif
  99. #if defined(BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
  100. # include "boost/type.hpp"
  101. # include "boost/non_type.hpp"
  102. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::type<t>* = 0
  103. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type<t>*
  104. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type<t, v>* = 0
  105. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type<t, v>*
  106. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
  107. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  108. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
  109. , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  110. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
  111. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  112. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
  113. , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  114. #else
  115. // no workaround needed: expand to nothing
  116. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
  117. # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  118. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  119. # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  120. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
  121. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
  122. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
  123. # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
  124. #endif // defined BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS
  125. #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)
  126. // Sun's compiler emits a hard error if a constant underflows,
  127. // as does aCC on PA-RISC, while gcc issues a large number of warnings:
  128. # define BOOST_MATH_SMALL_CONSTANT(x) 0
  129. #else
  130. # define BOOST_MATH_SMALL_CONSTANT(x) x
  131. #endif
  132. #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
  133. //
  134. // Define if constants too large for a float cause "bad"
  135. // values to be stored in the data, rather than infinity
  136. // or a suitably large value.
  137. //
  138. # define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  139. #endif
  140. //
  141. // Tune performance options for specific compilers:
  142. //
  143. #ifdef BOOST_MSVC
  144. # define BOOST_MATH_POLY_METHOD 2
  145. #elif defined(BOOST_INTEL)
  146. # define BOOST_MATH_POLY_METHOD 2
  147. # define BOOST_MATH_RATIONAL_METHOD 2
  148. #elif defined(__GNUC__)
  149. # define BOOST_MATH_POLY_METHOD 3
  150. # define BOOST_MATH_RATIONAL_METHOD 3
  151. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  152. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  153. #endif
  154. #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
  155. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
  156. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
  157. #endif
  158. //
  159. // The maximum order of polynomial that will be evaluated
  160. // via an unrolled specialisation:
  161. //
  162. #ifndef BOOST_MATH_MAX_POLY_ORDER
  163. # define BOOST_MATH_MAX_POLY_ORDER 17
  164. #endif
  165. //
  166. // Set the method used to evaluate polynomials and rationals:
  167. //
  168. #ifndef BOOST_MATH_POLY_METHOD
  169. # define BOOST_MATH_POLY_METHOD 1
  170. #endif
  171. #ifndef BOOST_MATH_RATIONAL_METHOD
  172. # define BOOST_MATH_RATIONAL_METHOD 0
  173. #endif
  174. //
  175. // decide whether to store constants as integers or reals:
  176. //
  177. #ifndef BOOST_MATH_INT_TABLE_TYPE
  178. # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
  179. #endif
  180. #ifndef BOOST_MATH_INT_VALUE_SUFFIX
  181. # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
  182. #endif
  183. //
  184. // Test whether to support __float128:
  185. //
  186. #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__)
  187. //
  188. // Only enable this when the compiler really is GCC as clang and probably
  189. // intel too don't support __float128 yet :-(
  190. //
  191. # define BOOST_MATH_USE_FLOAT128
  192. #endif
  193. //
  194. // Check for WinCE with no iostream support:
  195. //
  196. #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
  197. # define BOOST_MATH_NO_LEXICAL_CAST
  198. #endif
  199. //
  200. // Helper macro for controlling the FP behaviour:
  201. //
  202. #ifndef BOOST_MATH_CONTROL_FP
  203. # define BOOST_MATH_CONTROL_FP
  204. #endif
  205. //
  206. // Helper macro for using statements:
  207. //
  208. #define BOOST_MATH_STD_USING_CORE \
  209. using std::abs;\
  210. using std::acos;\
  211. using std::cos;\
  212. using std::fmod;\
  213. using std::modf;\
  214. using std::tan;\
  215. using std::asin;\
  216. using std::cosh;\
  217. using std::frexp;\
  218. using std::pow;\
  219. using std::tanh;\
  220. using std::atan;\
  221. using std::exp;\
  222. using std::ldexp;\
  223. using std::sin;\
  224. using std::atan2;\
  225. using std::fabs;\
  226. using std::log;\
  227. using std::sinh;\
  228. using std::ceil;\
  229. using std::floor;\
  230. using std::log10;\
  231. using std::sqrt;
  232. #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
  233. namespace boost{ namespace math{
  234. namespace tools
  235. {
  236. template <class T>
  237. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c)
  238. {
  239. return (std::max)((std::max)(a, b), c);
  240. }
  241. template <class T>
  242. inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d)
  243. {
  244. return (std::max)((std::max)(a, b), (std::max)(c, d));
  245. }
  246. } // namespace tools
  247. template <class T>
  248. void suppress_unused_variable_warning(const T&)
  249. {
  250. }
  251. }} // namespace boost namespace math
  252. #if ((defined(__linux__) && !defined(__UCLIBC__)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H)
  253. #include <boost/detail/fenv.hpp>
  254. # ifdef FE_ALL_EXCEPT
  255. namespace boost{ namespace math{
  256. namespace detail
  257. {
  258. struct fpu_guard
  259. {
  260. fpu_guard()
  261. {
  262. fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
  263. feclearexcept(FE_ALL_EXCEPT);
  264. }
  265. ~fpu_guard()
  266. {
  267. fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
  268. }
  269. private:
  270. fexcept_t m_flags;
  271. };
  272. } // namespace detail
  273. }} // namespaces
  274. # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
  275. # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
  276. # else
  277. # define BOOST_FPU_EXCEPTION_GUARD
  278. # define BOOST_MATH_INSTRUMENT_FPU
  279. # endif
  280. #else // All other platforms.
  281. # define BOOST_FPU_EXCEPTION_GUARD
  282. # define BOOST_MATH_INSTRUMENT_FPU
  283. #endif
  284. #ifdef BOOST_MATH_INSTRUMENT
  285. # include <iostream>
  286. # include <iomanip>
  287. # include <typeinfo>
  288. # define BOOST_MATH_INSTRUMENT_CODE(x) \
  289. std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
  290. # define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
  291. #else
  292. # define BOOST_MATH_INSTRUMENT_CODE(x)
  293. # define BOOST_MATH_INSTRUMENT_VARIABLE(name)
  294. #endif
  295. #endif // BOOST_MATH_TOOLS_CONFIG_HPP