Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:59

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_J0_HPP
0007 #define BOOST_MATH_BESSEL_J0_HPP
0008 
0009 #ifdef _MSC_VER
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/math/constants/constants.hpp>
0014 #include <boost/math/tools/rational.hpp>
0015 #include <boost/math/tools/big_constant.hpp>
0016 #include <boost/math/tools/assert.hpp>
0017 
0018 #if defined(__GNUC__) && defined(BOOST_MATH_USE_FLOAT128)
0019 //
0020 // This is the only way we can avoid
0021 // warning: non-standard suffix on floating constant [-Wpedantic]
0022 // when building with -Wall -pedantic.  Neither __extension__
0023 // nor #pragma diagnostic ignored work :(
0024 //
0025 #pragma GCC system_header
0026 #endif
0027 
0028 // Bessel function of the first kind of order zero
0029 // x <= 8, minimax rational approximations on root-bracketing intervals
0030 // x > 8, Hankel asymptotic expansion in Hart, Computer Approximations, 1968
0031 
0032 namespace boost { namespace math { namespace detail{
0033 
0034 template <typename T>
0035 T bessel_j0(T x);
0036 
0037 template <class T>
0038 struct bessel_j0_initializer
0039 {
0040    struct init
0041    {
0042       init()
0043       {
0044          do_init();
0045       }
0046       static void do_init()
0047       {
0048          bessel_j0(T(1));
0049       }
0050       void force_instantiate()const{}
0051    };
0052    static const init initializer;
0053    static void force_instantiate()
0054    {
0055       initializer.force_instantiate();
0056    }
0057 };
0058 
0059 template <class T>
0060 const typename bessel_j0_initializer<T>::init bessel_j0_initializer<T>::initializer;
0061 
0062 template <typename T>
0063 T bessel_j0(T x)
0064 {
0065     bessel_j0_initializer<T>::force_instantiate();
0066     
0067 #ifdef BOOST_MATH_INSTRUMENT
0068     static bool b = false;
0069     if (!b)
0070     {
0071        std::cout << "bessel_j0 called with " << typeid(x).name() << std::endl;
0072        std::cout << "double      = " << typeid(double).name() << std::endl;
0073        std::cout << "long double = " << typeid(long double).name() << std::endl;
0074        b = true;
0075     }
0076 #endif
0077 
0078     static const T P1[] = {
0079          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -4.1298668500990866786e+11)),
0080          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.7282507878605942706e+10)),
0081          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -6.2140700423540120665e+08)),
0082          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 6.6302997904833794242e+06)),
0083          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -3.6629814655107086448e+04)),
0084          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0344222815443188943e+02)),
0085          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.2117036164593528341e-01))
0086     };
0087     static const T Q1[] = {
0088          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.3883787996332290397e+12)),
0089          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.6328198300859648632e+10)),
0090          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.3985097372263433271e+08)),
0091          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.5612696224219938200e+05)),
0092          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 9.3614022392337710626e+02)),
0093          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0)),
0094          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 0.0))
0095     };
0096     static const T P2[] = {
0097          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.8319397969392084011e+03)),
0098          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.2254078161378989535e+04)),
0099          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -7.2879702464464618998e+03)),
0100          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0341910641583726701e+04)),
0101          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.1725046279757103576e+04)),
0102          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.4176707025325087628e+03)),
0103          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 7.4321196680624245801e+02)),
0104          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.8591703355916499363e+01))
0105     };
0106     static const T Q2[] = {
0107          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -3.5783478026152301072e+05)),
0108          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.4599102262586308984e+05)),
0109          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -8.4055062591169562211e+04)),
0110          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.8680990008359188352e+04)),
0111          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -2.9458766545509337327e+03)),
0112          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.3307310774649071172e+02)),
0113          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -2.5258076240801555057e+01)),
0114          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0))
0115     };
0116     static const T PC[] = {
0117          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.2779090197304684302e+04)),
0118          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.1345386639580765797e+04)),
0119          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.1170523380864944322e+04)),
0120          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.4806486443249270347e+03)),
0121          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.5376201909008354296e+02)),
0122          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 8.8961548424210455236e-01))
0123     };
0124     static const T QC[] = {
0125          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.2779090197304684318e+04)),
0126          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 4.1370412495510416640e+04)),
0127          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.1215350561880115730e+04)),
0128          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 3.5028735138235608207e+03)),
0129          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.5711159858080893649e+02)),
0130          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0))
0131     };
0132     static const T PS[] = {
0133         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -8.9226600200800094098e+01)),
0134         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.8591953644342993800e+02)),
0135         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.1183429920482737611e+02)),
0136         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -2.2300261666214198472e+01)),
0137         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.2441026745835638459e+00)),
0138         static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -8.8033303048680751817e-03))
0139     };
0140     static const T QS[] = {
0141          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 5.7105024128512061905e+03)),
0142          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.1951131543434613647e+04)),
0143          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 7.2642780169211018836e+03)),
0144          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.4887231232283756582e+03)),
0145          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 9.0593769594993125859e+01)),
0146          static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.0))
0147     };
0148     static const T x1  =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.4048255576957727686e+00)),
0149                    x2  =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 5.5200781102863106496e+00)),
0150                    x11 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 6.160e+02)),
0151                    x12 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, -1.42444230422723137837e-03)),
0152                    x21 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 1.4130e+03)),
0153                    x22 =  static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 5.46860286310649596604e-04));
0154 
0155     T value, factor, r, rc, rs;
0156 
0157     BOOST_MATH_STD_USING
0158     using namespace boost::math::tools;
0159     using namespace boost::math::constants;
0160 
0161     if (x < 0)
0162     {
0163         x = -x;                         // even function
0164     }
0165     if (x == 0)
0166     {
0167         return static_cast<T>(1);
0168     }
0169     if (x <= 4)                       // x in (0, 4]
0170     {
0171         T y = x * x;
0172         BOOST_MATH_ASSERT(sizeof(P1) == sizeof(Q1));
0173         r = evaluate_rational(P1, Q1, y);
0174         factor = (x + x1) * ((x - x11/256) - x12);
0175         value = factor * r;
0176     }
0177     else if (x <= 8.0)                  // x in (4, 8]
0178     {
0179         T y = 1 - (x * x)/64;
0180         BOOST_MATH_ASSERT(sizeof(P2) == sizeof(Q2));
0181         r = evaluate_rational(P2, Q2, y);
0182         factor = (x + x2) * ((x - x21/256) - x22);
0183         value = factor * r;
0184     }
0185     else                                // x in (8, \infty)
0186     {
0187         T y = 8 / x;
0188         T y2 = y * y;
0189         BOOST_MATH_ASSERT(sizeof(PC) == sizeof(QC));
0190         BOOST_MATH_ASSERT(sizeof(PS) == sizeof(QS));
0191         rc = evaluate_rational(PC, QC, y2);
0192         rs = evaluate_rational(PS, QS, y2);
0193         factor = constants::one_div_root_pi<T>() / sqrt(x);
0194         //
0195         // What follows is really just:
0196         //
0197         // T z = x - pi/4;
0198         // value = factor * (rc * cos(z) - y * rs * sin(z));
0199         //
0200         // But using the addition formulae for sin and cos, plus
0201         // the special values for sin/cos of pi/4.
0202         //
0203         T sx = sin(x);
0204         T cx = cos(x);
0205         BOOST_MATH_INSTRUMENT_VARIABLE(rc);
0206         BOOST_MATH_INSTRUMENT_VARIABLE(rs);
0207         BOOST_MATH_INSTRUMENT_VARIABLE(factor);
0208         BOOST_MATH_INSTRUMENT_VARIABLE(sx);
0209         BOOST_MATH_INSTRUMENT_VARIABLE(cx);
0210         value = factor * (rc * (cx + sx) - y * rs * (sx - cx));
0211     }
0212 
0213     return value;
0214 }
0215 
0216 }}} // namespaces
0217 
0218 #endif // BOOST_MATH_BESSEL_J0_HPP
0219