]>
Commit | Line | Data |
---|---|---|
7c62b943 BK |
1 | // Special functions -*- C++ -*- |
2 | ||
d652f226 | 3 | // Copyright (C) 2006, 2007, 2008, 2009, 2010 |
7c62b943 BK |
4 | // Free Software Foundation, Inc. |
5 | // | |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
748086b7 | 9 | // Free Software Foundation; either version 3, or (at your option) |
7c62b943 BK |
10 | // any later version. |
11 | // | |
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | // | |
748086b7 JJ |
17 | // Under Section 7 of GPL version 3, you are granted additional |
18 | // permissions described in the GCC Runtime Library Exception, version | |
19 | // 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | // You should have received a copy of the GNU General Public License and | |
22 | // a copy of the GCC Runtime Library Exception along with this program; | |
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 | // <http://www.gnu.org/licenses/>. | |
7c62b943 BK |
25 | |
26 | /** @file tr1/poly_hermite.tcc | |
27 | * This is an internal header file, included by other library headers. | |
f910786b | 28 | * Do not attempt to use it directly. @headername{tr1/cmath} |
7c62b943 BK |
29 | */ |
30 | ||
31 | // | |
32 | // ISO C++ 14882 TR1: 5.2 Special functions | |
33 | // | |
34 | ||
35 | // Written by Edward Smith-Rowland based on: | |
36 | // (1) Handbook of Mathematical Functions, | |
37 | // Ed. Milton Abramowitz and Irene A. Stegun, | |
38 | // Dover Publications, Section 22 pp. 773-802 | |
39 | ||
e133ace8 PC |
40 | #ifndef _GLIBCXX_TR1_POLY_HERMITE_TCC |
41 | #define _GLIBCXX_TR1_POLY_HERMITE_TCC 1 | |
7c62b943 | 42 | |
12ffa228 | 43 | namespace std _GLIBCXX_VISIBILITY(default) |
7c62b943 | 44 | { |
e133ace8 PC |
45 | namespace tr1 |
46 | { | |
7c62b943 BK |
47 | // [5.2] Special functions |
48 | ||
7c62b943 | 49 | // Implementation-space details. |
7c62b943 BK |
50 | namespace __detail |
51 | { | |
12ffa228 | 52 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
7c62b943 BK |
53 | |
54 | /** | |
55 | * @brief This routine returns the Hermite polynomial | |
56 | * of order n: \f$ H_n(x) \f$ by recursion on n. | |
57 | * | |
58 | * The Hermite polynomial is defined by: | |
59 | * @f[ | |
60 | * H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2} | |
61 | * @f] | |
62 | * | |
63 | * @param __n The order of the Hermite polynomial. | |
64 | * @param __x The argument of the Hermite polynomial. | |
65 | * @return The value of the Hermite polynomial of order n | |
66 | * and argument x. | |
67 | */ | |
68 | template<typename _Tp> | |
69 | _Tp | |
70 | __poly_hermite_recursion(const unsigned int __n, const _Tp __x) | |
71 | { | |
72 | // Compute H_0. | |
73 | _Tp __H_0 = 1; | |
74 | if (__n == 0) | |
75 | return __H_0; | |
76 | ||
77 | // Compute H_1. | |
78 | _Tp __H_1 = 2 * __x; | |
79 | if (__n == 1) | |
80 | return __H_1; | |
81 | ||
82 | // Compute H_n. | |
83 | _Tp __H_n, __H_nm1, __H_nm2; | |
84 | unsigned int __i; | |
85 | for (__H_nm2 = __H_0, __H_nm1 = __H_1, __i = 2; __i <= __n; ++__i) | |
86 | { | |
87 | __H_n = 2 * (__x * __H_nm1 + (__i - 1) * __H_nm2); | |
88 | __H_nm2 = __H_nm1; | |
89 | __H_nm1 = __H_n; | |
90 | } | |
91 | ||
92 | return __H_n; | |
93 | } | |
94 | ||
95 | ||
96 | /** | |
97 | * @brief This routine returns the Hermite polynomial | |
98 | * of order n: \f$ H_n(x) \f$. | |
99 | * | |
100 | * The Hermite polynomial is defined by: | |
101 | * @f[ | |
102 | * H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2} | |
103 | * @f] | |
104 | * | |
105 | * @param __n The order of the Hermite polynomial. | |
106 | * @param __x The argument of the Hermite polynomial. | |
107 | * @return The value of the Hermite polynomial of order n | |
108 | * and argument x. | |
109 | */ | |
110 | template<typename _Tp> | |
111 | inline _Tp | |
112 | __poly_hermite(const unsigned int __n, const _Tp __x) | |
113 | { | |
114 | if (__isnan(__x)) | |
115 | return std::numeric_limits<_Tp>::quiet_NaN(); | |
116 | else | |
117 | return __poly_hermite_recursion(__n, __x); | |
118 | } | |
119 | ||
12ffa228 | 120 | _GLIBCXX_END_NAMESPACE_VERSION |
7c62b943 | 121 | } // namespace std::tr1::__detail |
e133ace8 | 122 | } |
7c62b943 BK |
123 | } |
124 | ||
e133ace8 | 125 | #endif // _GLIBCXX_TR1_POLY_HERMITE_TCC |