47 #ifndef _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC
48 #define _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC 1
79 template <
typename _Tp>
82 _Tp & __Inu, _Tp & __Knu, _Tp & __Ipnu, _Tp & __Kpnu)
91 else if (__nu == _Tp(1))
108 const int __max_iter = 15000;
109 const _Tp __x_min = _Tp(2);
111 const int __nl =
static_cast<int>(__nu + _Tp(0.5L));
113 const _Tp __mu = __nu - __nl;
114 const _Tp __mu2 = __mu * __mu;
115 const _Tp __xi = _Tp(1) / __x;
116 const _Tp __xi2 = _Tp(2) * __xi;
117 _Tp __h = __nu * __xi;
118 if ( __h < __fp_min )
120 _Tp __b = __xi2 * __nu;
124 for ( __i = 1; __i <= __max_iter; ++__i )
127 __d = _Tp(1) / (__b + __d);
128 __c = __b + _Tp(1) / __c;
129 const _Tp __del = __c * __d;
131 if (
std::abs(__del - _Tp(1)) < __eps)
134 if (__i > __max_iter)
135 std::__throw_runtime_error(__N(
"Argument x too large "
137 "try asymptotic expansion."));
138 _Tp __Inul = __fp_min;
139 _Tp __Ipnul = __h * __Inul;
140 _Tp __Inul1 = __Inul;
141 _Tp __Ipnu1 = __Ipnul;
142 _Tp __fact = __nu * __xi;
143 for (
int __l = __nl; __l >= 1; --__l)
145 const _Tp __Inutemp = __fact * __Inul + __Ipnul;
147 __Ipnul = __fact * __Inutemp + __Inul;
150 _Tp __f = __Ipnul / __Inul;
154 const _Tp __x2 = __x / _Tp(2);
156 const _Tp __fact = (
std::abs(__pimu) < __eps
157 ? _Tp(1) : __pimu /
std::sin(__pimu));
159 _Tp __e = __mu * __d;
160 const _Tp __fact2 = (
std::abs(__e) < __eps
162 _Tp __gam1, __gam2, __gampl, __gammi;
165 * (__gam1 *
std::cosh(__e) + __gam2 * __fact2 * __d);
168 _Tp __p = __e / (_Tp(2) * __gampl);
169 _Tp __q = _Tp(1) / (_Tp(2) * __e * __gammi);
174 for (__i = 1; __i <= __max_iter; ++__i)
176 __ff = (__i * __ff + __p + __q) / (__i * __i - __mu2);
180 const _Tp __del = __c * __ff;
182 const _Tp __del1 = __c * (__p - __i * __ff);
187 if (__i > __max_iter)
188 std::__throw_runtime_error(__N(
"Bessel k series failed to converge "
191 __Knu1 = __sum1 * __xi2;
195 _Tp __b = _Tp(2) * (_Tp(1) + __x);
196 _Tp __d = _Tp(1) / __b;
201 _Tp __a1 = _Tp(0.25L) - __mu2;
202 _Tp __q = __c = __a1;
204 _Tp __s = _Tp(1) + __q * __delh;
206 for (__i = 2; __i <= __max_iter; ++__i)
208 __a -= 2 * (__i - 1);
209 __c = -__a * __c / __i;
210 const _Tp __qnew = (__q1 - __b * __q2) / __a;
215 __d = _Tp(1) / (__b + __a * __d);
216 __delh = (__b * __d - _Tp(1)) * __delh;
218 const _Tp __dels = __q * __delh;
220 if (
std::abs(__dels / __s) < __eps )
223 if (__i > __max_iter)
224 std::__throw_runtime_error(__N(
"Steed's method failed "
229 __Knu1 = __Kmu * (__mu + __x + _Tp(0.5L) - __h) * __xi;
232 _Tp __Kpmu = __mu * __xi * __Kmu - __Knu1;
233 _Tp __Inumu = __xi / (__f * __Kmu - __Kpmu);
234 __Inu = __Inumu * __Inul1 / __Inul;
235 __Ipnu = __Inumu * __Ipnu1 / __Inul;
236 for ( __i = 1; __i <= __nl; ++__i )
238 const _Tp __Knutemp = (__mu + __i) * __xi2 * __Knu1 + __Kmu;
243 __Kpnu = __nu * __xi * __Kmu - __Knu1;
263 template<
typename _Tp>
267 if (__nu < _Tp(0) || __x < _Tp(0))
268 std::__throw_domain_error(__N(
"Bad argument "
269 "in __cyl_bessel_i."));
270 else if (__isnan(__nu) || __isnan(__x))
272 else if (__x * __x < _Tp(10) * (__nu + _Tp(1)))
276 _Tp __I_nu, __K_nu, __Ip_nu, __Kp_nu;
277 __bessel_ik(__nu, __x, __I_nu, __K_nu, __Ip_nu, __Kp_nu);
299 template<
typename _Tp>
303 if (__nu < _Tp(0) || __x < _Tp(0))
304 std::__throw_domain_error(__N(
"Bad argument "
305 "in __cyl_bessel_k."));
306 else if (__isnan(__nu) || __isnan(__x))
310 _Tp __I_nu, __K_nu, __Ip_nu, __Kp_nu;
311 __bessel_ik(__nu, __x, __I_nu, __K_nu, __Ip_nu, __Kp_nu);
333 template <
typename _Tp>
336 _Tp & __i_n, _Tp & __k_n, _Tp & __ip_n, _Tp & __kp_n)
338 const _Tp __nu = _Tp(__n) + _Tp(0.5L);
340 _Tp __I_nu, __Ip_nu, __K_nu, __Kp_nu;
341 __bessel_ik(__nu, __x, __I_nu, __K_nu, __Ip_nu, __Kp_nu);
346 __i_n = __factor * __I_nu;
347 __k_n = __factor * __K_nu;
348 __ip_n = __factor * __Ip_nu - __i_n / (_Tp(2) * __x);
349 __kp_n = __factor * __Kp_nu - __k_n / (_Tp(2) * __x);
368 template <
typename _Tp>
371 _Tp & __Ai, _Tp & __Bi, _Tp & __Aip, _Tp & __Bip)
375 const _Tp __z = _Tp(2) * __absx * __rootx / _Tp(3);
379 else if (__x > _Tp(0))
381 _Tp __I_nu, __Ip_nu, __K_nu, __Kp_nu;
383 __bessel_ik(_Tp(1) / _Tp(3), __z, __I_nu, __K_nu, __Ip_nu, __Kp_nu);
384 __Ai = __rootx * __K_nu
390 __bessel_ik(_Tp(2) / _Tp(3), __z, __I_nu, __K_nu, __Ip_nu, __Kp_nu);
391 __Aip = -__x * __K_nu
398 else if (__x < _Tp(0))
400 _Tp __J_nu, __Jp_nu, __N_nu, __Np_nu;
402 __bessel_jn(_Tp(1) / _Tp(3), __z, __J_nu, __N_nu, __Jp_nu, __Np_nu);
403 __Ai = __rootx * (__J_nu
405 __Bi = -__rootx * (__N_nu
408 __bessel_jn(_Tp(2) / _Tp(3), __z, __J_nu, __N_nu, __Jp_nu, __Np_nu);
419 __Ai = _Tp(0.35502805388781723926L);
425 __Aip = -_Tp(0.25881940379280679840L);
436 #endif // _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC
_Tp __cyl_bessel_ij_series(const _Tp __nu, const _Tp __x, const _Tp __sgn, const unsigned int __max_iter)
This routine returns the cylindrical Bessel functions of order : or by series expansion.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
A structure for numeric constants.
_Tp __cyl_bessel_i(const _Tp __nu, const _Tp __x)
Return the regular modified Bessel function of order : .
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
void __gamma_temme(const _Tp __mu, _Tp &__gam1, _Tp &__gam2, _Tp &__gampl, _Tp &__gammi)
Compute the gamma functions required by the Temme series expansions of and . and where is and ...
void __airy(const _Tp __x, _Tp &__Ai, _Tp &__Bi, _Tp &__Aip, _Tp &__Bip)
Compute the Airy functions and and their first derivatives and respectively.
complex< _Tp > sinh(const complex< _Tp > &)
Return complex hyperbolic sine of z.
static _Tp __sqrt3()
Constant .
complex< _Tp > cosh(const complex< _Tp > &)
Return complex hyperbolic cosine of z.
complex< _Tp > sin(const complex< _Tp > &)
Return complex sine of z.
_Tp __cyl_bessel_k(const _Tp __nu, const _Tp __x)
Return the irregular modified Bessel function of order .
void __bessel_jn(const _Tp __nu, const _Tp __x, _Tp &__Jnu, _Tp &__Nnu, _Tp &__Jpnu, _Tp &__Npnu)
Compute the Bessel and Neumann functions and their first derivatives and respectively. These four functions are computed together for numerical stability.
void __bessel_ik(const _Tp __nu, const _Tp __x, _Tp &__Inu, _Tp &__Knu, _Tp &__Ipnu, _Tp &__Kpnu)
Compute the modified Bessel functions and and their first derivatives and respectively. These four functions are computed together for numerical stability.
static _Tp __pi()
Constant .
static _Tp __sqrtpio2()
Constant .
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
void __sph_bessel_ik(const unsigned int __n, const _Tp __x, _Tp &__i_n, _Tp &__k_n, _Tp &__ip_n, _Tp &__kp_n)
Compute the spherical modified Bessel functions and and their first derivatives and respectively...
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.