brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 3d77fc0 Raw
80 lines · plain
1 2//  (C) Copyright John Maddock 2006.3//  (C) Copyright Matt Borland 2024.4//  Use, modification and distribution are subject to the5//  Boost Software License, Version 1.0. (See accompanying file6//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)7 8#ifndef BOOST_MATH_SPECIAL_HERMITE_HPP9#define BOOST_MATH_SPECIAL_HERMITE_HPP10 11#ifdef _MSC_VER12#pragma once13#endif14 15#include <boost/math/tools/config.hpp>16#include <boost/math/tools/promotion.hpp>17#include <boost/math/special_functions/math_fwd.hpp>18#include <boost/math/policies/error_handling.hpp>19 20namespace boost{21namespace math{22 23// Recurrence relation for Hermite polynomials:24template <class T1, class T2, class T3>25BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2, T3>::type 26   hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1)27{28   using promoted_type = tools::promote_args_t<T1, T2, T3>;29   return (2 * promoted_type(x) * promoted_type(Hn) - 2 * n * promoted_type(Hnm1));30}31 32namespace detail{33 34// Implement Hermite polynomials via recurrence:35template <class T>36BOOST_MATH_GPU_ENABLED T hermite_imp(unsigned n, T x)37{38   T p0 = 1;39   T p1 = 2 * x;40 41   if(n == 0)42      return p0;43 44   unsigned c = 1;45 46   while(c < n)47   {48      BOOST_MATH_GPU_SAFE_SWAP(p0, p1);49      p1 = static_cast<T>(hermite_next(c, x, p0, p1));50      ++c;51   }52   return p1;53}54 55} // namespace detail56 57template <class T, class Policy>58BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type 59   hermite(unsigned n, T x, const Policy&)60{61   typedef typename tools::promote_args<T>::type result_type;62   typedef typename policies::evaluation<result_type, Policy>::type value_type;63   return policies::checked_narrowing_cast<result_type, Policy>(detail::hermite_imp(n, static_cast<value_type>(x)), "boost::math::hermite<%1%>(unsigned, %1%)");64}65 66template <class T>67BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type 68   hermite(unsigned n, T x)69{70   return boost::math::hermite(n, x, policies::policy<>());71}72 73} // namespace math74} // namespace boost75 76#endif // BOOST_MATH_SPECIAL_HERMITE_HPP77 78 79 80