45 #ifndef _GLIBCXX_TR1_LEGENDRE_FUNCTION_TCC
46 #define _GLIBCXX_TR1_LEGENDRE_FUNCTION_TCC 1
74 template<
typename _Tp>
79 if ((__x < _Tp(-1)) || (__x > _Tp(+1)))
80 std::__throw_domain_error(__N(
"Argument out of range"
81 " in __poly_legendre_p."));
82 else if (__isnan(__x))
84 else if (__x == +_Tp(1))
86 else if (__x == -_Tp(1))
87 return (__l % 2 == 1 ? -_Tp(1) : +_Tp(1));
99 for (
unsigned int __ll = 2; __ll <= __l; ++__ll)
103 __p_l = _Tp(2) * __x * __p_lm1 - __p_lm2
104 - (__x * __p_lm1 - __p_lm2) / _Tp(__ll);
131 template<
typename _Tp>
137 if (__x < _Tp(-1) || __x > _Tp(+1))
138 std::__throw_domain_error(__N(
"Argument out of range"
139 " in __assoc_legendre_p."));
141 std::__throw_domain_error(__N(
"Degree out of range"
142 " in __assoc_legendre_p."));
143 else if (__isnan(__x))
156 for (
unsigned int __i = 1; __i <= __m; ++__i)
158 __p_mm *= -__fact * __root;
165 _Tp __p_mp1m = _Tp(2 * __m + 1) * __x * __p_mm;
169 _Tp __p_lm2m = __p_mm;
170 _Tp __P_lm1m = __p_mp1m;
172 for (
unsigned int __j = __m + 2; __j <= __l; ++__j)
174 __p_lm = (_Tp(2 * __j - 1) * __x * __P_lm1m
175 - _Tp(__j + __m - 1) * __p_lm2m) / _Tp(__j - __m);
211 template <
typename _Tp>
216 if (__isnan(__theta))
223 std::__throw_domain_error(__N(
"Bad argument "
224 "in __sph_legendre."));
234 else if (__x == _Tp(1) || __x == -_Tp(1))
246 const _Tp __sgn = ( __m % 2 == 1 ? -_Tp(1) : _Tp(1));
247 const _Tp __y_mp1m_factor = __x *
std::sqrt(_Tp(2 * __m + 3));
248 #if _GLIBCXX_USE_C99_MATH_TR1
249 const _Tp __lncirc = std::tr1::log1p(-__x * __x);
251 const _Tp __lncirc =
std::log(_Tp(1) - __x * __x);
254 #if _GLIBCXX_USE_C99_MATH_TR1
255 const _Tp __lnpoch = std::tr1::lgamma(_Tp(__m + _Tp(0.5L)))
256 - std::tr1::lgamma(_Tp(__m));
258 const _Tp __lnpoch =
__log_gamma(_Tp(__m + _Tp(0.5L)))
261 const _Tp __lnpre_val =
263 + _Tp(0.5L) * (__lnpoch + __m * __lncirc);
264 _Tp __sr =
std::sqrt((_Tp(2) + _Tp(1) / __m)
266 _Tp __y_mm = __sgn * __sr *
std::exp(__lnpre_val);
267 _Tp __y_mp1m = __y_mp1m_factor * __y_mm;
273 else if (__l == __m + 1)
282 for (
int __ll = __m + 2; __ll <= __l; ++__ll)
284 const _Tp __rat1 = _Tp(__ll - __m) / _Tp(__ll + __m);
285 const _Tp __rat2 = _Tp(__ll - __m - 1) / _Tp(__ll + __m - 1);
286 const _Tp __fact1 =
std::sqrt(__rat1 * _Tp(2 * __ll + 1)
287 * _Tp(2 * __ll - 1));
288 const _Tp __fact2 =
std::sqrt(__rat1 * __rat2 * _Tp(2 * __ll + 1)
289 / _Tp(2 * __ll - 3));
290 __y_lm = (__x * __y_mp1m * __fact1
291 - (__ll + __m - 1) * __y_mm * __fact2) / _Tp(__ll - __m);
305 #endif // _GLIBCXX_TR1_LEGENDRE_FUNCTION_TCC
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
A structure for numeric constants.
complex< _Tp > cos(const complex< _Tp > &)
Return complex cosine of z.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
_Tp __poly_legendre_p(const unsigned int __l, const _Tp __x)
Return the Legendre polynomial by recursion on order .
static _Tp __lnpi()
Constant .
_Tp __log_gamma(const _Tp __x)
Return . This will return values even for . To recover the sign of for any argument use __log_gamma_...
_Tp __assoc_legendre_p(const unsigned int __l, const unsigned int __m, const _Tp __x)
Return the associated Legendre function by recursion on .
_Tp __sph_legendre(const unsigned int __l, const unsigned int __m, const _Tp __theta)
Return the spherical associated Legendre function.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.