]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/tr1/poly_hermite.tcc
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / tr1 / poly_hermite.tcc
1 // Special functions -*- C++ -*-
2
3 // Copyright (C) 2006, 2007, 2008
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
9 // Free Software Foundation; either version 2, or (at your option)
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 //
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21 //
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 /** @file tr1/poly_hermite.tcc
32  *  This is an internal header file, included by other library headers.
33  *  You should not attempt to use it directly.
34  */
35
36 //
37 // ISO C++ 14882 TR1: 5.2  Special functions
38 //
39
40 // Written by Edward Smith-Rowland based on:
41 //   (1) Handbook of Mathematical Functions,
42 //       Ed. Milton Abramowitz and Irene A. Stegun,
43 //       Dover Publications, Section 22 pp. 773-802
44
45 #ifndef _GLIBCXX_TR1_POLY_HERMITE_TCC
46 #define _GLIBCXX_TR1_POLY_HERMITE_TCC 1
47
48 namespace std
49 {
50 namespace tr1
51 {
52
53   // [5.2] Special functions
54
55   // Implementation-space details.
56   namespace __detail
57   {
58
59     /**
60      *   @brief This routine returns the Hermite polynomial
61      *          of order n: \f$ H_n(x) \f$ by recursion on n.
62      * 
63      *   The Hermite polynomial is defined by:
64      *   @f[
65      *     H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
66      *   @f]
67      *
68      *   @param __n The order of the Hermite polynomial.
69      *   @param __x The argument of the Hermite polynomial.
70      *   @return The value of the Hermite polynomial of order n
71      *           and argument x.
72      */
73     template<typename _Tp>
74     _Tp
75     __poly_hermite_recursion(const unsigned int __n, const _Tp __x)
76     {
77       //  Compute H_0.
78       _Tp __H_0 = 1;
79       if (__n == 0)
80         return __H_0;
81
82       //  Compute H_1.
83       _Tp __H_1 = 2 * __x;
84       if (__n == 1)
85         return __H_1;
86
87       //  Compute H_n.
88       _Tp __H_n, __H_nm1, __H_nm2;
89       unsigned int __i;
90       for  (__H_nm2 = __H_0, __H_nm1 = __H_1, __i = 2; __i <= __n; ++__i)
91         {
92           __H_n = 2 * (__x * __H_nm1 + (__i - 1) * __H_nm2);
93           __H_nm2 = __H_nm1;
94           __H_nm1 = __H_n;
95         }
96
97       return __H_n;
98     }
99
100
101     /**
102      *   @brief This routine returns the Hermite polynomial
103      *          of order n: \f$ H_n(x) \f$.
104      * 
105      *   The Hermite polynomial is defined by:
106      *   @f[
107      *     H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
108      *   @f]
109      *
110      *   @param __n The order of the Hermite polynomial.
111      *   @param __x The argument of the Hermite polynomial.
112      *   @return The value of the Hermite polynomial of order n
113      *           and argument x.
114      */
115     template<typename _Tp>
116     inline _Tp
117     __poly_hermite(const unsigned int __n, const _Tp __x)
118     {
119       if (__isnan(__x))
120         return std::numeric_limits<_Tp>::quiet_NaN();
121       else
122         return __poly_hermite_recursion(__n, __x);
123     }
124
125   } // namespace std::tr1::__detail
126 }
127 }
128
129 #endif // _GLIBCXX_TR1_POLY_HERMITE_TCC