Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:01

0001 //  Copyright (c) 2006 Xiaogang Zhang
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_MATH_BESSEL_YN_HPP
0007 #define BOOST_MATH_BESSEL_YN_HPP
0008 
0009 #ifdef _MSC_VER
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/math/special_functions/detail/bessel_y0.hpp>
0014 #include <boost/math/special_functions/detail/bessel_y1.hpp>
0015 #include <boost/math/special_functions/detail/bessel_jy_series.hpp>
0016 #include <boost/math/policies/error_handling.hpp>
0017 
0018 // Bessel function of the second kind of integer order
0019 // Y_n(z) is the dominant solution, forward recurrence always OK (though unstable)
0020 
0021 namespace boost { namespace math { namespace detail{
0022 
0023 template <typename T, typename Policy>
0024 T bessel_yn(int n, T x, const Policy& pol)
0025 {
0026     BOOST_MATH_STD_USING
0027     T value, factor, current, prev;
0028 
0029     using namespace boost::math::tools;
0030 
0031     static const char* function = "boost::math::bessel_yn<%1%>(%1%,%1%)";
0032 
0033     if ((x == 0) && (n == 0))
0034     {
0035        return -policies::raise_overflow_error<T>(function, nullptr, pol);
0036     }
0037     if (x <= 0)
0038     {
0039        return policies::raise_domain_error<T>(function,
0040             "Got x = %1%, but x must be > 0, complex result not supported.", x, pol);
0041     }
0042 
0043     //
0044     // Reflection comes first:
0045     //
0046     if (n < 0)
0047     {
0048         factor = static_cast<T>((n & 0x1) ? -1 : 1);  // Y_{-n}(z) = (-1)^n Y_n(z)
0049         n = -n;
0050     }
0051     else
0052     {
0053         factor = 1;
0054     }
0055     if(x < policies::get_epsilon<T, Policy>())
0056     {
0057        T scale = 1;
0058        value = bessel_yn_small_z(n, x, &scale, pol);
0059        if(tools::max_value<T>() * fabs(scale) < fabs(value))
0060           return boost::math::sign(scale) * boost::math::sign(value) * policies::raise_overflow_error<T>(function, nullptr, pol);
0061        value /= scale;
0062     }
0063     else if(asymptotic_bessel_large_x_limit(n, x))
0064     {
0065        value = factor * asymptotic_bessel_y_large_x_2(static_cast<T>(abs(n)), x, pol);
0066     }
0067     else if (n == 0)
0068     {
0069         value = bessel_y0(x, pol);
0070     }
0071     else if (n == 1)
0072     {
0073         value = factor * bessel_y1(x, pol);
0074     }
0075     else
0076     {
0077        prev = bessel_y0(x, pol);
0078        current = bessel_y1(x, pol);
0079        int k = 1;
0080        BOOST_MATH_ASSERT(k < n);
0081        policies::check_series_iterations<T>("boost::math::bessel_y_n<%1%>(%1%,%1%)", n, pol);
0082        T mult = 2 * k / x;
0083        value = mult * current - prev;
0084        prev = current;
0085        current = value;
0086        ++k;
0087        if((mult > 1) && (fabs(current) > 1))
0088        {
0089           prev /= current;
0090           factor /= current;
0091           value /= current;
0092           current = 1;
0093        }
0094        while(k < n)
0095        {
0096            mult = 2 * k / x;
0097            value = mult * current - prev;
0098            prev = current;
0099            current = value;
0100            ++k;
0101        }
0102        if(fabs(tools::max_value<T>() * factor) < fabs(value))
0103           return sign(value) * sign(factor) * policies::raise_overflow_error<T>(function, nullptr, pol);
0104        value /= factor;
0105     }
0106     return value;
0107 }
0108 
0109 }}} // namespaces
0110 
0111 #endif // BOOST_MATH_BESSEL_YN_HPP
0112