2 ///////////////////////////////////////////////////////////////////////////////
3 // Copyright 2018 John Maddock
4 // Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_MATH_BESSEL_ITERATORS_HPP
9 #define BOOST_MATH_BESSEL_ITERATORS_HPP
11 #include <boost/math/tools/recurrence.hpp>
18 struct bessel_jy_recurrence
20 bessel_jy_recurrence(T v, T z) : v(v), z(z) {}
21 boost::math::tuple<T, T, T> operator()(int k)
23 return boost::math::tuple<T, T, T>(1, -2 * (v + k) / z, 1);
29 struct bessel_ik_recurrence
31 bessel_ik_recurrence(T v, T z) : v(v), z(z) {}
32 boost::math::tuple<T, T, T> operator()(int k)
34 return boost::math::tuple<T, T, T>(1, -2 * (v + k) / z, -1);
42 struct bessel_j_backwards_iterator
44 typedef std::ptrdiff_t difference_type;
48 typedef std::input_iterator_tag iterator_category;
50 bessel_j_backwards_iterator(const T& v, const T& x)
51 : it(detail::bessel_jy_recurrence<T>(v, x), boost::math::cyl_bessel_j(v, x))
54 boost::math::policies::raise_domain_error("bessel_j_backwards_iterator<%1%>", "Order must be > 0 stable backwards recurrence but got %1%", v, boost::math::policies::policy<>());
57 bessel_j_backwards_iterator(const T& v, const T& x, const T& J_v)
58 : it(detail::bessel_jy_recurrence<T>(v, x), J_v)
61 boost::math::policies::raise_domain_error("bessel_j_backwards_iterator<%1%>", "Order must be > 0 stable backwards recurrence but got %1%", v, boost::math::policies::policy<>());
63 bessel_j_backwards_iterator(const T& v, const T& x, const T& J_v_plus_1, const T& J_v)
64 : it(detail::bessel_jy_recurrence<T>(v, x), J_v_plus_1, J_v)
67 boost::math::policies::raise_domain_error("bessel_j_backwards_iterator<%1%>", "Order must be > 0 stable backwards recurrence but got %1%", v, boost::math::policies::policy<>());
70 bessel_j_backwards_iterator& operator++()
76 bessel_j_backwards_iterator operator++(int)
78 bessel_j_backwards_iterator t(*this);
83 T operator*() { return *it; }
86 boost::math::tools::backward_recurrence_iterator< detail::bessel_jy_recurrence<T> > it;
90 struct bessel_i_backwards_iterator
92 typedef std::ptrdiff_t difference_type;
96 typedef std::input_iterator_tag iterator_category;
98 bessel_i_backwards_iterator(const T& v, const T& x)
99 : it(detail::bessel_ik_recurrence<T>(v, x), boost::math::cyl_bessel_i(v, x))
102 boost::math::policies::raise_domain_error("bessel_i_backwards_iterator<%1%>", "Order must be > 0 stable backwards recurrence but got %1%", v, boost::math::policies::policy<>());
104 bessel_i_backwards_iterator(const T& v, const T& x, const T& I_v)
105 : it(detail::bessel_ik_recurrence<T>(v, x), I_v)
108 boost::math::policies::raise_domain_error("bessel_i_backwards_iterator<%1%>", "Order must be > 0 stable backwards recurrence but got %1%", v, boost::math::policies::policy<>());
110 bessel_i_backwards_iterator(const T& v, const T& x, const T& I_v_plus_1, const T& I_v)
111 : it(detail::bessel_ik_recurrence<T>(v, x), I_v_plus_1, I_v)
114 boost::math::policies::raise_domain_error("bessel_i_backwards_iterator<%1%>", "Order must be > 0 stable backwards recurrence but got %1%", v, boost::math::policies::policy<>());
117 bessel_i_backwards_iterator& operator++()
123 bessel_i_backwards_iterator operator++(int)
125 bessel_i_backwards_iterator t(*this);
130 T operator*() { return *it; }
133 boost::math::tools::backward_recurrence_iterator< detail::bessel_ik_recurrence<T> > it;
137 struct bessel_i_forwards_iterator
139 typedef std::ptrdiff_t difference_type;
140 typedef T value_type;
142 typedef T& reference;
143 typedef std::input_iterator_tag iterator_category;
145 bessel_i_forwards_iterator(const T& v, const T& x)
146 : it(detail::bessel_ik_recurrence<T>(v, x), boost::math::cyl_bessel_i(v, x))
149 boost::math::policies::raise_domain_error("bessel_i_forwards_iterator<%1%>", "Order must be < 0 stable forwards recurrence but got %1%", v, boost::math::policies::policy<>());
151 bessel_i_forwards_iterator(const T& v, const T& x, const T& I_v)
152 : it(detail::bessel_ik_recurrence<T>(v, x), I_v)
155 boost::math::policies::raise_domain_error("bessel_i_forwards_iterator<%1%>", "Order must be < 0 stable forwards recurrence but got %1%", v, boost::math::policies::policy<>());
157 bessel_i_forwards_iterator(const T& v, const T& x, const T& I_v_plus_1, const T& I_v)
158 : it(detail::bessel_ik_recurrence<T>(v, x), I_v_plus_1, I_v)
161 boost::math::policies::raise_domain_error("bessel_i_forwards_iterator<%1%>", "Order must be < 0 stable forwards recurrence but got %1%", v, boost::math::policies::policy<>());
164 bessel_i_forwards_iterator& operator++()
170 bessel_i_forwards_iterator operator++(int)
172 bessel_i_forwards_iterator t(*this);
177 T operator*() { return *it; }
180 boost::math::tools::forward_recurrence_iterator< detail::bessel_ik_recurrence<T> > it;
186 #endif // BOOST_MATH_BESSEL_ITERATORS_HPP