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/cstdint.hpp> // for boost::uintmax_t
15 #include <boost/detail/workaround.hpp>
16 #include <algorithm> // for min and max
17 #include <boost/config/no_tr1/cmath.hpp>
20 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
24 #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
31 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
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:
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)
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
49 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
51 // Darwin's rather strange "double double" is rather hard to
52 // support, it should be possible given enough effort though...
54 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
56 #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
58 // Intel compiler prior to version 10 has sporadic problems
59 // calling the long double overloads of the std lib math functions:
60 // calling ::powl is OK, but std::pow(long double, long double)
61 // may segfault depending upon the value of the arguments passed
62 // and the specific Linux distribution.
64 // We'll be conservative and disable long double support for this compiler.
66 // Comment out this #define and try building the tests to determine whether
67 // your Intel compiler version has this issue or not.
69 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
71 #if defined(unix) && defined(__INTEL_COMPILER)
73 // Intel compiler has sporadic issues compiling std::fpclassify depending on
74 // the exact OS version used. Use our own code for this as we know it works
75 // well on Intel processors:
77 #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
80 #if defined(BOOST_MSVC) && !defined(_WIN32_WCE)
81 // Better safe than sorry, our tests don't support hardware exceptions:
82 # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
86 # define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
89 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
90 # define BOOST_MATH_USE_C99
93 #if (defined(__hpux) && !defined(__hppa))
94 # define BOOST_MATH_USE_C99
97 #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
98 # define BOOST_MATH_USE_C99
101 #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
102 # define BOOST_MATH_USE_C99
105 #if defined(__CYGWIN__) || defined(__HP_aCC) || defined(BOOST_INTEL) \
106 || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
107 || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\
108 || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
109 # define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
112 #if defined(BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
114 # include "boost/type.hpp"
115 # include "boost/non_type.hpp"
117 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::type<t>* = 0
118 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type<t>*
119 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type<t, v>* = 0
120 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type<t, v>*
122 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
123 , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
124 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
125 , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
126 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
127 , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
128 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
129 , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
133 // no workaround needed: expand to nothing
135 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
136 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
137 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
138 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
140 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
141 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
142 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
143 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
146 #endif // defined BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS
148 #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)
149 // Sun's compiler emits a hard error if a constant underflows,
150 // as does aCC on PA-RISC, while gcc issues a large number of warnings:
151 # define BOOST_MATH_SMALL_CONSTANT(x) 0
153 # define BOOST_MATH_SMALL_CONSTANT(x) x
157 #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
159 // Define if constants too large for a float cause "bad"
160 // values to be stored in the data, rather than infinity
161 // or a suitably large value.
163 # define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
166 // Tune performance options for specific compilers:
169 # define BOOST_MATH_POLY_METHOD 2
170 #elif defined(BOOST_INTEL)
171 # define BOOST_MATH_POLY_METHOD 2
172 # define BOOST_MATH_RATIONAL_METHOD 2
173 #elif defined(__GNUC__)
174 # define BOOST_MATH_POLY_METHOD 3
175 # define BOOST_MATH_RATIONAL_METHOD 3
176 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
177 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
180 #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
181 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
182 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
186 // The maximum order of polynomial that will be evaluated
187 // via an unrolled specialisation:
189 #ifndef BOOST_MATH_MAX_POLY_ORDER
190 # define BOOST_MATH_MAX_POLY_ORDER 17
193 // Set the method used to evaluate polynomials and rationals:
195 #ifndef BOOST_MATH_POLY_METHOD
196 # define BOOST_MATH_POLY_METHOD 1
198 #ifndef BOOST_MATH_RATIONAL_METHOD
199 # define BOOST_MATH_RATIONAL_METHOD 0
202 // decide whether to store constants as integers or reals:
204 #ifndef BOOST_MATH_INT_TABLE_TYPE
205 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
207 #ifndef BOOST_MATH_INT_VALUE_SUFFIX
208 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
211 // Test whether to support __float128:
213 #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__)
215 // Only enable this when the compiler really is GCC as clang and probably
216 // intel too don't support __float128 yet :-(
218 # define BOOST_MATH_USE_FLOAT128
221 // Check for WinCE with no iostream support:
223 #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
224 # define BOOST_MATH_NO_LEXICAL_CAST
228 // Helper macro for controlling the FP behaviour:
230 #ifndef BOOST_MATH_CONTROL_FP
231 # define BOOST_MATH_CONTROL_FP
234 // Helper macro for using statements:
236 #define BOOST_MATH_STD_USING_CORE \
261 #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
263 namespace boost{ namespace math{
268 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c)
270 return (std::max)((std::max)(a, b), c);
274 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d)
276 return (std::max)((std::max)(a, b), (std::max)(c, d));
282 void suppress_unused_variable_warning(const T&)
286 }} // namespace boost namespace math
288 #if ((defined(__linux__) && !defined(__UCLIBC__)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H)
290 #include <boost/detail/fenv.hpp>
292 # ifdef FE_ALL_EXCEPT
294 namespace boost{ namespace math{
301 fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
302 feclearexcept(FE_ALL_EXCEPT);
306 fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
312 } // namespace detail
315 # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
316 # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
320 # define BOOST_FPU_EXCEPTION_GUARD
321 # define BOOST_MATH_INSTRUMENT_FPU
325 #else // All other platforms.
326 # define BOOST_FPU_EXCEPTION_GUARD
327 # define BOOST_MATH_INSTRUMENT_FPU
330 #ifdef BOOST_MATH_INSTRUMENT
336 # define BOOST_MATH_INSTRUMENT_CODE(x) \
337 std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
338 # define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
342 # define BOOST_MATH_INSTRUMENT_CODE(x)
343 # define BOOST_MATH_INSTRUMENT_VARIABLE(name)
347 #endif // BOOST_MATH_TOOLS_CONFIG_HPP