Skip to content

Commit

Permalink
More bessel function tests for improved coverage.
Browse files Browse the repository at this point in the history
Kill some unused variable warnings.
Mark up code we think is unreachable but aren't sure about.
  • Loading branch information
jzmaddock committed Feb 9, 2024
1 parent eef497e commit 851c171
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
10 changes: 5 additions & 5 deletions include/boost/math/special_functions/detail/bessel_jy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,14 @@ namespace boost { namespace math {
else if(kind & need_j)
*J = policies::raise_domain_error<T>(function, "Value of Bessel J_v(x) is complex-infinity at %1%", x, pol); // complex infinity
else
*J = std::numeric_limits<T>::quiet_NaN(); // any value will do, not using J.
*J = std::numeric_limits<T>::quiet_NaN(); // LCOV_EXCL_LINE, we should never get here, any value will do, not using J.

if((kind & need_y) == 0)
*Y = std::numeric_limits<T>::quiet_NaN(); // any value will do, not using Y.
else
{
// We shoud never get here:
BOOST_MATH_ASSERT(x != 0);
BOOST_MATH_ASSERT(x != 0); // LCOV_EXCL_LINE
}
return 1;
}
Expand Down Expand Up @@ -420,9 +420,9 @@ namespace boost { namespace math {
{
if(temme_jy(u, x, &Yu, &Yu1, pol)) // Temme series
{
// domain error, this should really have already been handled, LCOV_EXCL_LINE
*J = *Y = Yu;
return 1;
// domain error, this should really have already been handled.
*J = *Y = Yu; // LCOV_EXCL_LINE
return 1; // LCOV_EXCL_LINE
}
prev = Yu;
current = Yu1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ inline T bessel_y_small_z_series(T v, T x, T* pscale, const Policy& pol)
{
scale /= gam;
gam = 1;
/*
* We can never get here, it would require p < 1/max_value.
if(tools::max_value<T>() * p < gam)
{
return -policies::raise_overflow_error<T>(function, nullptr, pol);
}
*/
}
prefix = -gam / (constants::pi<T>() * p);
}
Expand Down Expand Up @@ -244,14 +247,15 @@ T bessel_yn_small_z(int n, T z, T* scale, const Policy& pol)
#endif

T result = -((boost::math::factorial<T>(n - 1, pol) / constants::pi<T>()));
if(p * tools::max_value<T>() < result)
if(p * tools::max_value<T>() < fabs(result))
{
T div = tools::max_value<T>() / 8;
result /= div;
*scale /= div;
if(p * tools::max_value<T>() < result)
{
return -policies::raise_overflow_error<T>("bessel_yn_small_z<%1%>(%1%,%1%)", nullptr, pol);
// Impossible to get here??
return -policies::raise_overflow_error<T>("bessel_yn_small_z<%1%>(%1%,%1%)", nullptr, pol); // LCOV_EXCL_LINE
}
}
return result / p;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
}
else
{
root_lo *= 0.75F;
root_lo *= 0.75F; // LCOV_EXCL_LINE probably unreachable, but hard to prove?
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/special_functions/detail/bessel_y0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ template <typename T, typename Policy>
T bessel_y0(T x, const Policy&);

template <typename T, typename Policy>
T bessel_y0(T x, const Policy& pol)
T bessel_y0(T x, const Policy&)
{
static const T P1[] = {
static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0723538782003176831e+11)),
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/special_functions/detail/bessel_y1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ template <typename T, typename Policy>
T bessel_y1(T x, const Policy&);

template <typename T, typename Policy>
T bessel_y1(T x, const Policy& pol)
T bessel_y1(T x, const Policy&)
{
static const T P1[] = {
static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.0535726612579544093e+13)),
Expand Down
8 changes: 7 additions & 1 deletion test/test_bessel_y.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void test_bessel(T, const char* name)
#endif
BOOST_IF_CONSTEXPR(std::numeric_limits<T>::has_infinity && (std::numeric_limits<T>::min_exponent < -1072))
{
static const std::array<std::array<T, 3>, 5> coverage_data = { {
static const std::array<std::array<T, 3>, 7> coverage_data = { {
#if LDBL_MAX_10_EXP > 4931
{{ SC_(15.25), ldexp(T(1), -1071), SC_(-9.39553199265929955912687892204143267985847111378392154596e4931)}},
#else
Expand All @@ -264,6 +264,12 @@ void test_bessel(T, const char* name)
#endif
{{ SC_(233.0), ldexp(T(1), -63), -std::numeric_limits<T>::infinity() }},
{{ SC_(233.0), ldexp(T(1), -64), -std::numeric_limits<T>::infinity() }},
#if LDBL_MAX_10_EXP > 413
{{ SC_(200.25), SC_(1.25), SC_(-3.545198572052800784992190965856441074217589237581037286156e413)}},
#else
{{ SC_(200.25), SC_(1.25), -std::numeric_limits<T>::infinity()}},
#endif
{{ SC_(1652.25), SC_(1.25), -std::numeric_limits<T>::infinity()}},
} };

do_test_cyl_neumann_y<T>(coverage_data, name, "Extra Coverage Data");
Expand Down

0 comments on commit 851c171

Please sign in to comment.