Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. // Special functions -*- C++ -*-
  2.  
  3. // Copyright (C) 2006-2015 Free Software Foundation, Inc.
  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
  8. // Free Software Foundation; either version 3, or (at your option)
  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. //
  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/>.
  24.  
  25. /** @file tr1/poly_hermite.tcc
  26.  *  This is an internal header file, included by other library headers.
  27.  *  Do not attempt to use it directly. @headername{tr1/cmath}
  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.  
  39. #ifndef _GLIBCXX_TR1_POLY_HERMITE_TCC
  40. #define _GLIBCXX_TR1_POLY_HERMITE_TCC 1
  41.  
  42. namespace std _GLIBCXX_VISIBILITY(default)
  43. {
  44. namespace tr1
  45. {
  46.   // [5.2] Special functions
  47.  
  48.   // Implementation-space details.
  49.   namespace __detail
  50.   {
  51.   _GLIBCXX_BEGIN_NAMESPACE_VERSION
  52.  
  53.     /**
  54.      *   @brief This routine returns the Hermite polynomial
  55.      *          of order n: \f$ H_n(x) \f$ by recursion on n.
  56.      *
  57.      *   The Hermite polynomial is defined by:
  58.      *   @f[
  59.      *     H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
  60.      *   @f]
  61.      *
  62.      *   @param __n The order of the Hermite polynomial.
  63.      *   @param __x The argument of the Hermite polynomial.
  64.      *   @return The value of the Hermite polynomial of order n
  65.      *           and argument x.
  66.      */
  67.     template<typename _Tp>
  68.     _Tp
  69.     __poly_hermite_recursion(unsigned int __n, _Tp __x)
  70.     {
  71.       //  Compute H_0.
  72.       _Tp __H_0 = 1;
  73.       if (__n == 0)
  74.         return __H_0;
  75.  
  76.       //  Compute H_1.
  77.       _Tp __H_1 = 2 * __x;
  78.       if (__n == 1)
  79.         return __H_1;
  80.  
  81.       //  Compute H_n.
  82.       _Tp __H_n, __H_nm1, __H_nm2;
  83.       unsigned int __i;
  84.       for  (__H_nm2 = __H_0, __H_nm1 = __H_1, __i = 2; __i <= __n; ++__i)
  85.         {
  86.           __H_n = 2 * (__x * __H_nm1 - (__i - 1) * __H_nm2);
  87.           __H_nm2 = __H_nm1;
  88.           __H_nm1 = __H_n;
  89.         }
  90.  
  91.       return __H_n;
  92.     }
  93.  
  94.  
  95.     /**
  96.      *   @brief This routine returns the Hermite polynomial
  97.      *          of order n: \f$ H_n(x) \f$.
  98.      *
  99.      *   The Hermite polynomial is defined by:
  100.      *   @f[
  101.      *     H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
  102.      *   @f]
  103.      *
  104.      *   @param __n The order of the Hermite polynomial.
  105.      *   @param __x The argument of the Hermite polynomial.
  106.      *   @return The value of the Hermite polynomial of order n
  107.      *           and argument x.
  108.      */
  109.     template<typename _Tp>
  110.     inline _Tp
  111.     __poly_hermite(unsigned int __n, _Tp __x)
  112.     {
  113.       if (__isnan(__x))
  114.         return std::numeric_limits<_Tp>::quiet_NaN();
  115.       else
  116.         return __poly_hermite_recursion(__n, __x);
  117.     }
  118.  
  119.   _GLIBCXX_END_NAMESPACE_VERSION
  120.   } // namespace std::tr1::__detail
  121. }
  122. }
  123.  
  124. #endif // _GLIBCXX_TR1_POLY_HERMITE_TCC
  125.