1
// Copyright (c) 2006 Xiaogang Zhang
2
// Use, modification and distribution are subject to the
3
// Boost Software License, Version 1.0. (See accompanying file
4
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
#ifndef BOOST_MATH_BESSEL_YN_HPP
7
#define BOOST_MATH_BESSEL_YN_HPP
13
#include <boost/math/special_functions/detail/bessel_y0.hpp>
14
#include <boost/math/special_functions/detail/bessel_y1.hpp>
15
#include <boost/math/policies/error_handling.hpp>
17
// Bessel function of the second kind of integer order
18
// Y_n(z) is the dominant solution, forward recurrence always OK (though unstable)
20
namespace boost { namespace math { namespace detail{
22
template <typename T, typename Policy>
23
T bessel_yn(int n, T x, const Policy& pol)
25
T value, factor, current, prev;
27
using namespace boost::math::tools;
29
static const char* function = "boost::math::bessel_yn<%1%>(%1%,%1%)";
31
if ((x == 0) && (n == 0))
33
return -policies::raise_overflow_error<T>(function, 0, pol);
37
return policies::raise_domain_error<T>(function,
38
"Got x = %1%, but x must be > 0, complex result not supported.", x, pol);
42
// Reflection comes first:
46
factor = (n & 0x1) ? -1 : 1; // Y_{-n}(z) = (-1)^n Y_n(z)
56
value = bessel_y0(x, pol);
60
value = factor * bessel_y1(x, pol);
64
prev = bessel_y0(x, pol);
65
current = bessel_y1(x, pol);
70
value = 2 * k * current / x - prev;
83
#endif // BOOST_MATH_BESSEL_YN_HPP