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/cstdint.hpp> // for boost::uintmax_t
14 #include <boost/config.hpp>
15 #include <boost/detail/workaround.hpp>
16 #include <algorithm> // for min and max
17 #include <boost/config/no_tr1/cmath.hpp>
19 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
23 #include <boost/math/tools/user.hpp>
24 #include <boost/math/special_functions/detail/round_fwd.hpp>
26 #if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \
27 || defined(__hppa) || defined(__NO_LONG_DOUBLE_MATH)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
28 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
30 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
32 // Borland post 5.8.2 uses Dinkumware's std C lib which
33 // doesn't have true long double precision. Earlier
34 // versions are problematic too:
36 # define BOOST_MATH_NO_REAL_CONCEPT_TESTS
37 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
38 # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
41 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
43 // Darwin's rather strange "double double" is rather hard to
44 // support, it should be possible given enough effort though...
46 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
48 #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
50 // Intel compiler prior to version 10 has sporadic problems
51 // calling the long double overloads of the std lib math functions:
52 // calling ::powl is OK, but std::pow(long double, long double)
53 // may segfault depending upon the value of the arguments passed
54 // and the specific Linux distribution.
56 // We'll be conservative and disable long double support for this compiler.
58 // Comment out this #define and try building the tests to determine whether
59 // your Intel compiler version has this issue or not.
61 # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
63 #if defined(unix) && defined(__INTEL_COMPILER)
65 // Intel compiler has sporadic issues compiling std::fpclassify depending on
66 // the exact OS version used. Use our own code for this as we know it works
67 // well on Intel processors:
69 #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
72 #if defined(BOOST_MSVC) && !defined(_WIN32_WCE)
73 // Better safe than sorry, our tests don't support hardware exceptions:
74 # define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
78 # define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
81 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
82 # define BOOST_MATH_USE_C99
85 #if (defined(__hpux) && !defined(__hppa))
86 # define BOOST_MATH_USE_C99
89 #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
90 # define BOOST_MATH_USE_C99
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 # define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
99 #if defined(BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
101 # include "boost/type.hpp"
102 # include "boost/non_type.hpp"
104 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::type<t>* = 0
105 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type<t>*
106 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type<t, v>* = 0
107 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type<t, v>*
109 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
110 , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
111 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
112 , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
113 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
114 , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
115 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
116 , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
120 // no workaround needed: expand to nothing
122 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
123 # define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
124 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
125 # define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
127 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
128 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
129 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
130 # define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
133 #endif // defined BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS
135 #if defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)
136 // Sun's compiler emits a hard error if a constant underflows,
137 // as does aCC on PA-RISC, while gcc issues a large number of warnings:
138 # define BOOST_MATH_SMALL_CONSTANT(x) 0
140 # define BOOST_MATH_SMALL_CONSTANT(x) x
144 #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
146 // Define if constants too large for a float cause "bad"
147 // values to be stored in the data, rather than infinity
148 // or a suitably large value.
150 # define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
153 // Tune performance options for specific compilers:
156 # define BOOST_MATH_POLY_METHOD 2
157 #elif defined(BOOST_INTEL)
158 # define BOOST_MATH_POLY_METHOD 2
159 # define BOOST_MATH_RATIONAL_METHOD 2
160 #elif defined(__GNUC__)
161 # define BOOST_MATH_POLY_METHOD 3
162 # define BOOST_MATH_RATIONAL_METHOD 3
163 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
164 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
167 #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
168 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
169 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
173 // The maximum order of polynomial that will be evaluated
174 // via an unrolled specialisation:
176 #ifndef BOOST_MATH_MAX_POLY_ORDER
177 # define BOOST_MATH_MAX_POLY_ORDER 17
180 // Set the method used to evaluate polynomials and rationals:
182 #ifndef BOOST_MATH_POLY_METHOD
183 # define BOOST_MATH_POLY_METHOD 1
185 #ifndef BOOST_MATH_RATIONAL_METHOD
186 # define BOOST_MATH_RATIONAL_METHOD 0
189 // decide whether to store constants as integers or reals:
191 #ifndef BOOST_MATH_INT_TABLE_TYPE
192 # define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
194 #ifndef BOOST_MATH_INT_VALUE_SUFFIX
195 # define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
199 // Helper macro for controlling the FP behaviour:
201 #ifndef BOOST_MATH_CONTROL_FP
202 # define BOOST_MATH_CONTROL_FP
205 // Helper macro for using statements:
207 #define BOOST_MATH_STD_USING \
231 using boost::math::round;\
232 using boost::math::iround;\
233 using boost::math::lround;\
234 using boost::math::trunc;\
235 using boost::math::itrunc;\
236 using boost::math::ltrunc;\
237 using boost::math::modf;
240 namespace boost{ namespace math{
245 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c)
247 return (std::max)((std::max)(a, b), c);
251 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d)
253 return (std::max)((std::max)(a, b), (std::max)(c, d));
256 }} // namespace boost namespace math
258 #if (defined(__linux__) && !defined(__UCLIBC__)) || defined(__QNX__) || defined(__IBMCPP__)
262 namespace boost{ namespace math{
269 fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
270 feclearexcept(FE_ALL_EXCEPT);
274 fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
280 } // namespace detail
283 # define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
284 # define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
285 #else // All other platforms.
286 # define BOOST_FPU_EXCEPTION_GUARD
287 # define BOOST_MATH_INSTRUMENT_FPU
290 #ifdef BOOST_MATH_INSTRUMENT
291 #define BOOST_MATH_INSTRUMENT_CODE(x) \
292 std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
293 #define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
295 #define BOOST_MATH_INSTRUMENT_CODE(x)
296 #define BOOST_MATH_INSTRUMENT_VARIABLE(name)
299 #endif // BOOST_MATH_TOOLS_CONFIG_HPP