Back to home page

EIC code displayed by LXR

 
 

    


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

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_Y0_HPP
0007 #define BOOST_MATH_BESSEL_Y0_HPP
0008 
0009 #ifdef _MSC_VER
0010 #pragma once
0011 #pragma warning(push)
0012 #pragma warning(disable:4702) // Unreachable code (release mode only warning)
0013 #endif
0014 
0015 #include <boost/math/special_functions/detail/bessel_j0.hpp>
0016 #include <boost/math/constants/constants.hpp>
0017 #include <boost/math/tools/rational.hpp>
0018 #include <boost/math/tools/big_constant.hpp>
0019 #include <boost/math/policies/error_handling.hpp>
0020 #include <boost/math/tools/assert.hpp>
0021 
0022 #if defined(__GNUC__) && defined(BOOST_MATH_USE_FLOAT128)
0023 //
0024 // This is the only way we can avoid
0025 // warning: non-standard suffix on floating constant [-Wpedantic]
0026 // when building with -Wall -pedantic.  Neither __extension__
0027 // nor #pragma diagnostic ignored work :(
0028 //
0029 #pragma GCC system_header
0030 #endif
0031 
0032 // Bessel function of the second kind of order zero
0033 // x <= 8, minimax rational approximations on root-bracketing intervals
0034 // x > 8, Hankel asymptotic expansion in Hart, Computer Approximations, 1968
0035 
0036 namespace boost { namespace math { namespace detail{
0037 
0038 template <typename T, typename Policy>
0039 T bessel_y0(T x, const Policy&);
0040 
0041 template <class T, class Policy>
0042 struct bessel_y0_initializer
0043 {
0044    struct init
0045    {
0046       init()
0047       {
0048          do_init();
0049       }
0050       static void do_init()
0051       {
0052          bessel_y0(T(1), Policy());
0053       }
0054       void force_instantiate()const{}
0055    };
0056    static const init initializer;
0057    static void force_instantiate()
0058    {
0059       initializer.force_instantiate();
0060    }
0061 };
0062 
0063 template <class T, class Policy>
0064 const typename bessel_y0_initializer<T, Policy>::init bessel_y0_initializer<T, Policy>::initializer;
0065 
0066 template <typename T, typename Policy>
0067 T bessel_y0(T x, const Policy& pol)
0068 {
0069     bessel_y0_initializer<T, Policy>::force_instantiate();
0070 
0071     static const T P1[] = {
0072          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0723538782003176831e+11)),
0073         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -8.3716255451260504098e+09)),
0074          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.0422274357376619816e+08)),
0075         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -2.1287548474401797963e+06)),
0076          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0102532948020907590e+04)),
0077         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.8402381979244993524e+01)),
0078     };
0079     static const T Q1[] = {
0080          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 5.8873865738997033405e+11)),
0081          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 8.1617187777290363573e+09)),
0082          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 5.5662956624278251596e+07)),
0083          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.3889393209447253406e+05)),
0084          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 6.6475986689240190091e+02)),
0085          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0)),
0086     };
0087     static const T P2[] = {
0088         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -2.2213976967566192242e+13)),
0089         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -5.5107435206722644429e+11)),
0090          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.3600098638603061642e+10)),
0091         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -6.9590439394619619534e+08)),
0092          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.6905288611678631510e+06)),
0093         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.4566865832663635920e+04)),
0094          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.7427031242901594547e+01)),
0095     };
0096     static const T Q2[] = {
0097          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.3386146580707264428e+14)),
0098          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 5.4266824419412347550e+12)),
0099          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.4015103849971240096e+10)),
0100          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.3960202770986831075e+08)),
0101          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.0669982352539552018e+05)),
0102          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 8.3030857612070288823e+02)),
0103          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0)),
0104     };
0105     static const T P3[] = {
0106         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -8.0728726905150210443e+15)),
0107          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 6.7016641869173237784e+14)),
0108         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.2829912364088687306e+11)),
0109         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.9363051266772083678e+11)),
0110          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.1958827170518100757e+09)),
0111         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.0085539923498211426e+07)),
0112          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.1363534169313901632e+04)),
0113         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.7439661319197499338e+01)),
0114     };
0115     static const T Q3[] = {
0116          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.4563724628846457519e+17)),
0117          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.9272425569640309819e+15)),
0118          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.2598377924042897629e+13)),
0119          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 8.6926121104209825246e+10)),
0120          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.4727219475672302327e+08)),
0121          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 5.3924739209768057030e+05)),
0122          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 8.7903362168128450017e+02)),
0123          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0)),
0124     };
0125     static const T PC[] = {
0126          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.2779090197304684302e+04)),
0127          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.1345386639580765797e+04)),
0128          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.1170523380864944322e+04)),
0129          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.4806486443249270347e+03)),
0130          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.5376201909008354296e+02)),
0131          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 8.8961548424210455236e-01)),
0132     };
0133     static const T QC[] = {
0134          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.2779090197304684318e+04)),
0135          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.1370412495510416640e+04)),
0136          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.1215350561880115730e+04)),
0137          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.5028735138235608207e+03)),
0138          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.5711159858080893649e+02)),
0139          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0)),
0140     };
0141     static const T PS[] = {
0142         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -8.9226600200800094098e+01)),
0143         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.8591953644342993800e+02)),
0144         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.1183429920482737611e+02)),
0145         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -2.2300261666214198472e+01)),
0146         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.2441026745835638459e+00)),
0147         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -8.8033303048680751817e-03)),
0148     };
0149     static const T QS[] = {
0150          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 5.7105024128512061905e+03)),
0151          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.1951131543434613647e+04)),
0152          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 7.2642780169211018836e+03)),
0153          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.4887231232283756582e+03)),
0154          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 9.0593769594993125859e+01)),
0155          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0)),
0156     };
0157     static const T x1  =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 8.9357696627916752158e-01)),
0158                    x2  =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.9576784193148578684e+00)),
0159                    x3  =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 7.0860510603017726976e+00)),
0160                    x11 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.280e+02)),
0161                    x12 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.9519662791675215849e-03)),
0162                    x21 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0130e+03)),
0163                    x22 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 6.4716931485786837568e-04)),
0164                    x31 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.8140e+03)),
0165                    x32 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.1356030177269762362e-04))
0166     ;
0167     T value, factor, r, rc, rs;
0168 
0169     BOOST_MATH_STD_USING
0170     using namespace boost::math::tools;
0171     using namespace boost::math::constants;
0172 
0173     static const char* function = "boost::math::bessel_y0<%1%>(%1%,%1%)";
0174 
0175     if (x < 0)
0176     {
0177        return policies::raise_domain_error<T>(function,
0178             "Got x = %1% but x must be non-negative, complex result not supported.", x, pol);
0179     }
0180     if (x == 0)
0181     {
0182        return -policies::raise_overflow_error<T>(function, nullptr, pol);
0183     }
0184     if (x <= 3)                       // x in (0, 3]
0185     {
0186         T y = x * x;
0187         T z = 2 * log(x/x1) * bessel_j0(x) / pi<T>();
0188         r = evaluate_rational(P1, Q1, y);
0189         factor = (x + x1) * ((x - x11/256) - x12);
0190         value = z + factor * r;
0191     }
0192     else if (x <= 5.5f)                  // x in (3, 5.5]
0193     {
0194         T y = x * x;
0195         T z = 2 * log(x/x2) * bessel_j0(x) / pi<T>();
0196         r = evaluate_rational(P2, Q2, y);
0197         factor = (x + x2) * ((x - x21/256) - x22);
0198         value = z + factor * r;
0199     }
0200     else if (x <= 8)                  // x in (5.5, 8]
0201     {
0202         T y = x * x;
0203         T z = 2 * log(x/x3) * bessel_j0(x) / pi<T>();
0204         r = evaluate_rational(P3, Q3, y);
0205         factor = (x + x3) * ((x - x31/256) - x32);
0206         value = z + factor * r;
0207     }
0208     else                                // x in (8, \infty)
0209     {
0210         T y = 8 / x;
0211         T y2 = y * y;
0212         rc = evaluate_rational(PC, QC, y2);
0213         rs = evaluate_rational(PS, QS, y2);
0214         factor = constants::one_div_root_pi<T>() / sqrt(x);
0215         //
0216         // The following code is really just:
0217         //
0218         // T z = x - 0.25f * pi<T>();
0219         // value = factor * (rc * sin(z) + y * rs * cos(z));
0220         //
0221         // But using the sin/cos addition formulae and constant values for
0222         // sin/cos of PI/4 which then cancel part of the "factor" term as they're all
0223         // 1 / sqrt(2):
0224         //
0225         T sx = sin(x);
0226         T cx = cos(x);
0227         value = factor * (rc * (sx - cx) + y * rs * (cx + sx));
0228     }
0229 
0230     return value;
0231 }
0232 
0233 }}} // namespaces
0234 
0235 #ifdef _MSC_VER
0236 #pragma warning(pop)
0237 #endif
0238 
0239 #endif // BOOST_MATH_BESSEL_Y0_HPP
0240