blob: 77f03a5d81cf21c0e8ed1b68f8aa24f4e1743e54 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -07006#ifndef NDNBOOST_MATH_TOOLS_CONFIG_HPP
7#define NDNBOOST_MATH_TOOLS_CONFIG_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07008
9#ifdef _MSC_VER
10#pragma once
11#endif
12
13#include <ndnboost/config.hpp>
14#include <ndnboost/cstdint.hpp> // for ndnboost::uintmax_t
15#include <ndnboost/detail/workaround.hpp>
16#include <algorithm> // for min and max
17#include <ndnboost/config/no_tr1/cmath.hpp>
18#include <climits>
19#include <cfloat>
20#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
21# include <math.h>
22#endif
23
24#include <ndnboost/math/tools/user.hpp>
25
26#if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \
27 || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070028 && !defined(NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
29# define NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070030#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -070031#if NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x582))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070032//
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:
36//
Jeff Thompson3d613fd2013-10-15 15:39:04 -070037# define NDNBOOST_MATH_NO_REAL_CONCEPT_TESTS
38# define NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
39# define NDNBOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070040# include <float.h>
41#endif
42#ifdef __IBMCPP__
43//
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).
Jeff Thompson3d613fd2013-10-15 15:39:04 -070047# define NDNBOOST_MATH_NO_REAL_CONCEPT_TESTS
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070048#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070050//
51// Darwin's rather strange "double double" is rather hard to
52// support, it should be possible given enough effort though...
53//
Jeff Thompson3d613fd2013-10-15 15:39:04 -070054# define NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070055#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -070056#if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070057//
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.
63//
64// We'll be conservative and disable long double support for this compiler.
65//
66// Comment out this #define and try building the tests to determine whether
67// your Intel compiler version has this issue or not.
68//
Jeff Thompson3d613fd2013-10-15 15:39:04 -070069# define NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070070#endif
71#if defined(unix) && defined(__INTEL_COMPILER)
72//
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:
76//
Jeff Thompson3d613fd2013-10-15 15:39:04 -070077#define NDNBOOST_MATH_DISABLE_STD_FPCLASSIFY
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070078#endif
79
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080#if defined(NDNBOOST_MSVC) && !defined(_WIN32_WCE)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070081 // Better safe than sorry, our tests don't support hardware exceptions:
Jeff Thompson3d613fd2013-10-15 15:39:04 -070082# define NDNBOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070083#endif
84
85#ifdef __IBMCPP__
Jeff Thompson3d613fd2013-10-15 15:39:04 -070086# define NDNBOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070087#endif
88
89#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))
Jeff Thompson3d613fd2013-10-15 15:39:04 -070090# define NDNBOOST_MATH_USE_C99
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070091#endif
92
93#if (defined(__hpux) && !defined(__hppa))
Jeff Thompson3d613fd2013-10-15 15:39:04 -070094# define NDNBOOST_MATH_USE_C99
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070095#endif
96
97#if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)
Jeff Thompson3d613fd2013-10-15 15:39:04 -070098# define NDNBOOST_MATH_USE_C99
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070099#endif
100
101#if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700102# define NDNBOOST_MATH_USE_C99
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700103#endif
104
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105#if defined(__CYGWIN__) || defined(__HP_aCC) || defined(NDNBOOST_INTEL) \
106 || defined(NDNBOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \
107 || (defined(__GNUC__) && !defined(NDNBOOST_MATH_USE_C99))\
108 || defined(NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
109# define NDNBOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700110#endif
111
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700112#if defined(NDNBOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS) || NDNBOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700113
114# include "ndnboost/type.hpp"
115# include "ndnboost/non_type.hpp"
116
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700117# define NDNBOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) ndnboost::type<t>* = 0
118# define NDNBOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) ndnboost::type<t>*
119# define NDNBOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) ndnboost::non_type<t, v>* = 0
120# define NDNBOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) ndnboost::non_type<t, v>*
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700121
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700122# define NDNBOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \
123 , NDNBOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
124# define NDNBOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \
125 , NDNBOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
126# define NDNBOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \
127 , NDNBOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
128# define NDNBOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \
129 , NDNBOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700130
131#else
132
133// no workaround needed: expand to nothing
134
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700135# define NDNBOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)
136# define NDNBOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
137# define NDNBOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
138# define NDNBOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700139
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700140# define NDNBOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
141# define NDNBOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)
142# define NDNBOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
143# define NDNBOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700144
145
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700146#endif // defined NDNBOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700147
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700148#if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(NDNBOOST_MATH_SMALL_CONSTANT)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700149// 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:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700151# define NDNBOOST_MATH_SMALL_CONSTANT(x) 0
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700152#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700153# define NDNBOOST_MATH_SMALL_CONSTANT(x) x
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700154#endif
155
156
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700157#if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1400)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700158//
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.
162//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700163# define NDNBOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700164#endif
165//
166// Tune performance options for specific compilers:
167//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700168#ifdef NDNBOOST_MSVC
169# define NDNBOOST_MATH_POLY_METHOD 2
170#elif defined(NDNBOOST_INTEL)
171# define NDNBOOST_MATH_POLY_METHOD 2
172# define NDNBOOST_MATH_RATIONAL_METHOD 2
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700173#elif defined(__GNUC__)
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700174# define NDNBOOST_MATH_POLY_METHOD 3
175# define NDNBOOST_MATH_RATIONAL_METHOD 3
176# define NDNBOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
177# define NDNBOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700178#endif
179
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700180#if defined(NDNBOOST_NO_LONG_LONG) && !defined(NDNBOOST_MATH_INT_TABLE_TYPE)
181# define NDNBOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
182# define NDNBOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700183#endif
184
185//
186// The maximum order of polynomial that will be evaluated
187// via an unrolled specialisation:
188//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700189#ifndef NDNBOOST_MATH_MAX_POLY_ORDER
190# define NDNBOOST_MATH_MAX_POLY_ORDER 17
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700191#endif
192//
193// Set the method used to evaluate polynomials and rationals:
194//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700195#ifndef NDNBOOST_MATH_POLY_METHOD
196# define NDNBOOST_MATH_POLY_METHOD 1
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700197#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700198#ifndef NDNBOOST_MATH_RATIONAL_METHOD
199# define NDNBOOST_MATH_RATIONAL_METHOD 0
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700200#endif
201//
202// decide whether to store constants as integers or reals:
203//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700204#ifndef NDNBOOST_MATH_INT_TABLE_TYPE
205# define NDNBOOST_MATH_INT_TABLE_TYPE(RT, IT) IT
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700206#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700207#ifndef NDNBOOST_MATH_INT_VALUE_SUFFIX
208# define NDNBOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700209#endif
210//
211// Test whether to support __float128:
212//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700213#if defined(_GLIBCXX_USE_FLOAT128) && defined(NDNBOOST_GCC) && !defined(__STRICT_ANSI__)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700214//
215// Only enable this when the compiler really is GCC as clang and probably
216// intel too don't support __float128 yet :-(
217//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700218# define NDNBOOST_MATH_USE_FLOAT128
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700219#endif
220//
221// Check for WinCE with no iostream support:
222//
223#if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700224# define NDNBOOST_MATH_NO_LEXICAL_CAST
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700225#endif
226
227//
228// Helper macro for controlling the FP behaviour:
229//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700230#ifndef NDNBOOST_MATH_CONTROL_FP
231# define NDNBOOST_MATH_CONTROL_FP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700232#endif
233//
234// Helper macro for using statements:
235//
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700236#define NDNBOOST_MATH_STD_USING_CORE \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700237 using std::abs;\
238 using std::acos;\
239 using std::cos;\
240 using std::fmod;\
241 using std::modf;\
242 using std::tan;\
243 using std::asin;\
244 using std::cosh;\
245 using std::frexp;\
246 using std::pow;\
247 using std::tanh;\
248 using std::atan;\
249 using std::exp;\
250 using std::ldexp;\
251 using std::sin;\
252 using std::atan2;\
253 using std::fabs;\
254 using std::log;\
255 using std::sinh;\
256 using std::ceil;\
257 using std::floor;\
258 using std::log10;\
259 using std::sqrt;
260
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700261#define NDNBOOST_MATH_STD_USING NDNBOOST_MATH_STD_USING_CORE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700262
263namespace ndnboost{ namespace math{
264namespace tools
265{
266
267template <class T>
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700268inline T max NDNBOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700269{
270 return (std::max)((std::max)(a, b), c);
271}
272
273template <class T>
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700274inline T max NDNBOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700275{
276 return (std::max)((std::max)(a, b), (std::max)(c, d));
277}
278
279} // namespace tools
280
281template <class T>
282void suppress_unused_variable_warning(const T&)
283{
284}
285
286}} // namespace ndnboost namespace math
287
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700288#if ((defined(__linux__) && !defined(__UCLIBC__)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(NDNBOOST_NO_FENV_H)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700289
290 #include <ndnboost/detail/fenv.hpp>
291
292# ifdef FE_ALL_EXCEPT
293
294namespace ndnboost{ namespace math{
295 namespace detail
296 {
297 struct fpu_guard
298 {
299 fpu_guard()
300 {
301 fegetexceptflag(&m_flags, FE_ALL_EXCEPT);
302 feclearexcept(FE_ALL_EXCEPT);
303 }
304 ~fpu_guard()
305 {
306 fesetexceptflag(&m_flags, FE_ALL_EXCEPT);
307 }
308 private:
309 fexcept_t m_flags;
310 };
311
312 } // namespace detail
313 }} // namespaces
314
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700315# define NDNBOOST_FPU_EXCEPTION_GUARD ndnboost::math::detail::fpu_guard local_guard_object;
316# define NDNBOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); NDNBOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0);
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700317
318# else
319
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700320# define NDNBOOST_FPU_EXCEPTION_GUARD
321# define NDNBOOST_MATH_INSTRUMENT_FPU
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700322
323# endif
324
325#else // All other platforms.
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700326# define NDNBOOST_FPU_EXCEPTION_GUARD
327# define NDNBOOST_MATH_INSTRUMENT_FPU
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700328#endif
329
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700330#ifdef NDNBOOST_MATH_INSTRUMENT
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700331
332# include <iostream>
333# include <iomanip>
334# include <typeinfo>
335
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700336# define NDNBOOST_MATH_INSTRUMENT_CODE(x) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700337 std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700338# define NDNBOOST_MATH_INSTRUMENT_VARIABLE(name) NDNBOOST_MATH_INSTRUMENT_CODE(NDNBOOST_STRINGIZE(name) << " = " << name)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700339
340#else
341
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700342# define NDNBOOST_MATH_INSTRUMENT_CODE(x)
343# define NDNBOOST_MATH_INSTRUMENT_VARIABLE(name)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700344
345#endif
346
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700347#endif // NDNBOOST_MATH_TOOLS_CONFIG_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700348
349
350
351
352