2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Implement suggestions by jzmaddock

This commit is contained in:
Kilian Kilger
2025-04-18 12:04:17 +02:00
parent 7503be4cfa
commit 410f74821b
2 changed files with 15 additions and 15 deletions

View File

@@ -1481,14 +1481,14 @@ BOOST_MATH_GPU_ENABLED T gamma_incomplete_imp_final(T a, T x, bool normalised, b
#ifdef BOOST_MATH_HAS_NVRTC
if (boost::math::is_same_v<T, float>)
{
init_value = (normalised ? 1 : ::tgammaf(a));
init_value = (normalised ? T(1) : ::tgammaf(a));
}
else
{
init_value = (normalised ? 1 : ::tgamma(a));
init_value = (normalised ? T(1) : ::tgamma(a));
}
#else
init_value = (normalised ? 1 : boost::math::tgamma(a, pol));
init_value = (normalised ? T(1) : boost::math::tgamma(a, pol));
#endif
if(normalised || (result >= 1) || (tools::max_value<T>() * result > init_value))
@@ -1620,29 +1620,29 @@ BOOST_MATH_GPU_ENABLED T gamma_incomplete_imp_final(T a, T x, bool normalised, b
T gam;
if (boost::math::is_same_v<T, float>)
{
gam = normalised ? 1 : ::tgammaf(a);
gam = normalised ? T(1) : ::tgammaf(a);
}
else
{
gam = normalised ? 1 : ::tgamma(a);
gam = normalised ? T(1) : ::tgamma(a);
}
#else
T gam = normalised ? 1 : boost::math::tgamma(a, pol);
T gam = normalised ? T(1) : boost::math::tgamma(a, pol);
#endif
result = gam - result;
}
if(p_derivative && x > 0)
if(p_derivative)
{
//
// Need to convert prefix term to derivative:
//
if((x < 1) && (tools::max_value<T>() * x < *p_derivative))
if(x == 0 || ((x < 1) && (tools::max_value<T>() * x < *p_derivative)))
{
// overflow, just return an arbitrarily large value:
*p_derivative = tools::max_value<T>() / 2;
}
*p_derivative /= x;
else
*p_derivative /= x;
}
return result;
@@ -2110,8 +2110,8 @@ BOOST_MATH_GPU_ENABLED T gamma_p_derivative_imp(T a, T x, const Policy& pol)
//
if(x == 0)
{
return (a > 1) ? 0 :
(a == 1) ? 1 : policies::raise_overflow_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", nullptr, pol);
return (a > 1) ? T(0) :
(a == 1) ? T(1) : policies::raise_overflow_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", nullptr, pol);
}
//
// Normal case:

View File

@@ -127,11 +127,11 @@ void test_impl()
void test_derivative()
{
using namespace boost::math::detail;
double derivative = 0;
double result = boost::math::detail::gamma_incomplete_imp(1.0, 0.0,
true, false, c_policy(), &derivative);
double result = gamma_incomplete_imp(1.0, 0.0, true, false, c_policy(), &derivative);
BOOST_CHECK(errno == 0);
BOOST_CHECK_EQUAL(derivative, 0);
BOOST_CHECK_EQUAL(derivative, tools::max_value<double>() / 2);
BOOST_CHECK_EQUAL(result, 0);
}