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