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/predef.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>
20 #include <climits>
21 #include <cfloat>
22 #if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
23 #  include <math.h>
24 #endif
25 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
26 #  include <limits>
27 #endif
28 
29 #include <boost/math/tools/user.hpp>
30 
31 #if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \
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
35 #endif
36 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
37 //
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:
41 //
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)
45 #  include <float.h>
46 #endif
47 #ifdef __IBMCPP__
48 //
49 // For reasons I don't unserstand, 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
53 #endif
54 #ifdef sun
55 // Any use of __float128 in program startup code causes a segfault  (tested JM 2015, Solaris 11).
56 #  define BOOST_MATH_DISABLE_FLOAT128
57 #endif
58 #ifdef __HAIKU__
59 //
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
65 #endif
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)
67 //
68 // Darwin's rather strange "double double" is rather hard to
69 // support, it should be possible given enough effort though...
70 //
71 #  define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
72 #endif
73 #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
74 //
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.
80 //
81 // We'll be conservative and disable long double support for this compiler.
82 //
83 // Comment out this #define and try building the tests to determine whether
84 // your Intel compiler version has this issue or not.
85 //
86 #  define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
87 #endif
88 #if defined(unix) && defined(__INTEL_COMPILER)
89 //
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:
93 //
94 #define BOOST_MATH_DISABLE_STD_FPCLASSIFY
95 #endif
96 
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)
100 #endif
101 
102 #ifdef __IBMCPP__
103 #  define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
104 #endif
105 
106 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
107 #  define BOOST_MATH_USE_C99
108 #endif
109 
110 #if (defined(__hpux) && !defined(__hppa))
111 #  define BOOST_MATH_USE_C99
112 #endif
113 
114 #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
115 #  define BOOST_MATH_USE_C99
116 #endif
117 
118 #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
119 #  define BOOST_MATH_USE_C99
120 #endif
121 
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
127 #endif
128 
129 #if BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
130 
131 #  include "boost/type.hpp"
132 #  include "boost/non_type.hpp"
133 
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>*
138 
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)
147 
148 #else
149 
150 // no workaround needed: expand to nothing
151 
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)
156 
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)
161 
162 
163 #endif // __SUNPRO_CC
164 
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
169 #else
170 #  define BOOST_MATH_SMALL_CONSTANT(x) x
171 #endif
172 
173 
174 #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
175 //
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.
179 //
180 #  define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
181 #endif
182 //
183 // Tune performance options for specific compilers:
184 //
185 #ifdef BOOST_MSVC
186 #  define BOOST_MATH_POLY_METHOD 2
187 #  define BOOST_MATH_RATIONAL_METHOD 1
188 #elif defined(BOOST_INTEL)
189 #  define BOOST_MATH_POLY_METHOD 2
190 #  define BOOST_MATH_RATIONAL_METHOD 1
191 #elif defined(__GNUC__)
192 #if __GNUC__ < 4
193 #  define BOOST_MATH_POLY_METHOD 3
194 #  define BOOST_MATH_RATIONAL_METHOD 3
195 #  define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
196 #  define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
197 #else
198 #  define BOOST_MATH_POLY_METHOD 3
199 #  define BOOST_MATH_RATIONAL_METHOD 1
200 #endif
201 #endif
202 
203 #if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE)
204 #  define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
205 #  define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
206 #endif
207 
208 //
209 // constexpr support, early GCC implementations can't cope so disable
210 // constexpr for them:
211 //
212 #if !defined(__clang) && defined(__GNUC__)
213 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 490
214 #  define BOOST_MATH_DISABLE_CONSTEXPR
215 #endif
216 #endif
217 
218 #ifdef BOOST_MATH_DISABLE_CONSTEXPR
219 #  define BOOST_MATH_CONSTEXPR
220 #else
221 #  define BOOST_MATH_CONSTEXPR BOOST_CONSTEXPR
222 #endif
223 
224 //
225 // noexcept support:
226 //
227 #ifndef BOOST_NO_CXX11_NOEXCEPT
228 #ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
229 #include <type_traits>
230 #  define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value)
231 #  define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value)
232 #else
233 #include <boost/type_traits/is_floating_point.hpp>
234 #  define BOOST_MATH_NOEXCEPT(T) noexcept(boost::is_floating_point<T>::value)
235 #  define BOOST_MATH_IS_FLOAT(T) (boost::is_floating_point<T>::value)
236 #endif
237 #else
238 #  define BOOST_MATH_NOEXCEPT(T)
239 #  define BOOST_MATH_IS_FLOAT(T) false
240 #endif
241 
242 //
243 // The maximum order of polynomial that will be evaluated
244 // via an unrolled specialisation:
245 //
246 #ifndef BOOST_MATH_MAX_POLY_ORDER
247 #  define BOOST_MATH_MAX_POLY_ORDER 20
248 #endif
249 //
250 // Set the method used to evaluate polynomials and rationals:
251 //
252 #ifndef BOOST_MATH_POLY_METHOD
253 #  define BOOST_MATH_POLY_METHOD 2
254 #endif
255 #ifndef BOOST_MATH_RATIONAL_METHOD
256 #  define BOOST_MATH_RATIONAL_METHOD 1
257 #endif
258 //
259 // decide whether to store constants as integers or reals:
260 //
261 #ifndef BOOST_MATH_INT_TABLE_TYPE
262 #  define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
263 #endif
264 #ifndef BOOST_MATH_INT_VALUE_SUFFIX
265 #  define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
266 #endif
267 //
268 // Test whether to support __float128, if we don't have quadmath.h then this can't currently work:
269 //
270 #ifndef BOOST_MATH_USE_FLOAT128
271 #ifdef __has_include
272 #if ! __has_include("quadmath.h")
273 #define BOOST_MATH_DISABLE_FLOAT128
274 #endif
275 #elif !defined(BOOST_ARCH_X86)
276 #define BOOST_MATH_DISABLE_FLOAT128
277 #endif
278 #endif
279 //
280 // And then the actual configuration:
281 //
282 #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__) \
283    && !defined(BOOST_MATH_DISABLE_FLOAT128) || defined(BOOST_MATH_USE_FLOAT128)
284 //
285 // Only enable this when the compiler really is GCC as clang and probably
286 // intel too don't support __float128 yet :-(
287 //
288 #ifndef BOOST_MATH_USE_FLOAT128
289 #  define BOOST_MATH_USE_FLOAT128
290 #endif
291 
292 #  if defined(BOOST_INTEL) && defined(BOOST_INTEL_CXX_VERSION) && (BOOST_INTEL_CXX_VERSION >= 1310) && defined(__GNUC__)
293 #    if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
294 #      define BOOST_MATH_FLOAT128_TYPE __float128
295 #    endif
296 #  elif defined(__GNUC__)
297 #      define BOOST_MATH_FLOAT128_TYPE __float128
298 #  endif
299 
300 #  ifndef BOOST_MATH_FLOAT128_TYPE
301 #      define BOOST_MATH_FLOAT128_TYPE _Quad
302 #  endif
303 #endif
304 //
305 // Check for WinCE with no iostream support:
306 //
307 #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
308 #  define BOOST_MATH_NO_LEXICAL_CAST
309 #endif
310 
311 //
312 // Helper macro for controlling the FP behaviour:
313 //
314 #ifndef BOOST_MATH_CONTROL_FP
315 #  define BOOST_MATH_CONTROL_FP
316 #endif
317 //
318 // Helper macro for using statements:
319 //
320 #define BOOST_MATH_STD_USING_CORE \
321    using std::abs;\
322    using std::acos;\
323    using std::cos;\
324    using std::fmod;\
325    using std::modf;\
326    using std::tan;\
327    using std::asin;\
328    using std::cosh;\
329    using std::frexp;\
330    using std::pow;\
331    using std::tanh;\
332    using std::atan;\
333    using std::exp;\
334    using std::ldexp;\
335    using std::sin;\
336    using std::atan2;\
337    using std::fabs;\
338    using std::log;\
339    using std::sinh;\
340    using std::ceil;\
341    using std::floor;\
342    using std::log10;\
343    using std::sqrt;
344 
345 #define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE
346 
347 namespace boost{ namespace math{
348 namespace tools
349 {
350 
351 template <class T>
BOOST_PREVENT_MACRO_SUBSTITUTION(T a,T b,T c)352 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T)
353 {
354    return (std::max)((std::max)(a, b), c);
355 }
356 
357 template <class T>
BOOST_PREVENT_MACRO_SUBSTITUTION(T a,T b,T c,T d)358 inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T)
359 {
360    return (std::max)((std::max)(a, b), (std::max)(c, d));
361 }
362 
363 } // namespace tools
364 
365 template <class T>
suppress_unused_variable_warning(const T &)366 void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T)
367 {
368 }
369 
370 namespace detail{
371 
372 template <class T>
373 struct is_integer_for_rounding
374 {
375    static const bool value = boost::is_integral<T>::value
376 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
377       || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer)
378 #endif
379       ;
380 };
381 
382 }
383 
384 }} // namespace boost namespace math
385 
386 #ifdef __GLIBC_PREREQ
387 #  if __GLIBC_PREREQ(2,14)
388 #     define BOOST_MATH_HAVE_FIXED_GLIBC
389 #  endif
390 #endif
391 
392 #if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H)
393 //
394 // This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445
395 // Basically powl and expl can return garbage when the result is small and certain exception flags are set
396 // on entrance to these functions.  This appears to have been fixed in Glibc 2.14 (May 2011).
397 // Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4
398 //
399 
400    #include <boost/detail/fenv.hpp>
401 
402 #  ifdef FE_ALL_EXCEPT
403 
404 namespace boost{ namespace math{
405    namespace detail
406    {
407    struct fpu_guard
408    {
fpu_guardboost::math::detail::fpu_guard409       fpu_guard()
410       {
411          fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
412          feclearexcept(FE_ALL_EXCEPT);
413       }
~fpu_guardboost::math::detail::fpu_guard414       ~fpu_guard()
415       {
416          fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
417       }
418    private:
419       fexcept_t m_flags;
420    };
421 
422    } // namespace detail
423    }} // namespaces
424 
425 #    define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;
426 #    define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
427 
428 #  else
429 
430 #    define BOOST_FPU_EXCEPTION_GUARD
431 #    define BOOST_MATH_INSTRUMENT_FPU
432 
433 #  endif
434 
435 #else // All other platforms.
436 #  define BOOST_FPU_EXCEPTION_GUARD
437 #  define BOOST_MATH_INSTRUMENT_FPU
438 #endif
439 
440 #ifdef BOOST_MATH_INSTRUMENT
441 
442 #  include <iostream>
443 #  include <iomanip>
444 #  include <typeinfo>
445 
446 #  define BOOST_MATH_INSTRUMENT_CODE(x) \
447       std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
448 #  define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name)
449 
450 #else
451 
452 #  define BOOST_MATH_INSTRUMENT_CODE(x)
453 #  define BOOST_MATH_INSTRUMENT_VARIABLE(name)
454 
455 #endif
456 
457 #endif // BOOST_MATH_TOOLS_CONFIG_HPP
458 
459 
460 
461 
462 
463