diff --git a/include/boost/math/special_functions/detail/ibeta_inverse.hpp b/include/boost/math/special_functions/detail/ibeta_inverse.hpp index b9f0995a6..90a94e644 100644 --- a/include/boost/math/special_functions/detail/ibeta_inverse.hpp +++ b/include/boost/math/special_functions/detail/ibeta_inverse.hpp @@ -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(); + } + } if(bet != 0) { y = pow(b * q * bet, 1/b); diff --git a/include/boost/math/tools/roots.hpp b/include/boost/math/tools/roots.hpp index cb2c89123..ccf908f21 100644 --- a/include/boost/math/tools/roots.hpp +++ b/include/boost/math/tools/roots.hpp @@ -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() : -tools::min_value(); + f1 = f2 = 0; + } --count; BOOST_MATH_INSTRUMENT_VARIABLE(f0);