Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 6 | #ifndef NDNBOOST_MATH_TOOLS_CONFIG_HPP |
| 7 | #define NDNBOOST_MATH_TOOLS_CONFIG_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 8 | |
| 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 28 | && !defined(NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) |
| 29 | # define NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 30 | #endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 31 | #if NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x582)) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 32 | // |
| 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 37 | # 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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 40 | # 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 47 | # define NDNBOOST_MATH_NO_REAL_CONCEPT_TESTS |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 48 | #endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 49 | #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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 50 | // |
| 51 | // Darwin's rather strange "double double" is rather hard to |
| 52 | // support, it should be possible given enough effort though... |
| 53 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 54 | # define NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 55 | #endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 56 | #if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 57 | // |
| 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 69 | # define NDNBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 70 | #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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 77 | #define NDNBOOST_MATH_DISABLE_STD_FPCLASSIFY |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 78 | #endif |
| 79 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 80 | #if defined(NDNBOOST_MSVC) && !defined(_WIN32_WCE) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 81 | // Better safe than sorry, our tests don't support hardware exceptions: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 82 | # define NDNBOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 83 | #endif |
| 84 | |
| 85 | #ifdef __IBMCPP__ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 86 | # define NDNBOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 87 | #endif |
| 88 | |
| 89 | #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 90 | # define NDNBOOST_MATH_USE_C99 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 91 | #endif |
| 92 | |
| 93 | #if (defined(__hpux) && !defined(__hppa)) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 94 | # define NDNBOOST_MATH_USE_C99 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 95 | #endif |
| 96 | |
| 97 | #if defined(__GNUC__) && defined(_GLIBCXX_USE_C99) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 98 | # define NDNBOOST_MATH_USE_C99 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 99 | #endif |
| 100 | |
| 101 | #if defined(_LIBCPP_VERSION) && !defined(_MSC_VER) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 102 | # define NDNBOOST_MATH_USE_C99 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 103 | #endif |
| 104 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 105 | #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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 110 | #endif |
| 111 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 112 | #if defined(NDNBOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS) || NDNBOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 113 | |
| 114 | # include "ndnboost/type.hpp" |
| 115 | # include "ndnboost/non_type.hpp" |
| 116 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 117 | # 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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 121 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 122 | # 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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 130 | |
| 131 | #else |
| 132 | |
| 133 | // no workaround needed: expand to nothing |
| 134 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 135 | # 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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 139 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 140 | # 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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 144 | |
| 145 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 146 | #endif // defined NDNBOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 147 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 148 | #if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(NDNBOOST_MATH_SMALL_CONSTANT) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 151 | # define NDNBOOST_MATH_SMALL_CONSTANT(x) 0 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 152 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 153 | # define NDNBOOST_MATH_SMALL_CONSTANT(x) x |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 154 | #endif |
| 155 | |
| 156 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 157 | #if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1400) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 158 | // |
| 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 163 | # define NDNBOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 164 | #endif |
| 165 | // |
| 166 | // Tune performance options for specific compilers: |
| 167 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 168 | #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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 173 | #elif defined(__GNUC__) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 174 | # 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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 178 | #endif |
| 179 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 180 | #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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 183 | #endif |
| 184 | |
| 185 | // |
| 186 | // The maximum order of polynomial that will be evaluated |
| 187 | // via an unrolled specialisation: |
| 188 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 189 | #ifndef NDNBOOST_MATH_MAX_POLY_ORDER |
| 190 | # define NDNBOOST_MATH_MAX_POLY_ORDER 17 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 191 | #endif |
| 192 | // |
| 193 | // Set the method used to evaluate polynomials and rationals: |
| 194 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 195 | #ifndef NDNBOOST_MATH_POLY_METHOD |
| 196 | # define NDNBOOST_MATH_POLY_METHOD 1 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 197 | #endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 198 | #ifndef NDNBOOST_MATH_RATIONAL_METHOD |
| 199 | # define NDNBOOST_MATH_RATIONAL_METHOD 0 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 200 | #endif |
| 201 | // |
| 202 | // decide whether to store constants as integers or reals: |
| 203 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 204 | #ifndef NDNBOOST_MATH_INT_TABLE_TYPE |
| 205 | # define NDNBOOST_MATH_INT_TABLE_TYPE(RT, IT) IT |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 206 | #endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 207 | #ifndef NDNBOOST_MATH_INT_VALUE_SUFFIX |
| 208 | # define NDNBOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 209 | #endif |
| 210 | // |
| 211 | // Test whether to support __float128: |
| 212 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 213 | #if defined(_GLIBCXX_USE_FLOAT128) && defined(NDNBOOST_GCC) && !defined(__STRICT_ANSI__) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 214 | // |
| 215 | // Only enable this when the compiler really is GCC as clang and probably |
| 216 | // intel too don't support __float128 yet :-( |
| 217 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 218 | # define NDNBOOST_MATH_USE_FLOAT128 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 219 | #endif |
| 220 | // |
| 221 | // Check for WinCE with no iostream support: |
| 222 | // |
| 223 | #if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 224 | # define NDNBOOST_MATH_NO_LEXICAL_CAST |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 225 | #endif |
| 226 | |
| 227 | // |
| 228 | // Helper macro for controlling the FP behaviour: |
| 229 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 230 | #ifndef NDNBOOST_MATH_CONTROL_FP |
| 231 | # define NDNBOOST_MATH_CONTROL_FP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 232 | #endif |
| 233 | // |
| 234 | // Helper macro for using statements: |
| 235 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 236 | #define NDNBOOST_MATH_STD_USING_CORE \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 237 | 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 261 | #define NDNBOOST_MATH_STD_USING NDNBOOST_MATH_STD_USING_CORE |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 262 | |
| 263 | namespace ndnboost{ namespace math{ |
| 264 | namespace tools |
| 265 | { |
| 266 | |
| 267 | template <class T> |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 268 | inline T max NDNBOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 269 | { |
| 270 | return (std::max)((std::max)(a, b), c); |
| 271 | } |
| 272 | |
| 273 | template <class T> |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 274 | inline T max NDNBOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 275 | { |
| 276 | return (std::max)((std::max)(a, b), (std::max)(c, d)); |
| 277 | } |
| 278 | |
| 279 | } // namespace tools |
| 280 | |
| 281 | template <class T> |
| 282 | void suppress_unused_variable_warning(const T&) |
| 283 | { |
| 284 | } |
| 285 | |
| 286 | }} // namespace ndnboost namespace math |
| 287 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 288 | #if ((defined(__linux__) && !defined(__UCLIBC__)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(NDNBOOST_NO_FENV_H) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 289 | |
| 290 | #include <ndnboost/detail/fenv.hpp> |
| 291 | |
| 292 | # ifdef FE_ALL_EXCEPT |
| 293 | |
| 294 | namespace 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 315 | # 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 Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 317 | |
| 318 | # else |
| 319 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 320 | # define NDNBOOST_FPU_EXCEPTION_GUARD |
| 321 | # define NDNBOOST_MATH_INSTRUMENT_FPU |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 322 | |
| 323 | # endif |
| 324 | |
| 325 | #else // All other platforms. |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 326 | # define NDNBOOST_FPU_EXCEPTION_GUARD |
| 327 | # define NDNBOOST_MATH_INSTRUMENT_FPU |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 328 | #endif |
| 329 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 330 | #ifdef NDNBOOST_MATH_INSTRUMENT |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 331 | |
| 332 | # include <iostream> |
| 333 | # include <iomanip> |
| 334 | # include <typeinfo> |
| 335 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 336 | # define NDNBOOST_MATH_INSTRUMENT_CODE(x) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 337 | std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl; |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 338 | # define NDNBOOST_MATH_INSTRUMENT_VARIABLE(name) NDNBOOST_MATH_INSTRUMENT_CODE(NDNBOOST_STRINGIZE(name) << " = " << name) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 339 | |
| 340 | #else |
| 341 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 342 | # define NDNBOOST_MATH_INSTRUMENT_CODE(x) |
| 343 | # define NDNBOOST_MATH_INSTRUMENT_VARIABLE(name) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 344 | |
| 345 | #endif |
| 346 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 347 | #endif // NDNBOOST_MATH_TOOLS_CONFIG_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |