From 77dda6f157303f1bf9b61bc3010010e47bac0ec7 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 16 Aug 2024 09:32:53 +0700 Subject: [PATCH 1/4] Fix warning C4701: "potentially uninitialized local variable used" --- include/boost/math/special_functions/detail/bessel_ik.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/math/special_functions/detail/bessel_ik.hpp b/include/boost/math/special_functions/detail/bessel_ik.hpp index 0c653b4753..9cc885f4c6 100644 --- a/include/boost/math/special_functions/detail/bessel_ik.hpp +++ b/include/boost/math/special_functions/detail/bessel_ik.hpp @@ -334,6 +334,8 @@ int bessel_ik(T v, T x, T* result_I, T* result_K, int kind, const Policy& pol) T eight_z = 8 * x; Kv = 1 + (mu - 1) / eight_z + (mu - 1) * (mu - 9) / (2 * eight_z * eight_z) + (mu - 1) * (mu - 9) * (mu - 25) / (6 * eight_z * eight_z * eight_z); Kv *= exp(-x) * constants::root_pi() / sqrt(2 * x); + n = 0; + u = 0; } else { From 3bed94d69e8a85bab6515f7b10b5e08845e9cad0 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 16 Aug 2024 17:38:12 +0700 Subject: [PATCH 2/4] Add failed tests --- include/boost/math/special_functions/detail/bessel_ik.hpp | 4 ++-- test/test_bessel_j.hpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/boost/math/special_functions/detail/bessel_ik.hpp b/include/boost/math/special_functions/detail/bessel_ik.hpp index 9cc885f4c6..a342ccf0c5 100644 --- a/include/boost/math/special_functions/detail/bessel_ik.hpp +++ b/include/boost/math/special_functions/detail/bessel_ik.hpp @@ -18,6 +18,7 @@ #include #include #include +#include // Modified Bessel functions of the first and second kind of fractional order @@ -334,8 +335,6 @@ int bessel_ik(T v, T x, T* result_I, T* result_K, int kind, const Policy& pol) T eight_z = 8 * x; Kv = 1 + (mu - 1) / eight_z + (mu - 1) * (mu - 9) / (2 * eight_z * eight_z) + (mu - 1) * (mu - 9) * (mu - 25) / (6 * eight_z * eight_z * eight_z); Kv *= exp(-x) * constants::root_pi() / sqrt(2 * x); - n = 0; - u = 0; } else { @@ -416,6 +415,7 @@ int bessel_ik(T v, T x, T* result_I, T* result_K, int kind, const Policy& pol) } if (reflect) { + BOOST_MATH_ASSERT(fabs(v - n - u) < tools::forth_root_epsilon()); T z = (u + n % 2); T fact = (2 / pi()) * (boost::math::sin_pi(z, pol) * Kv); if(fact == 0) diff --git a/test/test_bessel_j.hpp b/test/test_bessel_j.hpp index 82106213ea..c54ad4fa8b 100644 --- a/test/test_bessel_j.hpp +++ b/test/test_bessel_j.hpp @@ -288,6 +288,7 @@ void test_bessel(T, const char* name) BOOST_CHECK_EQUAL(boost::math::cyl_bessel_j(T(0), std::numeric_limits::infinity()), T(0)); BOOST_CHECK_EQUAL(boost::math::cyl_bessel_j(T(2), std::numeric_limits::infinity()), T(0)); BOOST_CHECK_EQUAL(boost::math::cyl_bessel_j(T(1.25), std::numeric_limits::infinity()), T(0)); + BOOST_CHECK_EQUAL(boost::math::cyl_bessel_j(T(-1.25), std::numeric_limits::infinity()), T(0)); BOOST_CHECK_EQUAL(boost::math::sph_bessel(0, std::numeric_limits::infinity()), T(0)); BOOST_CHECK_EQUAL(boost::math::sph_bessel(1, std::numeric_limits::infinity()), T(0)); BOOST_CHECK_EQUAL(boost::math::sph_bessel(2, std::numeric_limits::infinity()), T(0)); From f29be8d4c9748e02c9a8a4362566e8ef4ef57e13 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 16 Aug 2024 17:39:37 +0700 Subject: [PATCH 3/4] correct fix --- .../boost/math/special_functions/detail/bessel_ik.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/boost/math/special_functions/detail/bessel_ik.hpp b/include/boost/math/special_functions/detail/bessel_ik.hpp index a342ccf0c5..badb70dee4 100644 --- a/include/boost/math/special_functions/detail/bessel_ik.hpp +++ b/include/boost/math/special_functions/detail/bessel_ik.hpp @@ -327,6 +327,11 @@ int bessel_ik(T v, T x, T* result_I, T* result_K, int kind, const Policy& pol) T scale = 1; T scale_sign = 1; + n = iround(v, pol); + u = v - n; // -1/2 <= u < 1/2 + BOOST_MATH_INSTRUMENT_VARIABLE(n); + BOOST_MATH_INSTRUMENT_VARIABLE(u); + if (((kind & need_i) == 0) && (fabs(4 * v * v - 25) / (8 * x) < tools::forth_root_epsilon())) { // A&S 9.7.2 @@ -338,11 +343,6 @@ int bessel_ik(T v, T x, T* result_I, T* result_K, int kind, const Policy& pol) } else { - n = iround(v, pol); - u = v - n; // -1/2 <= u < 1/2 - BOOST_MATH_INSTRUMENT_VARIABLE(n); - BOOST_MATH_INSTRUMENT_VARIABLE(u); - BOOST_MATH_ASSERT(x > 0); // Error handling for x <= 0 handled in cyl_bessel_i and cyl_bessel_k // x is positive until reflection From 59db0fc1144febac0d2a3104fc78cc5a3e801370 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 16 Aug 2024 17:40:24 +0700 Subject: [PATCH 4/4] remove unneeded include --- include/boost/math/special_functions/detail/bessel_ik.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/boost/math/special_functions/detail/bessel_ik.hpp b/include/boost/math/special_functions/detail/bessel_ik.hpp index badb70dee4..2ffb0f060c 100644 --- a/include/boost/math/special_functions/detail/bessel_ik.hpp +++ b/include/boost/math/special_functions/detail/bessel_ik.hpp @@ -18,7 +18,6 @@ #include #include #include -#include // Modified Bessel functions of the first and second kind of fractional order