OSDN Git Service

2008-01-31 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / tr1 / poly_hermite.tcc
1 // Special functions -*- C++ -*-
2
3 // Copyright (C) 2006-2007
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   /**
56    * @ingroup tr1_math_spec_func
57    * @{
58    */
59
60   //
61   // Implementation-space details.
62   //
63   namespace __detail
64   {
65
66     /**
67      *   @brief This routine returns the Hermite polynomial
68      *          of order n: \f$ H_n(x) \f$ by recursion on n.
69      * 
70      *   The Hermite polynomial is defined by:
71      *   @f[
72      *     H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
73      *   @f]
74      *
75      *   @param __n The order of the Hermite polynomial.
76      *   @param __x The argument of the Hermite polynomial.
77      *   @return The value of the Hermite polynomial of order n
78      *           and argument x.
79      */
80     template<typename _Tp>
81     _Tp
82     __poly_hermite_recursion(const unsigned int __n, const _Tp __x)
83     {
84       //  Compute H_0.
85       _Tp __H_0 = 1;
86       if (__n == 0)
87         return __H_0;
88
89       //  Compute H_1.
90       _Tp __H_1 = 2 * __x;
91       if (__n == 1)
92         return __H_1;
93
94       //  Compute H_n.
95       _Tp __H_n, __H_nm1, __H_nm2;
96       unsigned int __i;
97       for  (__H_nm2 = __H_0, __H_nm1 = __H_1, __i = 2; __i <= __n; ++__i)
98         {
99           __H_n = 2 * (__x * __H_nm1 + (__i - 1) * __H_nm2);
100           __H_nm2 = __H_nm1;
101           __H_nm1 = __H_n;
102         }
103
104       return __H_n;
105     }
106
107
108     /**
109      *   @brief This routine returns the Hermite polynomial
110      *          of order n: \f$ H_n(x) \f$.
111      * 
112      *   The Hermite polynomial is defined by:
113      *   @f[
114      *     H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
115      *   @f]
116      *
117      *   @param __n The order of the Hermite polynomial.
118      *   @param __x The argument of the Hermite polynomial.
119      *   @return The value of the Hermite polynomial of order n
120      *           and argument x.
121      */
122     template<typename _Tp>
123     inline _Tp
124     __poly_hermite(const unsigned int __n, const _Tp __x)
125     {
126       if (__isnan(__x))
127         return std::numeric_limits<_Tp>::quiet_NaN();
128       else
129         return __poly_hermite_recursion(__n, __x);
130     }
131
132   } // namespace std::tr1::__detail
133
134   /* @} */ // group tr1_math_spec_func
135
136 }
137 }
138
139 #endif // _GLIBCXX_TR1_POLY_HERMITE_TCC