You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 line
3.8KB

  1. // Special functions -*- C++ -*-
  2. // Copyright (C) 2006-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // Under Section 7 of GPL version 3, you are granted additional
  16. // permissions described in the GCC Runtime Library Exception, version
  17. // 3.1, as published by the Free Software Foundation.
  18. // You should have received a copy of the GNU General Public License and
  19. // a copy of the GCC Runtime Library Exception along with this program;
  20. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  21. // <http://www.gnu.org/licenses/>.
  22. /** @file tr1/poly_hermite.tcc
  23. * This is an internal header file, included by other library headers.
  24. * Do not attempt to use it directly. @headername{tr1/cmath}
  25. */
  26. //
  27. // ISO C++ 14882 TR1: 5.2 Special functions
  28. //
  29. // Written by Edward Smith-Rowland based on:
  30. // (1) Handbook of Mathematical Functions,
  31. // Ed. Milton Abramowitz and Irene A. Stegun,
  32. // Dover Publications, Section 22 pp. 773-802
  33. #ifndef _GLIBCXX_TR1_POLY_HERMITE_TCC
  34. #define _GLIBCXX_TR1_POLY_HERMITE_TCC 1
  35. namespace std _GLIBCXX_VISIBILITY(default)
  36. {
  37. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  38. #if _GLIBCXX_USE_STD_SPEC_FUNCS
  39. #elif defined(_GLIBCXX_TR1_CMATH)
  40. namespace tr1
  41. {
  42. #else
  43. # error do not include this header directly, use <cmath> or <tr1/cmath>
  44. #endif
  45. // [5.2] Special functions
  46. // Implementation-space details.
  47. namespace __detail
  48. {
  49. /**
  50. * @brief This routine returns the Hermite polynomial
  51. * of order n: \f$ H_n(x) \f$ by recursion on n.
  52. *
  53. * The Hermite polynomial is defined by:
  54. * @f[
  55. * H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
  56. * @f]
  57. *
  58. * @param __n The order of the Hermite polynomial.
  59. * @param __x The argument of the Hermite polynomial.
  60. * @return The value of the Hermite polynomial of order n
  61. * and argument x.
  62. */
  63. template<typename _Tp>
  64. _Tp
  65. __poly_hermite_recursion(unsigned int __n, _Tp __x)
  66. {
  67. // Compute H_0.
  68. _Tp __H_0 = 1;
  69. if (__n == 0)
  70. return __H_0;
  71. // Compute H_1.
  72. _Tp __H_1 = 2 * __x;
  73. if (__n == 1)
  74. return __H_1;
  75. // Compute H_n.
  76. _Tp __H_n, __H_nm1, __H_nm2;
  77. unsigned int __i;
  78. for (__H_nm2 = __H_0, __H_nm1 = __H_1, __i = 2; __i <= __n; ++__i)
  79. {
  80. __H_n = 2 * (__x * __H_nm1 - (__i - 1) * __H_nm2);
  81. __H_nm2 = __H_nm1;
  82. __H_nm1 = __H_n;
  83. }
  84. return __H_n;
  85. }
  86. /**
  87. * @brief This routine returns the Hermite polynomial
  88. * of order n: \f$ H_n(x) \f$.
  89. *
  90. * The Hermite polynomial is defined by:
  91. * @f[
  92. * H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2}
  93. * @f]
  94. *
  95. * @param __n The order of the Hermite polynomial.
  96. * @param __x The argument of the Hermite polynomial.
  97. * @return The value of the Hermite polynomial of order n
  98. * and argument x.
  99. */
  100. template<typename _Tp>
  101. inline _Tp
  102. __poly_hermite(unsigned int __n, _Tp __x)
  103. {
  104. if (__isnan(__x))
  105. return std::numeric_limits<_Tp>::quiet_NaN();
  106. else
  107. return __poly_hermite_recursion(__n, __x);
  108. }
  109. } // namespace __detail
  110. #if ! _GLIBCXX_USE_STD_SPEC_FUNCS && defined(_GLIBCXX_TR1_CMATH)
  111. } // namespace tr1
  112. #endif
  113. _GLIBCXX_END_NAMESPACE_VERSION
  114. }
  115. #endif // _GLIBCXX_TR1_POLY_HERMITE_TCC