mirror of
https://github.com/boostorg/math.git
synced 2026-02-15 01:02:14 +00:00
Manual merge from bernoulli-numbers branch to bernoulli-tgamma branch.
This commit is contained in:
@@ -249,6 +249,31 @@ template <class T>
|
||||
inline T raise_overflow_error(
|
||||
const char* ,
|
||||
const char* ,
|
||||
const T&,
|
||||
const ::boost::math::policies::overflow_error< ::boost::math::policies::ignore_error>&)
|
||||
{
|
||||
// This may or may not do the right thing, but the user asked for the error
|
||||
// to be ignored so here we go anyway:
|
||||
return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T raise_overflow_error(
|
||||
const char* ,
|
||||
const char* ,
|
||||
const ::boost::math::policies::overflow_error< ::boost::math::policies::errno_on_error>&)
|
||||
{
|
||||
errno = ERANGE;
|
||||
// This may or may not do the right thing, but the user asked for the error
|
||||
// to be silent so here we go anyway:
|
||||
return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T raise_overflow_error(
|
||||
const char* ,
|
||||
const char* ,
|
||||
const T&,
|
||||
const ::boost::math::policies::overflow_error< ::boost::math::policies::errno_on_error>&)
|
||||
{
|
||||
errno = ERANGE;
|
||||
@@ -266,6 +291,23 @@ inline T raise_overflow_error(
|
||||
return user_overflow_error(function, message, std::numeric_limits<T>::infinity());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T raise_overflow_error(
|
||||
const char* function,
|
||||
const char* message,
|
||||
const T& val,
|
||||
const ::boost::math::policies::overflow_error< ::boost::math::policies::user_error>&)
|
||||
{
|
||||
std::string fmsg("Error in function ");
|
||||
#ifndef BOOST_NO_RTTI
|
||||
fmsg += (boost::format(function) % typeid(T).name()).str();
|
||||
#else
|
||||
fmsg += function;
|
||||
#endif
|
||||
int prec = 2 + (boost::math::policies::digits<T, boost::math::policies::policy<> >() * 30103UL) / 100000UL;
|
||||
std::string msg = do_format(boost::format(message), boost::io::group(std::setprecision(prec), val));
|
||||
return user_overflow_error(fmsg.c_str(), msg.c_str(), std::numeric_limits<T>::infinity());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T raise_underflow_error(
|
||||
|
||||
@@ -30,7 +30,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, pol);
|
||||
*out = (i & 1 ? 1 : -1) * policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(n)", 0, T(i), pol);
|
||||
++out;
|
||||
}
|
||||
return out;
|
||||
|
||||
@@ -86,7 +86,7 @@ T b2n_asymptotic(int n)
|
||||
+ (((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, Policy())
|
||||
? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, nx, Policy())
|
||||
: exp(approximate_log_of_bernoulli_bn));
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ 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, Policy());
|
||||
return policies::raise_overflow_error<T>("boost::math::tangent_t2n<%1%>(std::size_t)", 0, T(n), Policy());
|
||||
t2n *= p2;
|
||||
p2 -= 1;
|
||||
if(tools::max_value<T>() / p2 < t2n)
|
||||
@@ -420,7 +420,7 @@ public:
|
||||
}
|
||||
for(; n; ++start, --n)
|
||||
{
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(start), pol);
|
||||
++out;
|
||||
}
|
||||
return out;
|
||||
@@ -437,7 +437,7 @@ public:
|
||||
|
||||
for(std::size_t i = (std::max)(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, pol) : bn[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;
|
||||
}
|
||||
#elif defined(BOOST_MATH_NO_ATOMIC_INT)
|
||||
@@ -453,7 +453,7 @@ public:
|
||||
|
||||
for(std::size_t i = (std::max)(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, pol) : bn[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;
|
||||
}
|
||||
|
||||
@@ -481,7 +481,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, 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)", 0, T(i), pol) : bn[static_cast<typename container_type::size_type>(i)];
|
||||
++out;
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ public:
|
||||
}
|
||||
for(; n; ++start, --n)
|
||||
{
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(start), pol);
|
||||
++out;
|
||||
}
|
||||
return out;
|
||||
@@ -541,11 +541,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, pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, 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, pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol);
|
||||
else
|
||||
*out = tn[static_cast<typename container_type::size_type>(i)] / tangent_scale_factor<T>();
|
||||
}
|
||||
@@ -565,11 +565,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, pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, 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, pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol);
|
||||
else
|
||||
*out = tn[static_cast<typename container_type::size_type>(i)] / tangent_scale_factor<T>();
|
||||
}
|
||||
@@ -601,11 +601,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, pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, 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, pol);
|
||||
*out = policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol);
|
||||
else
|
||||
*out = tn[static_cast<typename container_type::size_type>(i)] / tangent_scale_factor<T>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user