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

Rework logic and check some branch cover

This commit is contained in:
ckormanyos
2025-08-07 12:37:28 +02:00
parent f52df1cb9e
commit 018010e695
2 changed files with 22 additions and 3 deletions

View File

@@ -84,7 +84,11 @@ BOOST_MATH_GPU_ENABLED T bessel_jn(int n, T x, const Policy& pol)
current = value;
}
}
else if((x < 1) || ((n > x * x / 4) && (x < 5)))
else if(x < 1)
{
return factor * bessel_j_small_z_series(T(n), x, pol);
}
else if((x < 5) && (n > x * x / 4))
{
return factor * bessel_j_small_z_series(T(n), x, pol);
}

View File

@@ -327,7 +327,12 @@ namespace boost { namespace math {
// x is positive until reflection
W = T(2) / (x * pi<T>()); // Wronskian
T Yv_scale = 1;
if(((kind & need_y) == 0) && ((x < 1) || ((v > x * x / 4) && (x < 5))))
const bool kind_does_not_need_y { ((kind & need_y) == 0) };
const bool x_is_lt_one { (x < 1) };
if(kind_does_not_need_y && x_is_lt_one)
{
//
// This series will actually converge rapidly for all small
@@ -337,7 +342,17 @@ namespace boost { namespace math {
Jv = bessel_j_small_z_series(v, x, pol);
Yv = boost::math::numeric_limits<T>::quiet_NaN();
}
else if((x < 1) && (u != 0) && (log(policies::get_epsilon<T, Policy>() / 2) > v * log((x/2) * (x/2) / v)))
else if(kind_does_not_need_y && ((x < 5) && (v > x * x / 4)))
{
//
// This series will actually converge rapidly for all small
// x - say up to x < 20 - but the first few terms are large
// and divergent which leads to large errors :-(
//
Jv = bessel_j_small_z_series(v, x, pol);
Yv = boost::math::numeric_limits<T>::quiet_NaN();
}
else if(x_is_lt_one && (u != 0) && (log(policies::get_epsilon<T, Policy>() / 2) > v * log((x/2) * (x/2) / v)))
{
// Evaluate using series representations.
// This is particularly important for x << v as in this