ractions. * * The exponential integral is given by * \f[ * E_n(x) = \int_{1}^\infty \frac{e^{-xt}}{t^n} dt * \f] * * @param __n The order of the exponential integral function. * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint_En_cont_frac(const unsigned int __n, const _Tp __x) { const unsigned int __max_iter = 100; const _Tp __eps = std::numeric_limits<_Tp>::epsilon(); const _Tp __fp_min = std::numeric_limits<_Tp>::min(); const int __nm1 = __n - 1; _Tp __b = __x + _Tp(__n); _Tp __c = _Tp(1) / __fp_min; _Tp __d = _Tp(1) / __b; _Tp __h = __d; for ( unsigned int __i = 1; __i <= __max_iter; ++__i ) { _Tp __a = -_Tp(__i * (__nm1 + __i)); __b += _Tp(2); __d = _Tp(1) / (__a * __d + __b); __c = __b + __a / __c; const _Tp __del = __c * __d; __h *= __del; if (std::abs(__del - _Tp(1)) < __eps) { const _Tp __ans = __h * std::exp(-__x); return __ans; } } std::__throw_runtime_error(__N("Continued fraction failed " "in __expint_En_cont_frac.")); } /** * @brief Return the exponential integral @f$ E_n(x) @f$ * by recursion. Use upward recursion for @f$ x < n @f$ * and downward recursion (Miller's algorithm) otherwise. * * The exponential integral is given by * \f[ * E_n(x) = \int_{1}^\infty \frac{e^{-xt}}{t^n} dt * \f] * * @param __n The order of the exponential integral function. * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint_En_recursion(const unsigned int __n, const _Tp __x) { _Tp __En; _Tp __E1 = __expint_E1(__x); if (__x < _Tp(__n)) { // Forward recursion is stable only for n < x. __En = __E1; for (unsigned int __j = 2; __j < __n; ++__j) __En = (std::exp(-__x) - __x * __En) / _Tp(__j - 1); } else { // Backward recursion is stable only for n >= x. __En = _Tp(1); const int __N = __n + 20; // TODO: Check this starting number. _Tp __save = _Tp(0); for (int __j = __N; __j > 0; --__j) { __En = (std::exp(-__x) - __j * __En) / __x; if (__j == __n) __save = __En; } _Tp __norm = __En / __E1; __En /= __norm; } return __En; } /** * @brief Return the exponential integral @f$ Ei(x) @f$ * by series summation. * * The exponential integral is given by * \f[ * Ei(x) = -\int_{-x}^\infty \frac{e^t}{t} dt * \f] * * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint_Ei_series(const _Tp __x) { _Tp __term = _Tp(1); _Tp __sum = _Tp(0); const unsigned int __max_iter = 1000; for (unsigned int __i = 1; __i < __max_iter; ++__i) { __term *= __x / __i; __sum += __term / __i; if (__term < std::numeric_limits<_Tp>::epsilon() * __sum) break; } return __numeric_constants<_Tp>::__gamma_e() + __sum + std::log(__x); } /** * @brief Return the exponential integral @f$ Ei(x) @f$ * by asymptotic expansion. * * The exponential integral is given by * \f[ * Ei(x) = -\int_{-x}^\infty \frac{e^t}{t} dt * \f] * * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint_Ei_asymp(const _Tp __x) { _Tp __term = _Tp(1); _Tp __sum = _Tp(1); const unsigned int __max_iter = 1000; for (unsigned int __i = 1; __i < __max_iter; ++__i) { _Tp __prev = __term; __term *= __i / __x; if (__term < std::numeric_limits<_Tp>::epsilon()) break; if (__term >= __prev) break; __sum += __term; } return std::exp(__x) * __sum / __x; } /** * @brief Return the exponential integral @f$ Ei(x) @f$. * * The exponential integral is given by * \f[ * Ei(x) = -\int_{-x}^\infty \frac{e^t}{t} dt * \f] * * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint_Ei(const _Tp __x) { if (__x < _Tp(0)) return -__expint_E1(-__x); else if (__x < -std::log(std::numeric_limits<_Tp>::epsilon())) return __expint_Ei_series(__x); else return __expint_Ei_asymp(__x); } /** * @brief Return the exponential integral @f$ E_1(x) @f$. * * The exponential integral is given by * \f[ * E_1(x) = \int_{1}^\infty \frac{e^{-xt}}{t} dt * \f] * * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint_E1(const _Tp __x) { if (__x < _Tp(0)) return -__expint_Ei(-__x); else if (__x < _Tp(1)) return __expint_E1_series(__x); else if (__x < _Tp(100)) // TODO: Find a good asymptotic switch point. return __expint_En_cont_frac(1, __x); else return __expint_E1_asymp(__x); } /** * @brief Return the exponential integral @f$ G-H-I-J-E_n(x) @f$ * for large argument. * * The exponential integral is given by * \f[ * E_n(x) = \int_{1}^\infty \frac{e^{-xt}}{t^n} dt * \f] * * This is something of an extension. * * @param __n The order of the exponential integral function. * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint_asymp(const unsigned int __n, const _Tp __x) { _Tp __term = _Tp(1); _Tp __sum = _Tp(1); for (unsigned int __i = 1; __i <= __n; ++__i) { _Tp __prev = __term; __term *= -(__n - __i + 1) / __x; if (std::abs(__term) > std::abs(__prev)) break; __sum += __term; } return std::exp(-__x) * __sum / __x; } /** * @brief Return the exponential integral @f$ E_n(x) @f$ * for large order. * * The exponential integral is given by * \f[ * E_n(x) = \int_{1}^\infty \frac{e^{-xt}}{t^n} dt * \f] * * This is something of an extension. * * @param __n The order of the exponential integral function. * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint_large_n(const unsigned int __n, const _Tp __x) { const _Tp __xpn = __x + __n; const _Tp __xpn2 = __xpn * __xpn; _Tp __term = _Tp(1); _Tp __sum = _Tp(1); for (unsigned int __i = 1; __i <= __n; ++__i) { _Tp __prev = __term; __term *= (__n - 2 * (__i - 1) * __x) / __xpn2; if (std::abs(__term) < std::numeric_limits<_Tp>::epsilon()) break; __sum += __term; } return std::exp(-__x) * __sum / __xpn; } /** * @brief Return the exponential integral @f$ E_n(x) @f$. * * The exponential integral is given by * \f[ * E_n(x) = \int_{1}^\infty \frac{e^{-xt}}{t^n} dt * \f] * This is something of an extension. * * @param __n The order of the exponential integral function. * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template _Tp __expint(const unsigned int __n, const _Tp __x) { // Return NaN on NaN input. if (__isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (__n <= 1 && __x == _Tp(0)) return std::numeric_limits<_Tp>::infinity(); else { _Tp __E0 = std::exp(__x) / __x; if (__n == 0) return __E0; _Tp __E1 = __expint_E1(__x); if (__n == 1) return __E1; if (__x == _Tp(0)) return _Tp(1) / static_cast<_Tp>(__n - 1); _Tp __En = __expint_En_recursion(__n, __x); return __En; } } /** * @brief Return the exponential integral @f$ Ei(x) @f$. * * The exponential integral is given by * \f[ * Ei(x) = -\int_{-x}^\infty \frac{e^t}{t} dt * \f] * * @param __x The argument of the exponential integral function. * @return The exponential integral. */ template inline _Tp __expint(const _Tp __x) { if (__isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else return __expint_Ei(__x); } } // namespace std::tr1::__detail } } #endif // _GLIBCXX_TR1_EXP_INTEGRAL_TCC // TR1 float.h -*- C++ -*- // Copyright (C) 2006 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/float.h * This is a TR1 C++ Library header. */ #ifndef _TR1_FLOAT_H #define _TR1_FLOAT_H 1 #include #endif // TR1 tgmath.h -*- C++ -*- // Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/tgmath.h * This is a TR1 C++ Library header. */ #ifndef _GLIBCXX_TR1_TGMATH_H #define _GLIBCXX_TR1_TGMATH_H 1 #include #endif // _GLIBCXX_TR1_TGMATH_H // TR1 ccomplex -*- C++ -*- // Copyright (C) 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/ccomplex * This is a TR1 C++ Library header. */ #ifndef _GLIBCXX_TR1_CCOMPLEX #define _GLIBCXX_TR1_CCOMPLEX 1 #include #endif // _GLIBCXX_TR1_CCOMPLEX // -*- C++ -*- // Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** * @file tr1/memory * This is a TR1 C++ Library header. */ #ifndef _GLIBCXX_TR1_MEMORY #define _GLIBCXX_TR1_MEMORY 1 #pragma GCC system_header #if defined(_GLIBCXX_INCLUDE_AS_CXX0X) # error TR1 header cannot be included from C++0x header #endif #include #include // std::exception #include // std::type_info in get_deleter #include // std::swap #include // std::basic_ostream #include #include #include #include // std::less #include #include #if defined(_GLIBCXX_INCLUDE_AS_TR1) # include # include # include #else # define _GLIBCXX_INCLUDE_AS_TR1 # define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { # define _GLIBCXX_END_NAMESPACE_TR1 } # define _GLIBCXX_TR1 tr1:: # include # include # include # undef _GLIBCXX_TR1 # undef _GLIBCXX_END_NAMESPACE_TR1 # undef _GLIBCXX_BEGIN_NAMESPACE_TR1 # undef _GLIBCXX_INCLUDE_AS_TR1 #endif #endif // _GLIBCXX_TR1_MEMORY // Special functions -*- C++ -*- // Copyright (C) 2006, 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/poly_laguerre.tcc * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ // // ISO C++ 14882 TR1: 5.2 Special functions // // Written by Edward Smith-Rowland based on: // (1) Handbook of Mathematical Functions, // Ed. Milton Abramowitz and Irene A. Stegun, // Dover Publications, // Section 13, pp. 509-510, Section 22 pp. 773-802 // (2) The Gnu Scientific Library, http://www.gnu.org/software/gsl #ifndef _GLIBCXX_TR1_POLY_LAGUERRE_TCC #define _GLIBCXX_TR1_POLY_LAGUERRE_TCC 1 namespace std { namespace tr1 { // [5.2] Special functions // Implementation-space details. namespace __detail { /** * @brief This routine returns the associated Laguerre polynomial * of order @f$ n @f$, degree @f$ \alpha @f$ for large n. * Abramowitz & Stegun, 13.5.21 * * @param __n The order of the Laguerre function. * @param __alpha The degree of the Laguerre function. * @param __x The argument of the Laguerre function. * @return The value of the Laguerre function of order n, * degree @f$ \alpha @f$, and argument x. * * This is from the GNU Scientific Library. */ template _Tp __poly_laguerre_large_n(const unsigned __n, const _Tpa __alpha1, const _Tp __x) { const _Tp __a = -_Tp(__n); const _Tp __b = _Tp(__alpha1) + _Tp(1); const _Tp __eta = _Tp(2) * __b - _Tp(4) * __a; const _Tp __cos2th = __x / __eta; const _Tp __sin2th = _Tp(1) - __cos2th; const _Tp __th = std::acos(std::sqrt(__cos2th)); const _Tp __pre_h = __numeric_constants<_Tp>::__pi_2() * __numeric_constants<_Tp>::__pi_2() * __eta * __eta * __cos2th * __sin2th; #if _GLIBCXX_USE_C99_MATH_TR1 const _Tp __lg_b = std::tr1::lgamma(_Tp(__n) + __b); const _Tp __lnfact = std::tr1::lgamma(_Tp(__n + 1)); #else const _Tp __lg_b = __log_gamma(_Tp(__n) + __b); const _Tp __lnfact = __log_gamma(_Tp(__n + 1)); #endif _Tp __pre_term1 = _Tp(0.5L) * (_Tp(1) - __b) * std::log(_Tp(0.25L) * __x * __eta); _Tp __pre_term2 = _Tp(0.25L) * std::log(__pre_h); _Tp __lnpre = __lg_b - __lnfact + _Tp(0.5L) * __x + __pre_term1 - __pre_term2; _Tp __ser_term1 = std::sin(__a * __numeric_constants<_Tp>::__pi()); _Tp __ser_term2 = std::sin(_Tp(0.25L) * __eta * (_Tp(2) * __th - std::sin(_Tp(2) * __th)) + __numeric_constants<_Tp>::__pi_4()); _Tp __ser = __ser_term1 + __ser_term2; return std::exp(__lnpre) * __ser; } /** * @brief Evaluate the polynomial based on the confluent hypergeometric * function in a safe way, with no restriction on the arguments. * * The associated Laguerre function is defined by * @f[ * L_n^\alpha(x) = \frac{(\alpha + 1)_n}{n!} * _1F_1(-n; \alpha + 1; x) * @f] * where @f$ (\alpha)_n @f$ is the Pochhammer symbol and * @f$ _1F_1(a; c; x) @f$ is the confluent hypergeometric function. * * This function assumes x != 0. * * This is from the GNU Scientific Library. */ template _Tp __poly_laguerre_hyperg(const unsigned int __n, const _Tpa __alpha1, const _Tp __x) { const _Tp __b = _Tp(__alpha1) + _Tp(1); const _Tp __mx = -__x; const _Tp __tc_sgn = (__x < _Tp(0) ? _Tp(1) : ((__n % 2 == 1) ? -_Tp(1) : _Tp(1))); // Get |x|^n/n! _Tp __tc = _Tp(1); const _Tp __ax = std::abs(__x); for (unsigned int __k = 1; __k <= __n; ++__k) __tc *= (__ax / __k); _Tp __term = __tc * __tc_sgn; _Tp __sum = __term; for (int __k = int(__n) - 1; __k >= 0; --__k) { __term *= ((__b + _Tp(__k)) / _Tp(int(__n) - __k)) * _Tp(__k + 1) / __mx; __sum += __term; } return __sum; } /** * @brief This routine returns the associated Laguerre polynomial * of order @f$ n @f$, degree @f$ \alpha @f$: @f$ L_n^\alpha(x) @f$ * by recursion. * * The associated Laguerre function is defined by * @f[ * L_n^\alpha(x) = \frac{(\alpha + 1)_n}{n!} * _1F_1(-n; \alpha + 1; x) * @f] * where @f$ (\alpha)_n @f$ is the Pochhammer symbol and * @f$ _1F_1(a; c; x) @f$ is the confluent hypergeometric function. * * The associated Laguerre polynomial is defined for integral * @f$ \alpha = m @f$ by: * @f[ * L_n^m(x) = (-1)^m \frac{d^m}{dx^m} L_{n + m}(x) * @f] * where the Laguerre polynomial is defined by: * @f[ * L_n(x) = \frac{e^x}{n!} \frac{d^n}{dx^n} (x^ne^{-x}) * @f] * * @param __n The order of the Laguerre function. * @param __alpha The degree of the Laguerre function. * @param __x The argument of the Laguerre function. * @return The value of the Laguerre function of order n, * degree @f$ \alpha @f$, and argument x. */ template _Tp __poly_laguerre_recursion(const unsigned int __n, const _Tpa __alpha1, const _Tp __x) { // Compute l_0. _Tp __l_0 = _Tp(1); if (__n == 0) return __l_0; // Compute l_1^alpha. _Tp __l_1 = -__x + _Tp(1) + _Tp(__alpha1); if (__n == 1) return __l_1; // Compute l_n^alpha by recursion on n. _Tp __l_n2 = __l_0; _Tp __l_n1 = __l_1; _Tp __l_n = _Tp(0); for (unsigned int __nn = 2; __nn <= __n; ++__nn) { __l_n = (_Tp(2 * __nn - 1) + _Tp(__alpha1) - __x) * __l_n1 / _Tp(__nn) - (_Tp(__nn - 1) + _Tp(__alpha1)) * __l_n2 / _Tp(__nn); __l_n2 = __l_n1; __l_n1 = __l_n; } return __l_n; } /** * @brief This routine returns the associated Laguerre polynomial * of order n, degree @f$ \alpha @f$: @f$ L_n^alpha(x) @f$. * * The associated Laguerre function is defined by * @f[ * L_n^\alpha(x) = \frac{(\alpha + 1)_n}{n!} * _1F_1(-n; \alpha + 1; x) * @f] * where @f$ (\alpha)_n @f$ is the Pochhammer symbol and * @f$ _1F_1(a; c; x) @f$ is the confluent hypergeometric function. * * The associated Laguerre polynomial is defined for integral * @f$ \alpha = m @f$ by: * @f[ * L_n^m(x) = (-1)^m \frac{d^m}{dx^m} L_{n + m}(x) * @f] * where the Laguerre polynomial is defined by: * @f[ * L_n(x) = \frac{e^x}{n!} \frac{d^n}{dx^n} (x^ne^{-x}) * @f] * * @param __n The order of the Laguerre function. * @param __alpha The degree of the Laguerre function. * @param __x The argument of the Laguerre function. * @return The value of the Laguerre function of order n, * degree @f$ \alpha @f$, and argument x. */ template inline _Tp __poly_laguerre(const unsigned int __n, const _Tpa __alpha1, const _Tp __x) { if (__x < _Tp(0)) std::__throw_domain_error(__N("Negative argument " "in __poly_laguerre.")); // Return NaN on NaN input. else if (__isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (__n == 0) return _Tp(1); else if (__n == 1) return _Tp(1) + _Tp(__alpha1) - __x; else if (__x == _Tp(0)) { _Tp __prod = _Tp(__alpha1) + _Tp(1); for (unsigned int __k = 2; __k <= __n; ++__k) __prod *= (_Tp(__alpha1) + _Tp(__k)) / _Tp(__k); return __prod; } else if (__n > 10000000 && _Tp(__alpha1) > -_Tp(1) && __x < _Tp(2) * (_Tp(__alpha1) + _Tp(1)) + _Tp(4 * __n)) return __poly_laguerre_large_n(__n, __alpha1, __x); else if (_Tp(__alpha1) >= _Tp(0) || (__x > _Tp(0) && _Tp(__alpha1) < -_Tp(__n + 1))) return __poly_laguerre_recursion(__n, __alpha1, __x); else return __poly_laguerre_hyperg(__n, __alpha1, __x); } /** * @brief This routine returns the associated Laguerre polynomial * of order n, degree m: @f$ L_n^m(x) @f$. * * The associated Laguerre polynomial is defined for integral * @f$ \alpha = m @f$ by: * @f[ * L_n^m(x) = (-1)^m \frac{d^m}{dx^m} L_{n + m}(x) * @f] * where the Laguerre polynomial is defined by: * @f[ * L_n(x) = \frac{e^x}{n!} \frac{d^n}{dx^n} (x^ne^{-x}) * @f] * * @param __n The order of the Laguerre polynomial. * @param __m The degree of the Laguerre polynomial. * @param __x The argument of the Laguerre polynomial. * @return The value of the associated Laguerre polynomial of order n, * degree m, and argument x. */ template inline _Tp __assoc_laguerre(const unsigned int __n, const unsigned int __m, const _Tp __x) { return __poly_laguerre(__n, __m, __x); } /** * @brief This routine returns the Laguerre polynomial * of order n: @f$ L_n(x) @f$. * * The Laguerre polynomial is defined by: * @f[ * L_n(x) = \frac{e^x}{n!} \frac{d^n}{dx^n} (x^ne^{-x}) * @f] * * @param __n The order of the Laguerre polynomial. * @param __x The argument of the Laguerre polynomial. * @return The value of the Laguerre polynomial of order n * and argument x. */ template inline _Tp __laguerre(const unsigned int __n, const _Tp __x) { return __poly_laguerre(__n, 0, __x); } } // namespace std::tr1::__detail } } #endif // _GLIBCXX_TR1_POLY_LAGUERRE_TCC // TR1 cstdarg -*- C++ -*- // Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/cstdarg * This is a TR1 C++ Library header. */ #ifndef _GLIBCXX_TR1_CSTDARG #define _GLIBCXX_TR1_CSTDARG 1 #include #endif // _GLIBCXX_TR1_CSTDARG // TR1 stdarg.h -*- C++ -*- // Copyright (C) 2006 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/stdarg.h * This is a TR1 C++ Library header. */ #ifndef _TR1_STDARG_H #define _TR1_STDARG_H 1 #include #endif // TR1 cwchar -*- C++ -*- // Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/cwchar * This is a TR1 C++ Library header. */ #ifndef _GLIBCXX_TR1_CWCHAR #define _GLIBCXX_TR1_CWCHAR 1 #pragma GCC system_header #if defined(_GLIBCXX_INCLUDE_AS_CXX0X) # error TR1 header cannot be included from C++0x header #endif #include #if defined(_GLIBCXX_INCLUDE_AS_TR1) # include #else # define _GLIBCXX_INCLUDE_AS_TR1 # define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { # define _GLIBCXX_END_NAMESPACE_TR1 } # define _GLIBCXX_TR1 tr1:: # include # undef _GLIBCXX_TR1 # undef _GLIBCXX_END_NAMESPACE_TR1 # undef _GLIBCXX_BEGIN_NAMESPACE_TR1 # undef _GLIBCXX_INCLUDE_AS_TR1 #endif #endif // _GLIBCXX_TR1_CWCHAR // TR1 ctype.h -*- C++ -*- // Copyright (C) 2006 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/ctype.h * This is a TR1 C++ Library header. */ #ifndef _TR1_CTYPE_H #define _TR1_CTYPE_H 1 #include #endif // TR1 unordered_map -*- C++ -*- // Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/unordered_map * This is a TR1 C++ Library header. */ #ifndef _GLIBCXX_TR1_UNORDERED_MAP #define _GLIBCXX_TR1_UNORDERED_MAP 1 #pragma GCC system_header #if defined(_GLIBCXX_INCLUDE_AS_CXX0X) # error TR1 header cannot be included from C++0x header #endif #include #include #include #include // equal_to, _Identity, _Select1st #include #include #include #include #if defined(_GLIBCXX_INCLUDE_AS_TR1) # include #else # define _GLIBCXX_INCLUDE_AS_TR1 # define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { # define _GLIBCXX_END_NAMESPACE_TR1 } # define _GLIBCXX_TR1 tr1:: # include # undef _GLIBCXX_TR1 # undef _GLIBCXX_END_NAMESPACE_TR1 # undef _GLIBCXX_BEGIN_NAMESPACE_TR1 # undef _GLIBCXX_INCLUDE_AS_TR1 #endif #endif // _GLIBCXX_TR1_UNORDERED_MAP // Special functions -*- C++ -*- // Copyright (C) 2006, 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file tr1/ell_integral.tcc * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ // // ISO C++ 14882 TR1: 5.2 Special functions // // Written by Edward Smith-Rowland based on: // (1) B. C. Carlson Numer. Math. 33, 1 (1979) // (2) B. C. Carlson, Special Functions of Applied Mathematics (1977) // (3) The Gnu Scientific Library, http://www.gnu.org/software/gsl // (4) Numerical Recipes in C, 2nd ed, by W. H. Press, S. A. Teukolsky, // W. T. Vetterling, B. P. Flannery, Cambridge University Press // (1992), pp. 261-269 #ifndef _GLIBCXX_TR1_ELL_INTEGRAL_TCC #define _GLIBCXX_TR1_ELL_INTEGRAL_TCC 1 namespace std { namespace tr1 { // [5.2] Special functions // Implementation-space details. namespace __detail { /** * @brief Return the Carlson elliptic function @f$ R_F(x,y,z) @f$ * of the first kind. * * The Carlson elliptic function of the first kind is defined by: * @f[ * R_F(x,y,z) = \frac{1}{2} \int_0^\infty * \frac{dt}{(t + x)^{1/2}(t + y)^{1/2}(t + z)^{1/2}} * @f] * * @param __x The first of three symmetric arguments. * @param __y The second of three symmetric arguments. * @param __z The third of three symmetric arguments. * @return The Carlson elliptic function of the first kind. */ template _Tp __ellint_rf(const _Tp __x, const _Tp __y, const _Tp __z) { const _Tp __min = std::numeric_limits<_Tp>::min(); const _Tp __max = std::numeric_limits<_Tp>::max(); const _Tp __lolim = _Tp(5) * __min; const _Tp __uplim = __max / _Tp(5); if (__x < _Tp(0) || __y < _Tp(0) || __z < _Tp(0)) std::__throw_domain_error(__N("Argument less than zero " "in __ellint_rf.")); else if (__x + __y < __lolim || __x + __z < __lolim || __y + __z < __lolim) std::__throw_domain_error(__N("Argument too small in __ellint_rf")); else { const _Tp __c0 = _Tp(1) / _Tp(4); const _Tp __c1 = _Tp(1) / _Tp(24); const _Tp __c2 = _Tp(1) / _Tp(10); const _Tp __c3 = _Tp(3) / _Tp(44); const _Tp __c4 = _Tp(1) / _Tp(14); _Tp __xn = __x; _Tp __yn = __y; _Tp __zn = __z; const _Tp __eps = std::numeric_limits<_Tp>::epsilon(); const _Tp __errtol = std::pow(__eps, _Tp(1) / _Tp(6)); _Tp __mu; _Tp __xndev, __yndev, __zndev; const unsigned int __max_iter = 100; for (unsigned int __iter = 0; __iter < __max_iter; ++__iter) { __mu = (__xn + __yn + __zn) / _Tp(3); __xndev = 2 - (__mu + __xn) / __mu; __yndev = 2 - (__mu + __yn) / __mu; __zndev = 2 - (__mu + __zn) / __mu; _Tp __epsilon = std::max(std::abs(__xndev), std::abs(__yndev)); __epsilon = std::max(__epsilon, std::abs(__zndev)); if (__epsilon < __errtol) break; const _Tp __xnroot = std::sqrt(__xn); const _Tp __ynroot = std::sqrt(__yn); const _Tp __znroot = std::sqrt(__zn); const _Tp __lambda = __xnroot * (__ynroot + __znroot) + __ynroot * __znroot; __xn = __c0 * (__xn + __lambda); __yn = __c0 * (__yn + __lambda); __zn = __c0 * (__zn + __lambda); } const _Tp __e2 = __xndev * __yndev - __zndev * __zndev; const _Tp __e3 = __xndev * __yndev * __zndev; const _Tp __s = _Tp(1) + (__c1 * __e2 - __c2 - __c3 * __e3) * __e2 + __c4 * __e3; return __s / std::sqrt(__mu); } } /** * @brief Return the complete elliptic integral of the first kind * @f$ K(k) @f$ by series expansion. * * The complete elliptic integral of the first kind is defined as * @f[ * K(k) = F(k,\pi/2) = \int_0^{\pi/2}\frac{d\theta} * {\sqrt{1 - k^2sin^2\theta}} * @f] * * This routine is not bad as long as |k| is somewhat smaller than 1 * but is not is good as the Carlson elliptic integral formulation. * * @param __k The argument of the complete elliptic function. * @return The complete elliptic function of the first kind. */ template _Tp __comp_ellint_1_series(const _Tp __k) { const _Tp __kk = __k * __k; _Tp __term = __kk / _Tp(4); _Tp __sum = _Tp(1) + __term; const unsigned int __max_iter = 1000; for (unsigned int __i = 2; __i < __max_iter; ++__i) { __term *= (2 * __i - 1) * __kk / (2 * __i); if (__term < std::numeric_limits<_Tp>::epsilon()) break; __sum += __term; } return __numeric_constants<_Tp>::__pi_2() * __sum; } /** * @brief Return the complete elliptic integral of the first kind * @f$ K(k) @f$ using the Carlson formulation. * * The complete elliptic integral of the first kind is defined as * @f[ * K(k) = F(k,\pi/2) = \int_0^{\pi/2}\frac{d\theta} * {\sqrt{1 - k^2 sin^2\theta}} * @f] * where @f$ F(k,\phi) @f$ is the incomplete elliptic integral of the * first kind. * * @param __k The argument of the complete elliptic function. * @return The complete elliptic function of the first kind. */ template _Tp __comp_ellint_1(const _Tp __k) { if (__isnan(__k)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (std::abs(__k) >= _Tp(1)) return std::numeric_limits<_Tp>::quiet_NaN(); else return __ellint_rf(_Tp(0), _Tp(1) - __k * __k, _Tp(1)); } /** * @brief Return the incomplete elliptic integral of the first kind * @f$ F(k,\phi) @f$ using the Carlson formulation. * * The incomplete elliptic integral of the first kind is defined as * @f[ * F(k,\phi) = \int_0^{\phi}\frac{d\theta} * {\sqrt{1 - k^2 sin^2\theta}} * @f] * * @param __k The argument of the elliptic function. * @param __phi The integral limit argument of the elliptic function. * @return The elliptic function of the first kind. */ template _Tp __ellint_1(const _Tp __k, const _Tp __phi) { if (__isnan(__k) || __isnan(__phi)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (std::abs(__k) > _Tp(1)) std::__throw_domain_error(__N("Bad argument in __ellint_1.")); else { // Reduce phi to -pi/2 < phi < +pi/2. const int __n = std::floor(__phi / __numeric_constants<_Tp>::__pi() + _Tp(0.5L)); const _Tp __phi_red = __phi - __n * __numeric_constants<_Tp>::__pi(); const _Tp __s = std::sin(__phi_red); const _Tp __c = std::cos(__phi_red); const _Tp __F = __s * __ellint_rf(__c * __c, _Tp(1) - __k * __k * __s * __s, _Tp(1)); if (__n == 0) return __F; else return __F + _Tp(2) * __n * __comp_ellint_1(__k); } } /** * @brief Return the complete elliptic integral of the second kind * @f$ E(k) @f$ by series expansion. * * The complete elliptic integral of the second kind is defined as * @f[ * E(k,\pi/2) = \int_0^{\pi/2}\sqrt{1 - k^2 sin^2\theta} * @f] * * This routine is not bad as long as |k| is somewhat smaller than 1 * but is not is good as the Carlson elliptic integral formulation. * * @param __k The argument of the complete elliptic function. * @return The complete elliptic function of the second kind. */ template _Tp __comp_ellint_2_series(const _Tp __k) { const _Tp __kk = __k * __k; _Tp __term = __kk; _Tp __sum = __term; const unsigned int __max_iter = 1000; for (unsigned int __i = 2; __i < __max_iter; ++__i) { const _Tp __i2m = 2 * __i - 1; const _Tp __i2 = 2 * __i; __term *= __i2m * __i2m * __kk / (__i2 * __i2); if (__term < std::numeric_limits<_Tp>::epsilon()) break; __sum += __term / __i2m; } return __numeric_constants<_Tp>::__pi_2() * (_Tp(1) - __sum); } /** * @brief Return the Carlson elliptic function of the second kind * @f$ R_D(x,y,z) = R_J(x,y,z,z) @f$ where * @f$ R_J(x,y,z,p) @f$ is the Carlson elliptic function * of the third kind. * * The Carlson elliptic function of the second kind is defined by: * @f[ * R_D(x,y,z) = \frac{3}{2} \int_0^\infty * \frac{dt}{(t + x)^{1/2}(t + y)^{1/2}(t + z)^{3/2}} * @f] * * Based on Carlson's algorithms: * - B. C. Carlson Numer. Math. 33, 1 (1979) * - B. C. Carlson, Special Functions of Applied Mathematics (1977) * - Numerical Recipes in C, 2nd ed, pp. 261-269, * by Press, Teukolsky, Vetterling, Flannery (1992) * * @param __x The first of two symmetric arguments. * @param __y The second of two symmetric arguments. * @param __z The third argument. * @return The Carlson elliptic function of the second kind. */ template _Tp __ellint_rd(const _Tp __x, const _Tp __y, const _Tp __z) { const _Tp __eps = std::numeric_limits<_Tp>::epsilon(); const _Tp __errtol = std::pow(__eps / _Tp(8), _Tp(1) / _Tp(6)); const _Tp __min = std::numeric_limits<_Tp>::min(); const _Tp __max = std::numeric_limits<_Tp>::max(); const _Tp __lolim = _Tp(2) / std::pow(__max, _Tp(2) / _Tp(3)); const _Tp __uplim = std::pow(_Tp(0.1L) * __errtol / __min, _Tp(2) / _Tp(3)); if (__x < _Tp(0) || __y < _Tp(0)) std::__throw_domain_error(__N("Argument less than zero " "in __ellint_rd.")); else if (__x + __y < __lolim || __z < __lolim) std::__throw_domain_error(__N("Argument too small " "in __ellint_rd.")); else { const _Tp __c0 = _Tp(1) / _Tp(4); const _Tp __c1 = _Tp(3) / _Tp(14); coy-z-{-|-}-~--€--‚-ƒ-„-…-†-‡-ˆ-nst _Tp __c2 = _Tp(1) / _Tp(6); const _Tp __c3 = _Tp(9) / _Tp(22); const _Tp __c4 = _Tp(3) / _Tp(26); _Tp __xn = __x; _Tp __yn = __y; _Tp __zn = __z; _Tp __sigma = _Tp(0); _Tp __power4 = _Tp(1); _Tp __mu; _Tp __xndev, __yndev, __zndev; const unsigned int __max_iter = 100; for (unsigned int __iter = 0; __iter < __max_iter; ++__iter) { __mu = (__xn + __yn + _Tp(3) * __zn) / _Tp(5); __xndev = (__mu - __xn) / __mu; __yndev = (__mu - __yn) / __mu; __zndev = (__mu - __zn) / __mu; _Tp __epsilon = std::max(std::abs(__xndev), std::abs(__yndev)); __epsilon = std::max(__epsilon, std::abs(__zndev)); if (__epsilon < __errtol) break; _Tp __xnroot = std::sqrt(__xn); _Tp __ynroot = std::sqrt(__yn); _Tp __znroot = std::sqrt(__zn); _Tp __lambda = __xnroot * (__ynroot + __znroot) + __ynroot * __znroot; __sigma += __power4 / (__znroot * (__zn + __lambda)); __power4 *= __c0; __xn = __c0 * (__xn + __lambda); __yn = __c0 * (__yn + __lambda); __zn = __c0 * (__zn + __lambda); } _Tp __ea = __xndev * __yndev; _Tp __eb = __zndev * __zndev; _Tp __ec = __ea - __eb; _Tp __ed = __ea - _Tp(6) * __eb; _Tp __ef = __ed + __ec + __ec; _Tp __s1 = __ed * (-__c1 + __c3 * __ed / _Tp(3) - _Tp(3) * __c4 * __zndev * __ef / _Tp(2)); _Tp __s2 = __zndev * (__c2 * __ef + __zndev * (-__c3 * __ec - __zndev * __c4 - __ea)); return _Tp(3) * __sigma + __power4 * (_Tp(1) + __s1 + __s2) / (__mu * std::sqrt(__mu)); } } /** * @brief Return the complete elliptic integral of the second kind * @f$ E(k) @f$ using the Carlson formulation. * * The complete elliptic integral of the second kind is defined as * @f[ * E(k,\pi/2) = \int_0^{\pi/2}\sqrt{1 - k^2 sin^2\theta} * @f] * * @param __k The argument of the complete elliptic function. * @return The complete elliptic function of the second kind. */ template _Tp __comp_ellint_2(const _Tp __k) { if (__isnan(__k)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (std::abs(__k) == 1) return _Tp(1); else if (std::abs(__k) > _Tp(1)) std::__throw_domain_error(__N("Bad argument in __comp_ellint_2.")); else { const _Tp __kk = __k * __k; return __ellint_rf(_Tp(0), _Tp(1) - __kk, _Tp(1)) - __kk * __ellint_rd(_Tp(0), _Tp(1) - __kk, _Tp(1)) / _Tp(3); } } /** * @brief Return the incomplete elliptic integral of the second kind * @f$ E(k,\phi) @f$ using the Carlson formulation. * * The incomplete elliptic integral of the second kind is defined as * @f[ * E(k,\phi) = \int_0^{\phi} \sqrt{1 - k^2 sin^2\theta} * @f] * * @param __k The argument of the elliptic function. * @param __phi The integral limit argument of the elliptic function. * @return The elliptic function of the second kind. */ template _Tp __ellint_2(const _Tp __k, const _Tp __phi) { if (__isnan(__k) || __isnan(__phi)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (std::abs(__k) > _Tp(1)) std::__throw_domain_error(__N("Bad argument in __ellint_2.")); else { // Reduce phi to -pi/2 < phi < +pi/2. const int __n = std::floor(__phi / __numeric_constants<_Tp>::__pi() + _Tp(0.5L)); const _Tp __phi_red = __phi - __n * __numeric_constants<_Tp>::__pi(); const _Tp __kk = __k * __k; const _Tp __s = std::sin(__phi_red); const _Tp __ss = __s * __s; const _Tp __sss = __ss * __s; const _Tp __c = std::cos(__phi_red); const _Tp __cc = __c * __c; const _Tp __E = __s * __ellint_rf(__cc, _Tp(1) - __kk * __ss, _Tp(1)) - __kk * __sss * __ellint_rd(__cc, _Tp(1) - __kk * __ss, _Tp(1)) / _Tp(3); if (__n == 0) return __E; else return __E + _Tp(2) * __n * __comp_ellint_2(__k); } } /** * @brief Return the Carlson elliptic function * @f$ R_C(x,y) = R_F(x,y,y) @f$ where @f$ R_F(x,y,z) @f$ * is the Carlson elliptic function of the first kind. * * The Carlson elliptic function is defined by: * @f[ * R_C(x,y) = \frac{1}{2} \int_0^\infty * \frac{dt}{(t + x)^{1/2}(t + y)} * @f] * * Based on Carlson's algorithms: * - B. C. Carlson Numer. Math. 33, 1 (1979) * - B. C. Carlson, Special Functions of Applied Mathematics (1977) * - Numerical Recipes in C, 2nd ed, pp. 261-269, * by Press, Teukolsky, Vetterling, Flannery (1992) * * @param __x The first argument. * @param __y The second argument. * @return The Carlson elliptic function. */ template _Tp __ellint_rc(const _Tp __x, const _Tp __y) { const _Tp __min = std::numeric_limits<_Tp>::min(); const _Tp __max = std::numeric_limits<_Tp>::max(); const _Tp __lolim = _Tp(5) * __min; const _Tp __uplim = __max / _Tp(5); if (__x < _Tp(0) || __y < _Tp(0) || __x + __y < __lolim) std::__throw_domain_error(__N("Argument less than zero " "in __ellint_rc.")); else { const _Tp __c0 = _Tp(1) / _Tp(4); const _Tp __c1 = _Tp(1) / _Tp(7); const _Tp __c2 = _Tp(9) / _Tp(22); const _Tp __c3 = _Tp(3) / _Tp(10); const _Tp __c4 = _Tp(3) / _Tp(8); _Tp __xn = __x; _Tp __yn = __y; const _Tp __eps = std::numeric_limits<_Tp>::epsilon(); const _Tp __errtol = std::pow(__eps / _Tp(30), _Tp(1) / _Tp(6)); _Tp __mu; _Tp __sn; const unsigned int __max_iter = 100; for (unsigned int __iter = 0; __iter < __max_iter; ++__iter) { __mu = (__xn + _Tp(2) * __yn) / _Tp(3); __sn = (__yn + __mu) / __mu - _Tp(2); if (std::abs(__sn) < __errtol) break; const _Tp __lambda = _Tp(2) * std::sqrt(__xn) * std::sqrt(__yn) + __yn; __xn = __c0 * (__xn + __lambda); __yn = __c0 * (__yn + __lambda); } _Tp __