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 
6 #ifndef BOOST_MATH_TOOLS_CONFIG_HPP
7 #define BOOST_MATH_TOOLS_CONFIG_HPP
8 
9 #ifdef _MSC_VER
10 #pragma once
11 #endif
12 
13 #include <boost/config.hpp>
14 #include <boost/cstdint.hpp> // for boost::uintmax_t
15 #include <boost/detail/workaround.hpp>
16 #include <boost/type_traits/is_integral.hpp>
17 #include <algorithm>  // for min and max
18 #include <boost/config/no_tr1/cmath.hpp>
19 #include <climits>
20 #include <cfloat>
21 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
22 #  include <math.h>
23 #endif
24 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
25 #  include <limits>
26 #endif
27 
28 #include <boost/math/tools/user.hpp>
29 
30 #if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \
31    || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \
32    && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
33 #  define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
34 #endif
35 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
36 //
37 // Borland post 5.8.2 uses Dinkumware's std C lib which
38 // doesn't have true long double precision.  Earlier
39 // versions are problematic too:
40 //
41 #  define BOOST_MATH_NO_REAL_CONCEPT_TESTS
42 #  define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
43 #  define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
44 #  include <float.h>
45 #endif
46 #ifdef __IBMCPP__
47 //
48 // For reasons I don't unserstand, the tests with IMB's compiler all
49 // pass at long double precision, but fail with real_concept, those tests
50 // are disabled for now.  (JM 2012).
51 #  define BOOST_MATH_NO_REAL_CONCEPT_TESTS
52 #endif
53 #ifdef sun
54 // Any use of __float128 in program startup code causes a segfault  (tested JM 2015, Solaris 11).
55 #  define BOOST_MATH_DISABLE_FLOAT128
56 #endif
57 #ifdef __HAIKU__
58 //
59 // Not sure what's up with the math detection on Haiku, but linking fails with
60 // float128 code enabled, and we don't have an implementation of __expl, so
61 // disabling long double functions for now as well.
62 #  define BOOST_MATH_DISABLE_FLOAT128
63 #  define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
64 #endif
65 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
66 //
67 // Darwin's rather strange "double double" is rather hard to
68 // support, it should be possible given enough effort though...
69 //
70 #  define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
71 #endif
72 #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
73 //
74 // Intel compiler prior to version 10 has sporadic problems
75 // calling the long double overloads of the std lib math functions:
76 // calling ::powl is OK, but std::pow(long double, long double)
77 // may segfault depending upon the value of the arguments passed
78 // and the specific Linux distribution.
79 //
80 // We'll be conservative and disable long double support for this compiler.
81 //
82 // Comment out this #define and try building the tests to determine whether
83 // your Intel compiler version has this issue or not.
84 //
85 #  define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
86 #endif
87 #if defined(unix) && defined(__INTEL_COMPILER)
88 //
89 // Intel compiler has sporadic issues compiling std::fpclassify depending on
90 // the exact OS version used.  Use our own code for this as we know it works
91 // well on Intel processors:
92 //
93 #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
94 #endif
95 
96 #if defined(BOOST_MSVC) && !defined(_WIN32_WCE)
97    // Better safe than sorry, our tests don't support hardware exceptions:
98 #  define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
99 #endif
100 
101 #ifdef __IBMCPP__
102 #  define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
103 #endif
104 
105 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
106 #  define BOOST_MATH_USE_C99
107 #endif
108 
109 #if (defined(__hpux) && !defined(__hppa))
110 #  define BOOST_MATH_USE_C99
111 #endif
112 
113 #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
114 #  define BOOST_MATH_USE_C99
115 #endif
116 
117 #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
118 #  define BOOST_MATH_USE_C99
119 #endif
120 
121 #if defined(__CYGWIN__) || defined(__HP_aCC) || defined(BOOST_INTEL) \
122   || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
123   || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\
124   || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
125 #  define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
126 #endif
127 
128 #if BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
129 
130 #  include "boost/type.hpp"
131 #  include "boost/non_type.hpp"
132 
133 #  define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)         boost::type<t>* = 0
134 #  define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)    boost::type<t>*
135 #  define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)  boost::non_type<t, v>* = 0
136 #  define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)  boost::non_type<t, v>*
137 
138 #  define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)         \
139              , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
140 #  define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)    \
141              , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
142 #  define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)  \
143              , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
144 #  define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)  \
145              , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
146 
147 #else
148 
149 // no workaround needed: expand to nothing
150 
151 #  define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
152 #  define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
153 #  define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
154 #  define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
155 
156 #  define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
157 #  define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
158 #  define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
159 #  define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
160 
161 
162 #endif // __SUNPRO_CC
163 
164 #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)
165 // Sun's compiler emits a hard error if a constant underflows,
166 // as does aCC on PA-RISC, while gcc issues a large number of warnings:
167 #  define BOOST_MATH_SMALL_CONSTANT(x) 0.0
168 #else
169 #  define BOOST_MATH_SMALL_CONSTANT(x) x
170 #endif
171 
172 
173 #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
174 //
175 // Define if constants too large for a float cause "bad"
176 // values to be stored in the data, rather than infinity
177 // or a suitably large value.
178 //
179 #  define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
180 #endif
181 //
182 // Tune performance options for specific compilers:
183 //
184 #ifdef BOOST_MSVC
185 #  define BOOST_MATH_POLY_METHOD 2
186 #elif defined(BOOST_INTEL)
187 #  define BOOST_MATH_POLY_METHOD 2
188 #  define BOOST_MATH_RATIONAL_METHOD 2
189 #elif defined(__GNUC__)
190 #  define BOOST_MATH_POLY_METHOD 3
191 #  define BOOST_MATH_RATIONAL_METHOD 3
192 #  define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
193 #  define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
194 #endif
195 
196 #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
197 #  define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
198 #  define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
199 #endif
200 
201 //
202 // The maximum order of polynomial that will be evaluated
203 // via an unrolled specialisation:
204 //
205 #ifndef BOOST_MATH_MAX_POLY_ORDER
206 #  define BOOST_MATH_MAX_POLY_ORDER 17
207 #endif
208 //
209 // Set the method used to evaluate polynomials and rationals:
210 //
211 #ifndef BOOST_MATH_POLY_METHOD
212 #  define BOOST_MATH_POLY_METHOD 1
213 #endif
214 #ifndef BOOST_MATH_RATIONAL_METHOD
215 #  define BOOST_MATH_RATIONAL_METHOD 0
216 #endif
217 //
218 // decide whether to store constants as integers or reals:
219 //
220 #ifndef BOOST_MATH_INT_TABLE_TYPE
221 #  define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
222 #endif
223 #ifndef BOOST_MATH_INT_VALUE_SUFFIX
224 #  define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
225 #endif
226 //
227 // Test whether to support __float128:
228 //
229 #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__) \
230    && !defined(BOOST_MATH_DISABLE_FLOAT128) || defined(BOOST_MATH_USE_FLOAT128)
231 //
232 // Only enable this when the compiler really is GCC as clang and probably
233 // intel too don't support __float128 yet :-(
234 //
235 #ifndef BOOST_MATH_USE_FLOAT128
236 #  define BOOST_MATH_USE_FLOAT128
237 #endif
238 
239 #  if defined(BOOST_INTEL) && defined(BOOST_INTEL_CXX_VERSION) && (BOOST_INTEL_CXX_VERSION >= 1310) && defined(__GNUC__)
240 #    if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
241 #      define BOOST_MATH_FLOAT128_TYPE __float128
242 #    endif
243 #  elif defined(__GNUC__)
244 #      define BOOST_MATH_FLOAT128_TYPE __float128
245 #  endif
246 
247 #  ifndef BOOST_MATH_FLOAT128_TYPE
248 #      define BOOST_MATH_FLOAT128_TYPE _Quad
249 #  endif
250 #endif
251 //
252 // Check for WinCE with no iostream support:
253 //
254 #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
255 #  define BOOST_MATH_NO_LEXICAL_CAST
256 #endif
257 
258 //
259 // Helper macro for controlling the FP behaviour:
260 //
261 #ifndef BOOST_MATH_CONTROL_FP
262 #  define BOOST_MATH_CONTROL_FP
263 #endif
264 //
265 // Helper macro for using statements:
266 //
267 #define BOOST_MATH_STD_USING_CORE \
268    using std::abs;\
269    using std::acos;\
270    using std::cos;\
271    using std::fmod;\
272    using std::modf;\
273    using std::tan;\
274    using std::asin;\
275    using std::cosh;\
276    using std::frexp;\
277    using std::pow;\
278    using std::tanh;\
279    using std::atan;\
280    using std::exp;\
281    using std::ldexp;\
282    using std::sin;\
283    using std::atan2;\
284    using std::fabs;\
285    using std::log;\
286    using std::sinh;\
287    using std::ceil;\
288    using std::floor;\
289    using std::log10;\
290    using std::sqrt;
291 
292 #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
293 
294 namespace boost{ namespace math{
295 namespace tools
296 {
297 
298 template <class T>
BOOST_PREVENT_MACRO_SUBSTITUTION(T a,T b,T c)299 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c)
300 {
301    return (std::max)((std::max)(a, b), c);
302 }
303 
304 template <class T>
BOOST_PREVENT_MACRO_SUBSTITUTION(T a,T b,T c,T d)305 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d)
306 {
307    return (std::max)((std::max)(a, b), (std::max)(c, d));
308 }
309 
310 } // namespace tools
311 
312 template <class T>
suppress_unused_variable_warning(const T &)313 void suppress_unused_variable_warning(const T&)
314 {
315 }
316 
317 namespace detail{
318 
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 }
330 
331 }} // namespace boost namespace math
332 
333 #ifdef __GLIBC_PREREQ
334 #  if __GLIBC_PREREQ(2,14)
335 #     define BOOST_MATH_HAVE_FIXED_GLIBC
336 #  endif
337 #endif
338 
339 #if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H)
340 //
341 // This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445
342 // Basically powl and expl can return garbage when the result is small and certain exception flags are set
343 // on entrance to these functions.  This appears to have been fixed in Glibc 2.14 (May 2011).
344 // Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4
345 //
346 
347    #include <boost/detail/fenv.hpp>
348 
349 #  ifdef FE_ALL_EXCEPT
350 
351 namespace boost{ namespace math{
352    namespace detail
353    {
354    struct fpu_guard
355    {
fpu_guardboost::math::detail::fpu_guard356       fpu_guard()
357       {
358          fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
359          feclearexcept(FE_ALL_EXCEPT);
360       }
~fpu_guardboost::math::detail::fpu_guard361       ~fpu_guard()
362       {
363          fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
364       }
365    private:
366       fexcept_t m_flags;
367    };
368 
369    } // namespace detail
370    }} // namespaces
371 
372 #    define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
373 #    define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
374 
375 #  else
376 
377 #    define BOOST_FPU_EXCEPTION_GUARD
378 #    define BOOST_MATH_INSTRUMENT_FPU
379 
380 #  endif
381 
382 #else // All other platforms.
383 #  define BOOST_FPU_EXCEPTION_GUARD
384 #  define BOOST_MATH_INSTRUMENT_FPU
385 #endif
386 
387 #ifdef BOOST_MATH_INSTRUMENT
388 
389 #  include <iostream>
390 #  include <iomanip>
391 #  include <typeinfo>
392 
393 #  define BOOST_MATH_INSTRUMENT_CODE(x) \
394       std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
395 #  define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
396 
397 #else
398 
399 #  define BOOST_MATH_INSTRUMENT_CODE(x)
400 #  define BOOST_MATH_INSTRUMENT_VARIABLE(name)
401 
402 #endif
403 
404 #endif // BOOST_MATH_TOOLS_CONFIG_HPP
405 
406 
407 
408 
409 
410