diff --git a/include/boost/math/special_functions/bessel_iterators.hpp b/include/boost/math/special_functions/bessel_iterators.hpp index c577f7564..c5dbb5c02 100644 --- a/include/boost/math/special_functions/bessel_iterators.hpp +++ b/include/boost/math/special_functions/bessel_iterators.hpp @@ -9,6 +9,7 @@ #define BOOST_MATH_BESSEL_ITERATORS_HPP #include +#include namespace boost { namespace math { @@ -154,7 +155,7 @@ namespace boost { if (v > 1) boost::math::policies::raise_domain_error("bessel_i_forwards_iterator<%1%>", "Order must be < 0 stable forwards recurrence but got %1%", v, Policy()); } - bessel_i_forwards_iterator(const T& v, const T& x, const T& I_v_plus_1, const T& I_v) + bessel_i_forwards_iterator(const T& v, const T& x, const T& I_v_minus_1, const T& I_v) : it(detail::bessel_ik_recurrence(v, x), I_v_plus_1, I_v) { if (v > 1) diff --git a/include/boost/math/tools/recurrence.hpp b/include/boost/math/tools/recurrence.hpp index 10b3c097b..b08988d4b 100644 --- a/include/boost/math/tools/recurrence.hpp +++ b/include/boost/math/tools/recurrence.hpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include namespace boost { namespace math { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index dbef5a5ae..685bc15cc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -181,6 +181,7 @@ test-suite special_fun : [ run test_bessel_y_prime.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ] [ run test_bessel_i_prime.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ] [ run test_bessel_k_prime.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ] + [ run bessel_iterator_test.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ] [ run test_beta.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ] [ run test_bessel_airy_zeros.cpp ../../test/build//boost_unit_test_framework ] [ run test_bernoulli_constants.cpp ../../test/build//boost_unit_test_framework ] diff --git a/test/bessel_iterator_test.cpp b/test/bessel_iterator_test.cpp new file mode 100644 index 000000000..e79ffda90 --- /dev/null +++ b/test/bessel_iterator_test.cpp @@ -0,0 +1,79 @@ +// (C) Copyright John Maddock, 2024 +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MAIN +#include +#include + + +BOOST_AUTO_TEST_CASE(test_main) +{ + using boost::math::bessel_j_backwards_iterator; + using boost::math::bessel_i_backwards_iterator; + using boost::math::bessel_i_forwards_iterator; + + BOOST_CHECK_THROW(bessel_j_backwards_iterator(-2.3, 5.0), std::domain_error); + BOOST_CHECK_THROW(bessel_j_backwards_iterator(-2.3, 5.0, 2.0), std::domain_error); + BOOST_CHECK_THROW(bessel_j_backwards_iterator(-2.3, 5.0, 2.0, 2.0), std::domain_error); + + double tolerance = std::numeric_limits::epsilon() * 5; + + { + bessel_j_backwards_iterator i(12, 2.0); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_j(8, 2.0), tolerance); + } + { + bessel_j_backwards_iterator i(12, 2.0, boost::math::cyl_bessel_j(12, 2.0)); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_j(8, 2.0), tolerance); + } + { + bessel_j_backwards_iterator i(12, 2.0, boost::math::cyl_bessel_j(13, 2.0), boost::math::cyl_bessel_j(12, 2.0)); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_j(8, 2.0), tolerance); + } + + { + bessel_i_backwards_iterator i(12, 2.0); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_i(8, 2.0), tolerance); + } + { + bessel_i_backwards_iterator i(12, 2.0, boost::math::cyl_bessel_i(12, 2.0)); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_i(8, 2.0), tolerance); + } + { + bessel_i_backwards_iterator i(12, 2.0, boost::math::cyl_bessel_i(13, 2.0), boost::math::cyl_bessel_i(12, 2.0)); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_i(8, 2.0), tolerance); + } + + { + bessel_i_forwards_iterator i(-12, 2.0); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_i(-8, 2.0), tolerance); + } + { + bessel_i_forwards_iterator i(-12, 2.0, boost::math::cyl_bessel_i(-12, 2.0)); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_i(-8, 2.0), tolerance); + } + { + bessel_i_forwards_iterator i(-12, 2.0, boost::math::cyl_bessel_i(-13, 2.0), boost::math::cyl_bessel_i(-12, 2.0)); + for (unsigned j = 0; j < 4; ++j) + ++i; + BOOST_CHECK_CLOSE_FRACTION(*i, boost::math::cyl_bessel_i(-8, 2.0), tolerance); + } +} diff --git a/test/condition_number_test.cpp b/test/condition_number_test.cpp index 5bd89eee1..508b92438 100644 --- a/test/condition_number_test.cpp +++ b/test/condition_number_test.cpp @@ -7,6 +7,9 @@ #include "math_unit_test.hpp" #include #include +#if !defined(TEST) || (TEST > 1) +#include +#endif using std::abs; using std::log;