mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Replace 0 with nullptr in pole error
This commit is contained in:
@@ -537,7 +537,7 @@ mpfr_class digamma_imp(mpfr_class x, const std::integral_constant<int, 0>* , con
|
||||
//
|
||||
if(remainder == 0)
|
||||
{
|
||||
return policies::raise_pole_error<mpfr_class>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol);
|
||||
return policies::raise_pole_error<mpfr_class>("boost::math::digamma<%1%>(%1%)", nullptr, (1-x), pol);
|
||||
}
|
||||
result = constants::pi<mpfr_class>() / tan(constants::pi<mpfr_class>() * remainder);
|
||||
}
|
||||
|
||||
@@ -487,7 +487,7 @@ mpfr::mpreal digamma_imp(mpfr::mpreal x, const std::integral_constant<int, 0>* ,
|
||||
//
|
||||
if(remainder == 0)
|
||||
{
|
||||
return policies::raise_pole_error<mpfr::mpreal>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol);
|
||||
return policies::raise_pole_error<mpfr::mpreal>("boost::math::digamma<%1%>(%1%)", nullptr, (1-x), pol);
|
||||
}
|
||||
result = constants::pi<mpfr::mpreal>() / tan(constants::pi<mpfr::mpreal>() * remainder);
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ private:
|
||||
int exp = 0;
|
||||
NTL::RR t;
|
||||
bool neg = a < V(0) ? true : false;
|
||||
if(neg)
|
||||
if(neg)
|
||||
a = -a;
|
||||
while(a)
|
||||
{
|
||||
@@ -467,7 +467,7 @@ struct ntl_lanczos
|
||||
return lanczos61UDT::lanczos_sum_near_2(z);
|
||||
}
|
||||
static ntl::RR g()
|
||||
{
|
||||
{
|
||||
unsigned long p = ntl::RR::precision();
|
||||
if(p <= 72)
|
||||
return lanczos13UDT::g();
|
||||
@@ -691,8 +691,8 @@ namespace ntl{
|
||||
double r;
|
||||
conv(r, z.value());
|
||||
return boost::math::tools::halley_iterate(
|
||||
asin_root(z),
|
||||
RR(std::asin(r)),
|
||||
asin_root(z),
|
||||
RR(std::asin(r)),
|
||||
RR(-boost::math::constants::pi<RR>()/2),
|
||||
RR(boost::math::constants::pi<RR>()/2),
|
||||
NTL::RR::precision());
|
||||
@@ -719,8 +719,8 @@ namespace ntl{
|
||||
double r;
|
||||
conv(r, z.value());
|
||||
return boost::math::tools::halley_iterate(
|
||||
acos_root(z),
|
||||
RR(std::acos(r)),
|
||||
acos_root(z),
|
||||
RR(std::acos(r)),
|
||||
RR(-boost::math::constants::pi<RR>()/2),
|
||||
RR(boost::math::constants::pi<RR>()/2),
|
||||
NTL::RR::precision());
|
||||
@@ -748,8 +748,8 @@ namespace ntl{
|
||||
double r;
|
||||
conv(r, z.value());
|
||||
return boost::math::tools::halley_iterate(
|
||||
atan_root(z),
|
||||
RR(std::atan(r)),
|
||||
atan_root(z),
|
||||
RR(std::atan(r)),
|
||||
-boost::math::constants::pi<RR>()/2,
|
||||
boost::math::constants::pi<RR>()/2,
|
||||
NTL::RR::precision());
|
||||
@@ -858,7 +858,7 @@ ntl::RR digamma_imp(ntl::RR x, const std::integral_constant<int, 0>* , const Pol
|
||||
//
|
||||
if(remainder == 0)
|
||||
{
|
||||
return policies::raise_pole_error<ntl::RR>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol);
|
||||
return policies::raise_pole_error<ntl::RR>("boost::math::digamma<%1%>(%1%)", nullptr, (1-x), pol);
|
||||
}
|
||||
result = constants::pi<ntl::RR>() / tan(constants::pi<ntl::RR>() * remainder);
|
||||
}
|
||||
|
||||
@@ -917,7 +917,7 @@ template <typename P>
|
||||
class is_policy_imp
|
||||
{
|
||||
public:
|
||||
static constexpr bool value = (sizeof(::boost::math::policies::detail::test_is_policy(static_cast<P*>(0))) == sizeof(char));
|
||||
static constexpr bool value = (sizeof(::boost::math::policies::detail::test_is_policy(static_cast<P*>(nullptr))) == sizeof(char));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ OutputIterator bernoulli_number_imp(OutputIterator out, std::size_t start, std::
|
||||
for(std::size_t i = (std::max)(static_cast<std::size_t>(max_bernoulli_b2n<T>::value + 1), start); i < start + n; ++i)
|
||||
{
|
||||
// We must overflow:
|
||||
*out = (i & 1 ? 1 : -1) * policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(n)", 0, T(i), pol);
|
||||
*out = (i & 1 ? 1 : -1) * policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(n)", nullptr, T(i), pol);
|
||||
++out;
|
||||
}
|
||||
return out;
|
||||
|
||||
@@ -31,16 +31,16 @@ template <class T, class Policy>
|
||||
T b2n_asymptotic(int n)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
const T nx = static_cast<T>(n);
|
||||
const auto nx = static_cast<T>(n);
|
||||
const T nx2(nx * nx);
|
||||
|
||||
const T approximate_log_of_bernoulli_bn =
|
||||
const T approximate_log_of_bernoulli_bn =
|
||||
((boost::math::constants::half<T>() + nx) * log(nx))
|
||||
+ ((boost::math::constants::half<T>() - nx) * log(boost::math::constants::pi<T>()))
|
||||
+ (((T(3) / 2) - nx) * boost::math::constants::ln_two<T>())
|
||||
+ ((nx * (T(2) - (nx2 * 7) * (1 + ((nx2 * 30) * ((nx2 * 12) - 1))))) / (((nx2 * nx2) * nx2) * 2520));
|
||||
return ((n / 2) & 1 ? 1 : -1) * (approximate_log_of_bernoulli_bn > tools::log_max_value<T>()
|
||||
? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, nx, Policy())
|
||||
return ((n / 2) & 1 ? 1 : -1) * (approximate_log_of_bernoulli_bn > tools::log_max_value<T>()
|
||||
? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", nullptr, nx, Policy())
|
||||
: static_cast<T>(exp(approximate_log_of_bernoulli_bn)));
|
||||
}
|
||||
|
||||
@@ -52,11 +52,15 @@ T t2n_asymptotic(int n)
|
||||
T t2n = fabs(b2n_asymptotic<T, Policy>(2 * n)) / (2 * n);
|
||||
T p2 = ldexp(T(1), n);
|
||||
if(tools::max_value<T>() / p2 < t2n)
|
||||
return policies::raise_overflow_error<T>("boost::math::tangent_t2n<%1%>(std::size_t)", 0, T(n), Policy());
|
||||
{
|
||||
return policies::raise_overflow_error<T>("boost::math::tangent_t2n<%1%>(std::size_t)", nullptr, T(n), Policy());
|
||||
}
|
||||
t2n *= p2;
|
||||
p2 -= 1;
|
||||
if(tools::max_value<T>() / p2 < t2n)
|
||||
return policies::raise_overflow_error<T>("boost::math::tangent_t2n<%1%>(std::size_t)", 0, Policy());
|
||||
{
|
||||
return policies::raise_overflow_error<T>("boost::math::tangent_t2n<%1%>(std::size_t)", nullptr, Policy());
|
||||
}
|
||||
t2n *= p2;
|
||||
return t2n;
|
||||
}
|
||||
@@ -66,19 +70,19 @@ T t2n_asymptotic(int n)
|
||||
// us to elude a great deal of runtime checking for values below
|
||||
// n, and only perform the full overflow checks when we know that we're
|
||||
// getting close to the point where our calculations will overflow.
|
||||
// We use Luschny's LogB3 formula (http://www.luschny.de/math/primes/bernincl.html)
|
||||
// We use Luschny's LogB3 formula (http://www.luschny.de/math/primes/bernincl.html)
|
||||
// to find the limit, and since we're dealing with the log of the Bernoulli numbers
|
||||
// we need only perform the calculation at double precision and not with T
|
||||
// (which may be a multiprecision type). The limit returned is within 1 of the true
|
||||
// limit for all the types tested. Note that although the code below is basically
|
||||
// the same as b2n_asymptotic above, it has been recast as a continuous real-valued
|
||||
// the same as b2n_asymptotic above, it has been recast as a continuous real-valued
|
||||
// function as this makes the root finding go smoother/faster. It also omits the
|
||||
// sign of the Bernoulli number.
|
||||
//
|
||||
struct max_bernoulli_root_functor
|
||||
{
|
||||
max_bernoulli_root_functor(unsigned long long t) : target(static_cast<double>(t)) {}
|
||||
double operator()(double n)
|
||||
explicit max_bernoulli_root_functor(unsigned long long t) : target(static_cast<double>(t)) {}
|
||||
double operator()(double n) const
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
|
||||
@@ -89,7 +93,7 @@ struct max_bernoulli_root_functor
|
||||
const double approximate_log_of_bernoulli_bn
|
||||
= ((boost::math::constants::half<double>() + n) * log(n))
|
||||
+ ((boost::math::constants::half<double>() - n) * log(boost::math::constants::pi<double>()))
|
||||
+ (((double(3) / 2) - n) * boost::math::constants::ln_two<double>())
|
||||
+ (((static_cast<double>(3) / 2) - n) * boost::math::constants::ln_two<double>())
|
||||
+ ((n * (2 - (nx2 * 7) * (1 + ((nx2 * 30) * ((nx2 * 12) - 1))))) / (((nx2 * nx2) * nx2) * 2520));
|
||||
|
||||
return approximate_log_of_bernoulli_bn - target;
|
||||
@@ -102,16 +106,18 @@ template <class T, class Policy>
|
||||
inline std::size_t find_bernoulli_overflow_limit(const std::false_type&)
|
||||
{
|
||||
// Set a limit on how large the result can ever be:
|
||||
static const double max_result = static_cast<double>((std::numeric_limits<std::size_t>::max)() - 1000u);
|
||||
static const auto max_result = static_cast<double>((std::numeric_limits<std::size_t>::max)() - 1000u);
|
||||
|
||||
unsigned long long t = lltrunc(boost::math::tools::log_max_value<T>());
|
||||
max_bernoulli_root_functor fun(t);
|
||||
boost::math::tools::equal_floor tol;
|
||||
std::uintmax_t max_iter = boost::math::policies::get_max_root_iterations<Policy>();
|
||||
double result = boost::math::tools::toms748_solve(fun, sqrt(double(t)), double(t), tol, max_iter).first / 2;
|
||||
double result = boost::math::tools::toms748_solve(fun, sqrt(static_cast<double>(t)), static_cast<double>(t), tol, max_iter).first / 2;
|
||||
if (result > max_result)
|
||||
{
|
||||
result = max_result;
|
||||
|
||||
}
|
||||
|
||||
return static_cast<std::size_t>(result);
|
||||
}
|
||||
|
||||
@@ -126,7 +132,7 @@ std::size_t b2n_overflow_limit()
|
||||
{
|
||||
// This routine is called at program startup if it's called at all:
|
||||
// that guarantees safe initialization of the static variable.
|
||||
typedef std::integral_constant<bool, (bernoulli_imp_variant<T>::value >= 1) && (bernoulli_imp_variant<T>::value <= 3)> tag_type;
|
||||
using tag_type = std::integral_constant<bool, (bernoulli_imp_variant<T>::value >= 1) && (bernoulli_imp_variant<T>::value <= 3)>;
|
||||
static const std::size_t lim = find_bernoulli_overflow_limit<T, Policy>(tag_type());
|
||||
return lim;
|
||||
}
|
||||
@@ -162,22 +168,24 @@ inline T tangent_scale_factor()
|
||||
template <class T>
|
||||
struct fixed_vector : private std::allocator<T>
|
||||
{
|
||||
typedef unsigned size_type;
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
using size_type = unsigned;
|
||||
using iterator = T*;
|
||||
using const_iterator = const T*;
|
||||
fixed_vector() : m_used(0)
|
||||
{
|
||||
{
|
||||
std::size_t overflow_limit = 5 + b2n_overflow_limit<T, policies::policy<> >();
|
||||
m_capacity = static_cast<unsigned>((std::min)(overflow_limit, static_cast<std::size_t>(100000u)));
|
||||
m_data = this->allocate(m_capacity);
|
||||
m_data = this->allocate(m_capacity);
|
||||
}
|
||||
~fixed_vector()
|
||||
{
|
||||
typedef std::allocator<T> allocator_type;
|
||||
typedef std::allocator_traits<allocator_type> allocator_traits;
|
||||
allocator_type& alloc = *this;
|
||||
using allocator_type = std::allocator<T>;
|
||||
using allocator_traits = std::allocator_traits<allocator_type>;
|
||||
allocator_type& alloc = *this;
|
||||
for(unsigned i = 0; i < m_used; ++i)
|
||||
{
|
||||
allocator_traits::destroy(alloc, &m_data[i]);
|
||||
}
|
||||
allocator_traits::deallocate(alloc, m_data, m_capacity);
|
||||
}
|
||||
T& operator[](unsigned n) { BOOST_MATH_ASSERT(n < m_used); return m_data[n]; }
|
||||
@@ -208,7 +216,8 @@ struct fixed_vector : private std::allocator<T>
|
||||
void clear() { m_used = 0; }
|
||||
private:
|
||||
T* m_data;
|
||||
unsigned m_used, m_capacity;
|
||||
unsigned m_used {};
|
||||
unsigned m_capacity;
|
||||
};
|
||||
|
||||
template <class T, class Policy>
|
||||
@@ -220,7 +229,7 @@ public:
|
||||
, m_current_precision(boost::math::tools::digits<T>())
|
||||
{}
|
||||
|
||||
typedef fixed_vector<T> container_type;
|
||||
using container_type = fixed_vector<T>;
|
||||
|
||||
bool tangent(std::size_t m)
|
||||
{
|
||||
@@ -343,7 +352,7 @@ public:
|
||||
// There are basically 3 thread safety options:
|
||||
//
|
||||
// 1) There are no threads (BOOST_HAS_THREADS is not defined).
|
||||
// 2) There are threads, but we do not have a true atomic integer type,
|
||||
// 2) There are threads, but we do not have a true atomic integer type,
|
||||
// in this case we just use a mutex to guard against race conditions.
|
||||
// 3) There are threads, and we have an atomic integer: in this case we can
|
||||
// use the double-checked locking pattern to avoid thread synchronisation
|
||||
@@ -369,7 +378,7 @@ public:
|
||||
}
|
||||
for(; n; ++start, --n)
|
||||
{
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(start), pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", nullptr, T(start), pol);
|
||||
++out;
|
||||
}
|
||||
return out;
|
||||
@@ -400,7 +409,7 @@ public:
|
||||
|
||||
for(std::size_t i = (std::max)(std::size_t(max_bernoulli_b2n<T>::value + 1), start); i < start + n; ++i)
|
||||
{
|
||||
*out = (i >= m_overflow_limit) ? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol) : bn[i];
|
||||
*out = (i >= m_overflow_limit) ? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", nullptr, T(i), pol) : bn[i];
|
||||
++out;
|
||||
}
|
||||
#else
|
||||
@@ -438,7 +447,7 @@ public:
|
||||
|
||||
for(std::size_t i = (std::max)(static_cast<std::size_t>(max_bernoulli_b2n<T>::value + 1), start); i < start + n; ++i)
|
||||
{
|
||||
*out = (i >= m_overflow_limit) ? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol) : bn[static_cast<typename container_type::size_type>(i)];
|
||||
*out = (i >= m_overflow_limit) ? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", nullptr, T(i), pol) : bn[static_cast<typename container_type::size_type>(i)];
|
||||
++out;
|
||||
}
|
||||
|
||||
@@ -453,7 +462,7 @@ public:
|
||||
// There are basically 3 thread safety options:
|
||||
//
|
||||
// 1) There are no threads (BOOST_HAS_THREADS is not defined).
|
||||
// 2) There are threads, but we do not have a true atomic integer type,
|
||||
// 2) There are threads, but we do not have a true atomic integer type,
|
||||
// in this case we just use a mutex to guard against race conditions.
|
||||
// 3) There are threads, and we have an atomic integer: in this case we can
|
||||
// use the double-checked locking pattern to avoid thread synchronisation
|
||||
@@ -507,11 +516,11 @@ public:
|
||||
for(std::size_t i = start; i < start + n; ++i)
|
||||
{
|
||||
if(i >= m_overflow_limit)
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", nullptr, T(i), pol);
|
||||
else
|
||||
{
|
||||
if(tools::max_value<T>() * tangent_scale_factor<T>() < tn[static_cast<typename container_type::size_type>(i)])
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", nullptr, T(i), pol);
|
||||
else
|
||||
*out = tn[static_cast<typename container_type::size_type>(i)] / tangent_scale_factor<T>();
|
||||
}
|
||||
@@ -555,11 +564,11 @@ public:
|
||||
for(std::size_t i = start; i < start + n; ++i)
|
||||
{
|
||||
if(i >= m_overflow_limit)
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", nullptr, T(i), pol);
|
||||
else
|
||||
{
|
||||
if(tools::max_value<T>() * tangent_scale_factor<T>() < tn[static_cast<typename container_type::size_type>(i)])
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", nullptr, T(i), pol);
|
||||
else
|
||||
*out = tn[static_cast<typename container_type::size_type>(i)] / tangent_scale_factor<T>();
|
||||
}
|
||||
@@ -598,7 +607,7 @@ inline typename std::enable_if<(std::numeric_limits<T>::digits == 0) || (std::nu
|
||||
// or it's precision can vary at runtime. So make the cache thread_local so that each thread can
|
||||
// have it's own precision if required:
|
||||
//
|
||||
static
|
||||
static
|
||||
#ifndef BOOST_MATH_NO_THREAD_LOCAL_WITH_NON_TRIVIAL_TYPES
|
||||
BOOST_MATH_THREAD_LOCAL
|
||||
#endif
|
||||
|
||||
@@ -216,7 +216,7 @@ T digamma_imp_1_2(T x, const std::integral_constant<int, 113>*)
|
||||
static const T root4 = (((T(503992070) / 1073741824uL) / 1073741824uL) / 1073741824uL) / 1073741824uL;
|
||||
static const T root5 = BOOST_MATH_BIG_CONSTANT(T, 113, 0.52112228569249997894452490385577338504019838794544e-36);
|
||||
|
||||
static const T P[] = {
|
||||
static const T P[] = {
|
||||
BOOST_MATH_BIG_CONSTANT(T, 113, 0.25479851061131551526977464225335883769),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 113, -0.18684290534374944114622235683619897417),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 113, -0.80360876047931768958995775910991929922),
|
||||
@@ -228,7 +228,7 @@ T digamma_imp_1_2(T x, const std::integral_constant<int, 113>*)
|
||||
BOOST_MATH_BIG_CONSTANT(T, 113, -0.16454996865214115723416538844975174761e-4),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 113, -0.20327832297631728077731148515093164955e-6)
|
||||
};
|
||||
static const T Q[] = {
|
||||
static const T Q[] = {
|
||||
BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 113, 2.6210924610812025425088411043163287646),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 113, 2.6850757078559596612621337395886392594),
|
||||
@@ -276,7 +276,7 @@ T digamma_imp_1_2(T x, const std::integral_constant<int, 64>*)
|
||||
static const T root2 = (T(381566830) / 1073741824uL) / 1073741824uL;
|
||||
static const T root3 = BOOST_MATH_BIG_CONSTANT(T, 64, 0.9016312093258695918615325266959189453125e-19);
|
||||
|
||||
static const T P[] = {
|
||||
static const T P[] = {
|
||||
BOOST_MATH_BIG_CONSTANT(T, 64, 0.254798510611315515235),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 64, -0.314628554532916496608),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 64, -0.665836341559876230295),
|
||||
@@ -284,7 +284,7 @@ T digamma_imp_1_2(T x, const std::integral_constant<int, 64>*)
|
||||
BOOST_MATH_BIG_CONSTANT(T, 64, -0.0541156266153505273939),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 64, -0.00289268368333918761452)
|
||||
};
|
||||
static const T Q[] = {
|
||||
static const T Q[] = {
|
||||
BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 64, 2.1195759927055347547),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 64, 1.54350554664961128724),
|
||||
@@ -326,7 +326,7 @@ T digamma_imp_1_2(T x, const std::integral_constant<int, 53>*)
|
||||
static const T root2 = (T(381566830) / 1073741824uL) / 1073741824uL;
|
||||
static const T root3 = BOOST_MATH_BIG_CONSTANT(T, 53, 0.9016312093258695918615325266959189453125e-19);
|
||||
|
||||
static const T P[] = {
|
||||
static const T P[] = {
|
||||
BOOST_MATH_BIG_CONSTANT(T, 53, 0.25479851061131551),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 53, -0.32555031186804491),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 53, -0.65031853770896507),
|
||||
@@ -334,7 +334,7 @@ T digamma_imp_1_2(T x, const std::integral_constant<int, 53>*)
|
||||
BOOST_MATH_BIG_CONSTANT(T, 53, -0.045251321448739056),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 53, -0.0020713321167745952)
|
||||
};
|
||||
static const T Q[] = {
|
||||
static const T Q[] = {
|
||||
BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 53, 2.0767117023730469),
|
||||
BOOST_MATH_BIG_CONSTANT(T, 53, 1.4606242909763515),
|
||||
@@ -372,13 +372,13 @@ inline T digamma_imp_1_2(T x, const std::integral_constant<int, 24>*)
|
||||
static const float Y = 0.99558162689208984f;
|
||||
static const T root = 1532632.0f / 1048576;
|
||||
static const T root_minor = static_cast<T>(0.3700660185912626595423257213284682051735604e-6L);
|
||||
static const T P[] = {
|
||||
static const T P[] = {
|
||||
0.25479851023250261e0f,
|
||||
-0.44981331915268368e0f,
|
||||
-0.43916936919946835e0f,
|
||||
-0.61041765350579073e-1f
|
||||
};
|
||||
static const T Q[] = {
|
||||
static const T Q[] = {
|
||||
0.1e1,
|
||||
0.15890202430554952e1f,
|
||||
0.65341249856146947e0f,
|
||||
@@ -421,12 +421,12 @@ T digamma_imp(T x, const Tag* t, const Policy& pol)
|
||||
//
|
||||
if(remainder == 0)
|
||||
{
|
||||
return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol);
|
||||
return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", nullptr, (1-x), pol);
|
||||
}
|
||||
result = constants::pi<T>() / tan(constants::pi<T>() * remainder);
|
||||
}
|
||||
if(x == 0)
|
||||
return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", 0, x, pol);
|
||||
return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", nullptr, x, pol);
|
||||
//
|
||||
// If we're above the lower-limit for the
|
||||
// asymptotic expansion then use it:
|
||||
@@ -487,12 +487,12 @@ T digamma_imp(T x, const std::integral_constant<int, 0>* t, const Policy& pol)
|
||||
//
|
||||
if(remainder == 0)
|
||||
{
|
||||
return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", 0, (1 - x), pol);
|
||||
return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", nullptr, (1 - x), pol);
|
||||
}
|
||||
result = constants::pi<T>() / tan(constants::pi<T>() * remainder);
|
||||
}
|
||||
if(x == 0)
|
||||
return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", 0, x, pol);
|
||||
return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", nullptr, x, pol);
|
||||
//
|
||||
// If we're above the lower-limit for the
|
||||
// asymptotic expansion then use it, the
|
||||
@@ -584,7 +584,7 @@ const typename digamma_initializer<T, Policy>::init digamma_initializer<T, Polic
|
||||
} // namespace detail
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename tools::promote_args<T>::type
|
||||
inline typename tools::promote_args<T>::type
|
||||
digamma(T x, const Policy&)
|
||||
{
|
||||
typedef typename tools::promote_args<T>::type result_type;
|
||||
@@ -608,11 +608,11 @@ inline typename tools::promote_args<T>::type
|
||||
|
||||
return policies::checked_narrowing_cast<result_type, Policy>(detail::digamma_imp(
|
||||
static_cast<value_type>(x),
|
||||
static_cast<const tag_type*>(0), forwarding_policy()), "boost::math::digamma<%1%>(%1%)");
|
||||
static_cast<const tag_type*>(nullptr), forwarding_policy()), "boost::math::digamma<%1%>(%1%)");
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename tools::promote_args<T>::type
|
||||
inline typename tools::promote_args<T>::type
|
||||
digamma(T x)
|
||||
{
|
||||
return digamma(x, policies::policy<>());
|
||||
|
||||
@@ -20,12 +20,15 @@ namespace boost{ namespace math{
|
||||
namespace detail{
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename tools::promote_args<T>::type round(const T& v, const Policy& pol, const std::false_type&)
|
||||
inline tools::promote_args_t<T> round(const T& v, const Policy& pol, const std::false_type&)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
typedef typename tools::promote_args<T>::type result_type;
|
||||
using result_type = tools::promote_args_t<T>;
|
||||
|
||||
if(!(boost::math::isfinite)(v))
|
||||
return policies::raise_rounding_error("boost::math::round<%1%>(%1%)", 0, static_cast<result_type>(v), static_cast<result_type>(v), pol);
|
||||
{
|
||||
return policies::raise_rounding_error("boost::math::round<%1%>(%1%)", nullptr, static_cast<result_type>(v), static_cast<result_type>(v), pol);
|
||||
}
|
||||
//
|
||||
// The logic here is rather convoluted, but avoids a number of traps,
|
||||
// see discussion here https://github.com/boostorg/math/pull/8
|
||||
@@ -52,7 +55,7 @@ inline typename tools::promote_args<T>::type round(const T& v, const Policy& pol
|
||||
}
|
||||
}
|
||||
template <class T, class Policy>
|
||||
inline typename tools::promote_args<T>::type round(const T& v, const Policy&, const std::true_type&)
|
||||
inline tools::promote_args_t<T> round(const T& v, const Policy&, const std::true_type&)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
@@ -60,12 +63,12 @@ inline typename tools::promote_args<T>::type round(const T& v, const Policy&, co
|
||||
} // namespace detail
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename tools::promote_args<T>::type round(const T& v, const Policy& pol)
|
||||
inline tools::promote_args_t<T> round(const T& v, const Policy& pol)
|
||||
{
|
||||
return detail::round(v, pol, std::integral_constant<bool, detail::is_integer_for_rounding<T>::value>());
|
||||
}
|
||||
template <class T>
|
||||
inline typename tools::promote_args<T>::type round(const T& v)
|
||||
inline tools::promote_args_t<T> round(const T& v)
|
||||
{
|
||||
return round(v, policies::policy<>());
|
||||
}
|
||||
@@ -74,11 +77,11 @@ inline typename tools::promote_args<T>::type round(const T& v)
|
||||
// implicit conversion to the integer types. For user-defined
|
||||
// number types this will likely not be the case. In that case
|
||||
// these functions should either be specialized for the UDT in
|
||||
// question, or else overloads should be placed in the same
|
||||
// question, or else overloads should be placed in the same
|
||||
// namespace as the UDT: these will then be found via argument
|
||||
// dependent lookup. See our concept archetypes for examples.
|
||||
//
|
||||
// Non-standard numeric limits syntax "(std::numeric_limits<int>::max)()"
|
||||
// Non-standard numeric limits syntax "(std::numeric_limits<int>::max)()"
|
||||
// is to avoid macro substiution from MSVC
|
||||
// https://stackoverflow.com/questions/27442885/syntax-error-with-stdnumeric-limitsmax
|
||||
//
|
||||
@@ -86,10 +89,13 @@ template <class T, class Policy>
|
||||
inline int iround(const T& v, const Policy& pol)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
typedef typename tools::promote_args<T>::type result_type;
|
||||
using result_type = tools::promote_args_t<T>;
|
||||
|
||||
T r = boost::math::round(v, pol);
|
||||
if(r > static_cast<result_type>((std::numeric_limits<int>::max)()) || r < static_cast<result_type>((std::numeric_limits<int>::min)()))
|
||||
return static_cast<int>(policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0, pol));
|
||||
{
|
||||
return static_cast<int>(policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", nullptr, v, 0, pol));
|
||||
}
|
||||
return static_cast<int>(r);
|
||||
}
|
||||
template <class T>
|
||||
@@ -102,10 +108,12 @@ template <class T, class Policy>
|
||||
inline long lround(const T& v, const Policy& pol)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
typedef typename tools::promote_args<T>::type result_type;
|
||||
using result_type = tools::promote_args_t<T>;
|
||||
T r = boost::math::round(v, pol);
|
||||
if(r > static_cast<result_type>((std::numeric_limits<long>::max)()) || r < static_cast<result_type>((std::numeric_limits<long>::min)()))
|
||||
return static_cast<long int>(policies::raise_rounding_error("boost::math::lround<%1%>(%1%)", 0, v, 0L, pol));
|
||||
{
|
||||
return static_cast<long int>(policies::raise_rounding_error("boost::math::lround<%1%>(%1%)", nullptr, v, 0L, pol));
|
||||
}
|
||||
return static_cast<long int>(r);
|
||||
}
|
||||
template <class T>
|
||||
@@ -118,12 +126,13 @@ template <class T, class Policy>
|
||||
inline long long llround(const T& v, const Policy& pol)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
typedef typename tools::promote_args<T>::type result_type;
|
||||
using result_type = tools::promote_args_t<T>;
|
||||
|
||||
T r = boost::math::round(v, pol);
|
||||
if(r > static_cast<result_type>((std::numeric_limits<long long>::max)()) ||
|
||||
if(r > static_cast<result_type>((std::numeric_limits<long long>::max)()) ||
|
||||
r < static_cast<result_type>((std::numeric_limits<long long>::min)()))
|
||||
{
|
||||
return static_cast<long long>(policies::raise_rounding_error("boost::math::llround<%1%>(%1%)", 0, v, static_cast<long long>(0), pol));
|
||||
return static_cast<long long>(policies::raise_rounding_error("boost::math::llround<%1%>(%1%)", nullptr, v, static_cast<long long>(0), pol));
|
||||
}
|
||||
return static_cast<long long>(r);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ T trigamma_prec(T x, const std::integral_constant<int, 53>*, const Policy&)
|
||||
T y = 1 / x;
|
||||
return (1 + tools::evaluate_polynomial(P_4_inf, y) / tools::evaluate_polynomial(Q_4_inf, y)) / x;
|
||||
}
|
||||
|
||||
|
||||
template <class T, class Policy>
|
||||
T trigamma_prec(T x, const std::integral_constant<int, 64>*, const Policy&)
|
||||
{
|
||||
@@ -376,7 +376,7 @@ T trigamma_imp(T x, const Tag* t, const Policy& pol)
|
||||
// Argument reduction for tan:
|
||||
if(floor(x) == x)
|
||||
{
|
||||
return policies::raise_pole_error<T>("boost::math::trigamma<%1%>(%1%)", 0, (1-x), pol);
|
||||
return policies::raise_pole_error<T>("boost::math::trigamma<%1%>(%1%)", nullptr, (1-x), pol);
|
||||
}
|
||||
T s = fabs(x) < fabs(z) ? boost::math::sin_pi(x, pol) : boost::math::sin_pi(z, pol);
|
||||
return -trigamma_imp(z, t, pol) + boost::math::pow<2>(constants::pi<T>()) / (s * s);
|
||||
@@ -427,7 +427,7 @@ const typename trigamma_initializer<T, Policy>::init trigamma_initializer<T, Pol
|
||||
} // namespace detail
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename tools::promote_args<T>::type
|
||||
inline typename tools::promote_args<T>::type
|
||||
trigamma(T x, const Policy&)
|
||||
{
|
||||
typedef typename tools::promote_args<T>::type result_type;
|
||||
@@ -451,11 +451,11 @@ inline typename tools::promote_args<T>::type
|
||||
|
||||
return policies::checked_narrowing_cast<result_type, Policy>(detail::trigamma_imp(
|
||||
static_cast<value_type>(x),
|
||||
static_cast<const tag_type*>(0), forwarding_policy()), "boost::math::trigamma<%1%>(%1%)");
|
||||
static_cast<const tag_type*>(nullptr), forwarding_policy()), "boost::math::trigamma<%1%>(%1%)");
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename tools::promote_args<T>::type
|
||||
inline typename tools::promote_args<T>::type
|
||||
trigamma(T x)
|
||||
{
|
||||
return trigamma(x, policies::policy<>());
|
||||
|
||||
@@ -87,7 +87,7 @@ inline long ltrunc(const T& v, const Policy& pol)
|
||||
result_type r = boost::math::trunc(v, pol);
|
||||
if(r > static_cast<result_type>((std::numeric_limits<long>::max)()) || r < static_cast<result_type>((std::numeric_limits<long>::min)()))
|
||||
{
|
||||
return static_cast<long>(policies::raise_rounding_error("boost::math::ltrunc<%1%>(%1%)", 0, static_cast<result_type>(v), 0L, pol));
|
||||
return static_cast<long>(policies::raise_rounding_error("boost::math::ltrunc<%1%>(%1%)", nullptr, static_cast<result_type>(v), 0L, pol));
|
||||
}
|
||||
return static_cast<long>(r);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ inline long long lltrunc(const T& v, const Policy& pol)
|
||||
if(r > static_cast<result_type>((std::numeric_limits<long long>::max)()) ||
|
||||
r < static_cast<result_type>((std::numeric_limits<long long>::min)()))
|
||||
{
|
||||
return static_cast<long long>(policies::raise_rounding_error("boost::math::lltrunc<%1%>(%1%)", 0, v, static_cast<long long>(0), pol));
|
||||
return static_cast<long long>(policies::raise_rounding_error("boost::math::lltrunc<%1%>(%1%)", nullptr, v, static_cast<long long>(0), pol));
|
||||
}
|
||||
return static_cast<long long>(r);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user