2
0
mirror of https://github.com/boostorg/math.git synced 2026-02-25 16:32:15 +00:00

Make inverses overflow safe.

This commit is contained in:
jzmaddock
2022-11-25 17:45:01 +00:00
parent 8add2b4373
commit 18fd65aaa1
2 changed files with 20 additions and 3 deletions

View File

@@ -631,8 +631,17 @@ T ibeta_inv_imp(T a, T b, T p, T q, const Policy& pol, T* py)
// Try and compute the easy way first:
//
T bet = 0;
if(b < 2)
bet = boost::math::beta(a, b, pol);
if (b < 2)
{
try
{
bet = boost::math::beta(a, b, pol);
}
catch (const std::overflow_error&)
{
bet = tools::max_value<T>();
}
}
if(bet != 0)
{
y = pow(b * q * bet, 1/b);

View File

@@ -543,7 +543,15 @@ namespace detail {
last_f0 = f0;
delta2 = delta1;
delta1 = delta;
detail::unpack_tuple(f(result), f0, f1, f2);
try
{
detail::unpack_tuple(f(result), f0, f1, f2);
}
catch (const std::overflow_error&)
{
f0 = max > 0 ? tools::max_value<T>() : -tools::min_value<T>();
f1 = f2 = 0;
}
--count;
BOOST_MATH_INSTRUMENT_VARIABLE(f0);