/usr/include/boost/math/tools/precision.hpp is in libboost1.54-dev 1.54.0-4ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | // Copyright John Maddock 2005-2006.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_MATH_TOOLS_PRECISION_INCLUDED
#define BOOST_MATH_TOOLS_PRECISION_INCLUDED
#ifdef _MSC_VER
#pragma once
#endif
#include <boost/limits.hpp>
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/if.hpp>
#include <boost/math/policies/policy.hpp>
// These two are for LDBL_MAN_DIG:
#include <limits.h>
#include <math.h>
namespace boost{ namespace math
{
namespace tools
{
// If T is not specialized, the functions digits, max_value and min_value,
// all get synthesised automatically from std::numeric_limits.
// However, if numeric_limits is not specialised for type RealType,
// for example with NTL::RR type, then you will get a compiler error
// when code tries to use these functions, unless you explicitly specialise them.
// For example if the precision of RealType varies at runtime,
// then numeric_limits support may not be appropriate,
// see boost/math/tools/ntl.hpp for examples like
// template <> NTL::RR max_value<NTL::RR> ...
// See Conceptual Requirements for Real Number Types.
template <class T>
inline int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10);
#else
BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
BOOST_ASSERT(::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10);
#endif
return std::numeric_limits<T>::radix == 2
? std::numeric_limits<T>::digits
: ((std::numeric_limits<T>::digits + 1) * 1000L) / 301L;
}
template <class T>
inline T max_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
#else
BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
#endif
return (std::numeric_limits<T>::max)();
} // Also used as a finite 'infinite' value for - and +infinity, for example:
// -max_value<double> = -1.79769e+308, max_value<double> = 1.79769e+308.
template <class T>
inline T min_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
#else
BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
#endif
return (std::numeric_limits<T>::min)();
}
namespace detail{
//
// Logarithmic limits come next, note that although
// we can compute these from the log of the max value
// that is not in general thread safe (if we cache the value)
// so it's better to specialise these:
//
// For type float first:
//
template <class T>
inline T log_max_value(const mpl::int_<128>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
return 88.0f;
}
template <class T>
inline T log_min_value(const mpl::int_<128>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
return -87.0f;
}
//
// Now double:
//
template <class T>
inline T log_max_value(const mpl::int_<1024>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
return 709.0;
}
template <class T>
inline T log_min_value(const mpl::int_<1024>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
return -708.0;
}
//
// 80 and 128-bit long doubles:
//
template <class T>
inline T log_max_value(const mpl::int_<16384>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
return 11356.0L;
}
template <class T>
inline T log_min_value(const mpl::int_<16384>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
return -11355.0L;
}
template <class T>
inline T log_max_value(const mpl::int_<0>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
#else
BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
#endif
BOOST_MATH_STD_USING
static const T val = log((std::numeric_limits<T>::max)());
return val;
}
template <class T>
inline T log_min_value(const mpl::int_<0>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
#else
BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
#endif
BOOST_MATH_STD_USING
static const T val = log((std::numeric_limits<T>::min)());
return val;
}
template <class T>
inline T epsilon(const mpl::true_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
return std::numeric_limits<T>::epsilon();
}
#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106))
template <>
inline long double epsilon<long double>(const mpl::true_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(long double))
{
// numeric_limits on Darwin tells lies here.
// This static assert fails for some unknown reason, so
// disabled for now...
// BOOST_STATIC_ASSERT(std::numeric_limits<long double>::digits == 106);
return 2.4651903288156618919116517665087e-32L;
}
#endif
template <class T>
inline T epsilon(const mpl::false_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
BOOST_MATH_STD_USING // for ADL of std names
static const T eps = ldexp(static_cast<T>(1), 1-policies::digits<T, policies::policy<> >());
return eps;
}
} // namespace detail
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4309)
#endif
template <class T>
inline T log_max_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
typedef typename mpl::if_c<
(std::numeric_limits<T>::radix == 2) &&
(std::numeric_limits<T>::max_exponent == 128
|| std::numeric_limits<T>::max_exponent == 1024
|| std::numeric_limits<T>::max_exponent == 16384),
mpl::int_<(std::numeric_limits<T>::max_exponent > INT_MAX ? INT_MAX : static_cast<int>(std::numeric_limits<T>::max_exponent))>,
mpl::int_<0>
>::type tag_type;
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
return detail::log_max_value<T>(tag_type());
#else
BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
BOOST_MATH_STD_USING
static const T val = log((std::numeric_limits<T>::max)());
return val;
#endif
}
template <class T>
inline T log_min_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
typedef typename mpl::if_c<
(std::numeric_limits<T>::radix == 2) &&
(std::numeric_limits<T>::max_exponent == 128
|| std::numeric_limits<T>::max_exponent == 1024
|| std::numeric_limits<T>::max_exponent == 16384),
mpl::int_<(std::numeric_limits<T>::max_exponent > INT_MAX ? INT_MAX : static_cast<int>(std::numeric_limits<T>::max_exponent))>,
mpl::int_<0>
>::type tag_type;
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
return detail::log_min_value<T>(tag_type());
#else
BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
BOOST_MATH_STD_USING
static const T val = log((std::numeric_limits<T>::min)());
return val;
#endif
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
template <class T>
inline T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
return detail::epsilon<T>(mpl::bool_< ::std::numeric_limits<T>::is_specialized>());
#else
return ::std::numeric_limits<T>::is_specialized ?
detail::epsilon<T>(mpl::true_()) :
detail::epsilon<T>(mpl::false_());
#endif
}
namespace detail{
template <class T>
inline T root_epsilon_imp(const mpl::int_<24>&)
{
return static_cast<T>(0.00034526698300124390839884978618400831996329879769945L);
}
template <class T>
inline T root_epsilon_imp(const T*, const mpl::int_<53>&)
{
return static_cast<T>(0.1490116119384765625e-7L);
}
template <class T>
inline T root_epsilon_imp(const T*, const mpl::int_<64>&)
{
return static_cast<T>(0.32927225399135962333569506281281311031656150598474e-9L);
}
template <class T>
inline T root_epsilon_imp(const T*, const mpl::int_<113>&)
{
return static_cast<T>(0.1387778780781445675529539585113525390625e-16L);
}
template <class T, class Tag>
inline T root_epsilon_imp(const T*, const Tag&)
{
BOOST_MATH_STD_USING
static const T r_eps = sqrt(tools::epsilon<T>());
return r_eps;
}
template <class T>
inline T forth_root_epsilon_imp(const T*, const mpl::int_<24>&)
{
return static_cast<T>(0.018581361171917516667460937040007436176452688944747L);
}
template <class T>
inline T forth_root_epsilon_imp(const T*, const mpl::int_<53>&)
{
return static_cast<T>(0.0001220703125L);
}
template <class T>
inline T forth_root_epsilon_imp(const T*, const mpl::int_<64>&)
{
return static_cast<T>(0.18145860519450699870567321328132261891067079047605e-4L);
}
template <class T>
inline T forth_root_epsilon_imp(const T*, const mpl::int_<113>&)
{
return static_cast<T>(0.37252902984619140625e-8L);
}
template <class T, class Tag>
inline T forth_root_epsilon_imp(const T*, const Tag&)
{
BOOST_MATH_STD_USING
static const T r_eps = sqrt(sqrt(tools::epsilon<T>()));
return r_eps;
}
}
template <class T>
inline T root_epsilon()
{
typedef mpl::int_< (::std::numeric_limits<T>::radix == 2) ? std::numeric_limits<T>::digits : 0> tag_type;
return detail::root_epsilon_imp(static_cast<T const*>(0), tag_type());
}
template <class T>
inline T forth_root_epsilon()
{
typedef mpl::int_< (::std::numeric_limits<T>::radix == 2) ? std::numeric_limits<T>::digits : 0> tag_type;
return detail::forth_root_epsilon_imp(static_cast<T const*>(0), tag_type());
}
} // namespace tools
} // namespace math
} // namespace boost
#endif // BOOST_MATH_TOOLS_PRECISION_INCLUDED
|