Skip to content

Commit 87306e9

Browse files
committed
Implement suggestions by jzmaddock
1 parent 7503be4 commit 87306e9

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

include/boost/math/special_functions/gamma.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,14 +1481,14 @@ BOOST_MATH_GPU_ENABLED T gamma_incomplete_imp_final(T a, T x, bool normalised, b
14811481
#ifdef BOOST_MATH_HAS_NVRTC
14821482
if (boost::math::is_same_v<T, float>)
14831483
{
1484-
init_value = (normalised ? 1 : ::tgammaf(a));
1484+
init_value = (normalised ? T(1) : ::tgammaf(a));
14851485
}
14861486
else
14871487
{
1488-
init_value = (normalised ? 1 : ::tgamma(a));
1488+
init_value = (normalised ? T(1) : ::tgamma(a));
14891489
}
14901490
#else
1491-
init_value = (normalised ? 1 : boost::math::tgamma(a, pol));
1491+
init_value = (normalised ? T(1) : boost::math::tgamma(a, pol));
14921492
#endif
14931493

14941494
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
16201620
T gam;
16211621
if (boost::math::is_same_v<T, float>)
16221622
{
1623-
gam = normalised ? 1 : ::tgammaf(a);
1623+
gam = normalised ? T(1) : ::tgammaf(a);
16241624
}
16251625
else
16261626
{
1627-
gam = normalised ? 1 : ::tgamma(a);
1627+
gam = normalised ? T(1) : ::tgamma(a);
16281628
}
16291629
#else
1630-
T gam = normalised ? 1 : boost::math::tgamma(a, pol);
1630+
T gam = normalised ? T(1) : boost::math::tgamma(a, pol);
16311631
#endif
16321632
result = gam - result;
16331633
}
1634-
if(p_derivative && x > 0)
1634+
if(p_derivative)
16351635
{
16361636
//
16371637
// Need to convert prefix term to derivative:
16381638
//
1639-
if((x < 1) && (tools::max_value<T>() * x < *p_derivative))
1639+
if(x == 0 || ((x < 1) && (tools::max_value<T>() * x < *p_derivative)))
16401640
{
16411641
// overflow, just return an arbitrarily large value:
16421642
*p_derivative = tools::max_value<T>() / 2;
16431643
}
1644-
1645-
*p_derivative /= x;
1644+
else
1645+
*p_derivative /= x;
16461646
}
16471647

16481648
return result;
@@ -2110,8 +2110,8 @@ BOOST_MATH_GPU_ENABLED T gamma_p_derivative_imp(T a, T x, const Policy& pol)
21102110
//
21112111
if(x == 0)
21122112
{
2113-
return (a > 1) ? 0 :
2114-
(a == 1) ? 1 : policies::raise_overflow_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", nullptr, pol);
2113+
return (a > 1) ? T(0) :
2114+
(a == 1) ? T(1) : policies::raise_overflow_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", nullptr, pol);
21152115
}
21162116
//
21172117
// Normal case:

test/git_issue_1249.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ void test_impl()
127127

128128
void test_derivative()
129129
{
130+
using namespace boost::math::detail;
130131
double derivative = 0;
131-
double result = boost::math::detail::gamma_incomplete_imp(1.0, 0.0,
132-
true, false, c_policy(), &derivative);
132+
double result = gamma_incomplete_imp(1.0, 0.0, true, false, c_policy(), &derivative);
133133
BOOST_CHECK(errno == 0);
134-
BOOST_CHECK_EQUAL(derivative, 0);
134+
BOOST_CHECK_EQUAL(derivative, tools::max_value<double>() / 2);
135135
BOOST_CHECK_EQUAL(result, 0);
136136
}
137137

0 commit comments

Comments
 (0)