# poly_hermite.tcc

Go to the documentation of this file.

    00001 // Special functions -*- C++ -*-
    00002
    00003 // Copyright (C) 2006, 2007, 2008
    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 2, 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 // You should have received a copy of the GNU General Public License along
    00018 // with this library; see the file COPYING.  If not, write to the Free
    00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    00020 // USA.
    00021 //
    00022 // As a special exception, you may use this file as part of a free software
    00023 // library without restriction.  Specifically, if other files instantiate
    00024 // templates or use macros or inline functions from this file, or you compile
    00025 // this file and link it with other files to produce an executable, this
    00026 // file does not by itself cause the resulting executable to be covered by
    00027 // the GNU General Public License.  This exception does not however
    00028 // invalidate any other reasons why the executable file might be covered by
    00029 // the GNU General Public License.
    00030
    00031 /** @file tr1/poly_hermite.tcc
    00032  *  This is an internal header file, included by other library headers.
    00033  *  You should not attempt to use it directly.
    00034  */
    00035
    00036 //
    00037 // ISO C++ 14882 TR1: 5.2  Special functions
    00038 //
    00039
    00040 // Written by Edward Smith-Rowland based on:
    00041 //   (1) Handbook of Mathematical Functions,
    00042 //       Ed. Milton Abramowitz and Irene A. Stegun,
    00043 //       Dover Publications, Section 22 pp. 773-802
    00044
    00045 #ifndef _GLIBCXX_TR1_POLY_HERMITE_TCC
    00046 #define _GLIBCXX_TR1_POLY_HERMITE_TCC 1
    00047
    00048 namespace std
    00049 {
    00050 namespace tr1
    00051 {
    00052
    00053   // [5.2] Special functions
    00054
    00055   // Implementation-space details.
    00056   namespace __detail
    00057   {
    00058
    00059     /**
    00060      *   @brief This routine returns the Hermite polynomial
    00061      *          of order n: \f$ H_n(x) \f$ by recursion on n.
    00062      *
    00063      *   The Hermite polynomial is defined by:
    00064      *   @f[
    00065      *     H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
    00066      *   @f]
    00067      *
    00068      *   @param __n The order of the Hermite polynomial.
    00069      *   @param __x The argument of the Hermite polynomial.
    00070      *   @return The value of the Hermite polynomial of order n
    00071      *           and argument x.
    00072      */
    00073     template<typename _Tp>
    00074     _Tp
    00075     __poly_hermite_recursion(const unsigned int __n, const _Tp __x)
    00076     {
    00077       //  Compute H_0.
    00078       _Tp __H_0 = 1;
    00079       if (__n == 0)
    00080         return __H_0;
    00081
    00082       //  Compute H_1.
    00083       _Tp __H_1 = 2 * __x;
    00084       if (__n == 1)
    00085         return __H_1;
    00086
    00087       //  Compute H_n.
    00088       _Tp __H_n, __H_nm1, __H_nm2;
    00089       unsigned int __i;
    00090       for  (__H_nm2 = __H_0, __H_nm1 = __H_1, __i = 2; __i <= __n; ++__i)
    00091         {
    00092           __H_n = 2 * (__x * __H_nm1 + (__i - 1) * __H_nm2);
    00093           __H_nm2 = __H_nm1;
    00094           __H_nm1 = __H_n;
    00095         }
    00096
    00097       return __H_n;
    00098     }
    00099
    00100
    00101     /**
    00102      *   @brief This routine returns the Hermite polynomial
    00103      *          of order n: \f$ H_n(x) \f$.
    00104      *
    00105      *   The Hermite polynomial is defined by:
    00106      *   @f[
    00107      *     H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
    00108      *   @f]
    00109      *
    00110      *   @param __n The order of the Hermite polynomial.
    00111      *   @param __x The argument of the Hermite polynomial.
    00112      *   @return The value of the Hermite polynomial of order n
    00113      *           and argument x.
    00114      */
    00115     template<typename _Tp>
    00116     inline _Tp
    00117     __poly_hermite(const unsigned int __n, const _Tp __x)
    00118     {
    00119       if (__isnan(__x))
    00120         return std::numeric_limits<_Tp>::quiet_NaN();
    00121       else
    00122         return __poly_hermite_recursion(__n, __x);
    00123     }
    00124
    00125   } // namespace std::tr1::__detail
    00126 }
    00127 }
    00128
    00129 #endif // _GLIBCXX_TR1_POLY_HERMITE_TCC