00001 // Special functions -*- C++ -*- 00002 00003 // Copyright (C) 2006, 2007, 2008, 2009 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 3, or (at your option) 00010 // any later version. 00011 // 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // Under Section 7 of GPL version 3, you are granted additional 00018 // permissions described in the GCC Runtime Library Exception, version 00019 // 3.1, as published by the Free Software Foundation. 00020 00021 // You should have received a copy of the GNU General Public License and 00022 // a copy of the GCC Runtime Library Exception along with this program; 00023 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00024 // <http://www.gnu.org/licenses/>. 00025 00026 /** @file tr1/poly_hermite.tcc 00027 * This is an internal header file, included by other library headers. 00028 * You should not attempt to use it directly. 00029 */ 00030 00031 // 00032 // ISO C++ 14882 TR1: 5.2 Special functions 00033 // 00034 00035 // Written by Edward Smith-Rowland based on: 00036 // (1) Handbook of Mathematical Functions, 00037 // Ed. Milton Abramowitz and Irene A. Stegun, 00038 // Dover Publications, Section 22 pp. 773-802 00039 00040 #ifndef _GLIBCXX_TR1_POLY_HERMITE_TCC 00041 #define _GLIBCXX_TR1_POLY_HERMITE_TCC 1 00042 00043 namespace std 00044 { 00045 namespace tr1 00046 { 00047 00048 // [5.2] Special functions 00049 00050 // Implementation-space details. 00051 namespace __detail 00052 { 00053 00054 /** 00055 * @brief This routine returns the Hermite polynomial 00056 * of order n: \f$ H_n(x) \f$ by recursion on n. 00057 * 00058 * The Hermite polynomial is defined by: 00059 * @f[ 00060 * H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2} 00061 * @f] 00062 * 00063 * @param __n The order of the Hermite polynomial. 00064 * @param __x The argument of the Hermite polynomial. 00065 * @return The value of the Hermite polynomial of order n 00066 * and argument x. 00067 */ 00068 template<typename _Tp> 00069 _Tp 00070 __poly_hermite_recursion(const unsigned int __n, const _Tp __x) 00071 { 00072 // Compute H_0. 00073 _Tp __H_0 = 1; 00074 if (__n == 0) 00075 return __H_0; 00076 00077 // Compute H_1. 00078 _Tp __H_1 = 2 * __x; 00079 if (__n == 1) 00080 return __H_1; 00081 00082 // Compute H_n. 00083 _Tp __H_n, __H_nm1, __H_nm2; 00084 unsigned int __i; 00085 for (__H_nm2 = __H_0, __H_nm1 = __H_1, __i = 2; __i <= __n; ++__i) 00086 { 00087 __H_n = 2 * (__x * __H_nm1 + (__i - 1) * __H_nm2); 00088 __H_nm2 = __H_nm1; 00089 __H_nm1 = __H_n; 00090 } 00091 00092 return __H_n; 00093 } 00094 00095 00096 /** 00097 * @brief This routine returns the Hermite polynomial 00098 * of order n: \f$ H_n(x) \f$. 00099 * 00100 * The Hermite polynomial is defined by: 00101 * @f[ 00102 * H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2} 00103 * @f] 00104 * 00105 * @param __n The order of the Hermite polynomial. 00106 * @param __x The argument of the Hermite polynomial. 00107 * @return The value of the Hermite polynomial of order n 00108 * and argument x. 00109 */ 00110 template<typename _Tp> 00111 inline _Tp 00112 __poly_hermite(const unsigned int __n, const _Tp __x) 00113 { 00114 if (__isnan(__x)) 00115 return std::numeric_limits<_Tp>::quiet_NaN(); 00116 else 00117 return __poly_hermite_recursion(__n, __x); 00118 } 00119 00120 } // namespace std::tr1::__detail 00121 } 00122 } 00123 00124 #endif // _GLIBCXX_TR1_POLY_HERMITE_TCC