Skip to content

Commit

Permalink
Merge pull request #802 from boostorg/issue799
Browse files Browse the repository at this point in the history
Make sure ibeta_derivative triggers an underflow error when required.
  • Loading branch information
jzmaddock authored Jul 16, 2022
2 parents a0a0b37 + 08f30fb commit 8f5520c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/boost/math/special_functions/beta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ T ibeta_power_terms(T a,
else
{
T p1 = pow(b1, a / b);
T l3 = (log(p1) + log(b2)) * b;
T l3 = (p1 != 0) && (b2 != 0) ? (log(p1) + log(b2)) * b : tools::max_value<T>(); // arbitrary large value if the logs would fail!
if((l3 < tools::log_max_value<T>())
&& (l3 > tools::log_min_value<T>()))
{
Expand All @@ -416,6 +416,15 @@ T ibeta_power_terms(T a,

BOOST_MATH_INSTRUMENT_VARIABLE(result);

if (0 == result)
{
if ((a > 1) && (x == 0))
return result; // true zero
if ((b > 1) && (y == 0))
return result; // true zero
return boost::math::policies::raise_underflow_error<T>(function, nullptr, pol);
}

return result;
}
//
Expand Down

0 comments on commit 8f5520c

Please sign in to comment.