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)
6 #ifndef BOOST_MATH_TOOLS_CONFIG_HPP
7 #define BOOST_MATH_TOOLS_CONFIG_HPP
13 #include <boost/config.hpp>
14 #include <boost/predef/architecture/x86.h>
15 #include <boost/cstdint.hpp> // for boost::uintmax_t
16 #include <boost/detail/workaround.hpp>
17 #include <boost/type_traits/is_integral.hpp>
18 #include <algorithm> // for min and max
19 #include <boost/config/no_tr1/cmath.hpp>
22 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
25 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
29 #include <boost/math/tools/user.hpp>
31 #if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__EMSCRIPTEN__)\
32 || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \
33 && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
34 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
36 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
38 // Borland post 5.8.2 uses Dinkumware's std C lib which
39 // doesn't have true long double precision. Earlier
40 // versions are problematic too:
42 # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
43 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
44 # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
49 // For reasons I don't understand, the tests with IMB's compiler all
50 // pass at long double precision, but fail with real_concept, those tests
51 // are disabled for now. (JM 2012).
52 # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
55 // Any use of __float128 in program startup code causes a segfault (tested JM 2015, Solaris 11).
56 # define BOOST_MATH_DISABLE_FLOAT128
60 // Not sure what's up with the math detection on Haiku, but linking fails with
61 // float128 code enabled, and we don't have an implementation of __expl, so
62 // disabling long double functions for now as well.
63 # define BOOST_MATH_DISABLE_FLOAT128
64 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
66 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
68 // Darwin's rather strange "double double" is rather hard to
69 // support, it should be possible given enough effort though...
71 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
73 #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
75 // Intel compiler prior to version 10 has sporadic problems
76 // calling the long double overloads of the std lib math functions:
77 // calling ::powl is OK, but std::pow(long double, long double)
78 // may segfault depending upon the value of the arguments passed
79 // and the specific Linux distribution.
81 // We'll be conservative and disable long double support for this compiler.
83 // Comment out this #define and try building the tests to determine whether
84 // your Intel compiler version has this issue or not.
86 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
88 #if defined(unix) && defined(__INTEL_COMPILER)
90 // Intel compiler has sporadic issues compiling std::fpclassify depending on
91 // the exact OS version used. Use our own code for this as we know it works
92 // well on Intel processors:
94 #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
97 #if defined(BOOST_MSVC) && !defined(_WIN32_WCE)
98 // Better safe than sorry, our tests don't support hardware exceptions:
99 # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
103 # define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
106 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
107 # define BOOST_MATH_USE_C99
110 #if (defined(__hpux) && !defined(__hppa))
111 # define BOOST_MATH_USE_C99
114 #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
115 # define BOOST_MATH_USE_C99
118 #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
119 # define BOOST_MATH_USE_C99
122 #if defined(__CYGWIN__) || defined(__HP_aCC) || defined(BOOST_INTEL) \
123 || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
124 || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\
125 || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
126 # define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
129 #if BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
131 # include "boost/type.hpp"
132 # include "boost/non_type.hpp"
134 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::type<t>* = 0
135 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type<t>*
136 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type<t, v>* = 0
137 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type<t, v>*
139 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
140 , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
141 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
142 , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
143 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
144 , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
145 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
146 , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
150 // no workaround needed: expand to nothing
152 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
153 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
154 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
155 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
157 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
158 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
159 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
160 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
163 #endif // __SUNPRO_CC
165 #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)
166 // Sun's compiler emits a hard error if a constant underflows,
167 // as does aCC on PA-RISC, while gcc issues a large number of warnings:
168 # define BOOST_MATH_SMALL_CONSTANT(x) 0.0
170 # define BOOST_MATH_SMALL_CONSTANT(x) x
174 #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
176 // Define if constants too large for a float cause "bad"
177 // values to be stored in the data, rather than infinity
178 // or a suitably large value.
180 # define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
183 // Tune performance options for specific compilers:
186 # define BOOST_MATH_POLY_METHOD 2
187 #if BOOST_MSVC <= 1900
188 # define BOOST_MATH_RATIONAL_METHOD 1
190 # define BOOST_MATH_RATIONAL_METHOD 2
192 #if BOOST_MSVC > 1900
193 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
194 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
197 #elif defined(BOOST_INTEL)
198 # define BOOST_MATH_POLY_METHOD 2
199 # define BOOST_MATH_RATIONAL_METHOD 1
201 #elif defined(__GNUC__)
203 # define BOOST_MATH_POLY_METHOD 3
204 # define BOOST_MATH_RATIONAL_METHOD 3
205 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
206 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
208 # define BOOST_MATH_POLY_METHOD 3
209 # define BOOST_MATH_RATIONAL_METHOD 3
212 #elif defined(__clang__)
215 # define BOOST_MATH_POLY_METHOD 3
216 # define BOOST_MATH_RATIONAL_METHOD 3
217 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
218 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
223 #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
224 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
225 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
229 // constexpr support, early GCC implementations can't cope so disable
230 // constexpr for them:
232 #if !defined(__clang__) && defined(__GNUC__)
233 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 490
234 # define BOOST_MATH_DISABLE_CONSTEXPR
238 #ifdef BOOST_MATH_DISABLE_CONSTEXPR
239 # define BOOST_MATH_CONSTEXPR
241 # define BOOST_MATH_CONSTEXPR BOOST_CONSTEXPR
247 #ifndef BOOST_NO_CXX11_NOEXCEPT
248 #ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
249 #include <type_traits>
250 # define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value)
251 # define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value)
253 #include <boost/type_traits/is_floating_point.hpp>
254 # define BOOST_MATH_NOEXCEPT(T) noexcept(boost::is_floating_point<T>::value)
255 # define BOOST_MATH_IS_FLOAT(T) (boost::is_floating_point<T>::value)
258 # define BOOST_MATH_NOEXCEPT(T)
259 # define BOOST_MATH_IS_FLOAT(T) false
263 // The maximum order of polynomial that will be evaluated
264 // via an unrolled specialisation:
266 #ifndef BOOST_MATH_MAX_POLY_ORDER
267 # define BOOST_MATH_MAX_POLY_ORDER 20
270 // Set the method used to evaluate polynomials and rationals:
272 #ifndef BOOST_MATH_POLY_METHOD
273 # define BOOST_MATH_POLY_METHOD 2
275 #ifndef BOOST_MATH_RATIONAL_METHOD
276 # define BOOST_MATH_RATIONAL_METHOD 1
279 // decide whether to store constants as integers or reals:
281 #ifndef BOOST_MATH_INT_TABLE_TYPE
282 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
284 #ifndef BOOST_MATH_INT_VALUE_SUFFIX
285 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
288 // And then the actual configuration:
290 #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__) \
291 && !defined(BOOST_MATH_DISABLE_FLOAT128) || defined(BOOST_MATH_USE_FLOAT128)
293 // Only enable this when the compiler really is GCC as clang and probably
294 // intel too don't support __float128 yet :-(
296 #ifndef BOOST_MATH_USE_FLOAT128
297 # define BOOST_MATH_USE_FLOAT128
300 # if defined(BOOST_INTEL) && defined(BOOST_INTEL_CXX_VERSION) && (BOOST_INTEL_CXX_VERSION >= 1310) && defined(__GNUC__)
301 # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
302 # define BOOST_MATH_FLOAT128_TYPE __float128
304 # elif defined(__GNUC__)
305 # define BOOST_MATH_FLOAT128_TYPE __float128
308 # ifndef BOOST_MATH_FLOAT128_TYPE
309 # define BOOST_MATH_FLOAT128_TYPE _Quad
313 // Check for WinCE with no iostream support:
315 #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
316 # define BOOST_MATH_NO_LEXICAL_CAST
320 // Helper macro for controlling the FP behaviour:
322 #ifndef BOOST_MATH_CONTROL_FP
323 # define BOOST_MATH_CONTROL_FP
326 // Helper macro for using statements:
328 #define BOOST_MATH_STD_USING_CORE \
353 #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
355 namespace boost{ namespace math{
360 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T)
362 return (std::max)((std::max)(a, b), c);
366 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T)
368 return (std::max)((std::max)(a, b), (std::max)(c, d));
374 void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T)
381 struct is_integer_for_rounding
383 static const bool value = boost::is_integral<T>::value
384 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
385 || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer)
392 }} // namespace boost namespace math
394 #ifdef __GLIBC_PREREQ
395 # if __GLIBC_PREREQ(2,14)
396 # define BOOST_MATH_HAVE_FIXED_GLIBC
400 #if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H)
402 // This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445
403 // Basically powl and expl can return garbage when the result is small and certain exception flags are set
404 // on entrance to these functions. This appears to have been fixed in Glibc 2.14 (May 2011).
405 // Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4
408 #include <boost/detail/fenv.hpp>
410 # ifdef FE_ALL_EXCEPT
412 namespace boost{ namespace math{
419 fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
420 feclearexcept(FE_ALL_EXCEPT);
424 fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
430 } // namespace detail
433 # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
434 # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
438 # define BOOST_FPU_EXCEPTION_GUARD
439 # define BOOST_MATH_INSTRUMENT_FPU
443 #else // All other platforms.
444 # define BOOST_FPU_EXCEPTION_GUARD
445 # define BOOST_MATH_INSTRUMENT_FPU
448 #ifdef BOOST_MATH_INSTRUMENT
454 # define BOOST_MATH_INSTRUMENT_CODE(x) \
455 std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
456 # define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
460 # define BOOST_MATH_INSTRUMENT_CODE(x)
461 # define BOOST_MATH_INSTRUMENT_VARIABLE(name)
466 // Thread local storage:
468 #if !defined(BOOST_NO_CXX11_THREAD_LOCAL) && !defined(BOOST_INTEL)
469 # define BOOST_MATH_THREAD_LOCAL thread_local
471 # define BOOST_MATH_THREAD_LOCAL
475 // Can we have constexpr tables?
477 #if (!defined(BOOST_NO_CXX11_HDR_ARRAY) && !defined(BOOST_NO_CXX14_CONSTEXPR)) || BOOST_WORKAROUND(BOOST_MSVC, >= 1910)
478 #define BOOST_MATH_HAVE_CONSTEXPR_TABLES
479 #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr
481 #define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION
485 #endif // BOOST_MATH_TOOLS_CONFIG_HPP