// Copyright 2006 John Maddock // Copyright 2024 Matt Borland // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #ifndef BOOST_DECIMAL_DETAIL_CMATH_HERMITE_HPP #define BOOST_DECIMAL_DETAIL_CMATH_HERMITE_HPP #include #include #include #include #include #ifndef BOOST_DECIMAL_BUILD_MODULE #include #include #endif namespace boost { namespace decimal { namespace detail { template constexpr auto hermite_next(const unsigned n, const T1 x, const T2 Hn, const T3 Hnm1) { using promoted_type = promote_args_t; return 2 * static_cast(x) * static_cast(Hn) - 2 * n * static_cast(Hnm1); } template constexpr auto hermite_impl(const unsigned n, const T x) noexcept BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T) { T p0 {UINT64_C(1)}; T p1 {UINT64_C(2) * x}; if (n == 0) { return p0; } unsigned c = 1; while (c < n) { std::swap(p0, p1); p1 = static_cast(hermite_next(c, x, p0, p1)); ++c; } return p1; } } //namespace detail BOOST_DECIMAL_EXPORT template constexpr auto hermite(const unsigned n, const T x) noexcept BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T) { using evaluation_type = detail::evaluation_type_t; return static_cast(detail::hermite_impl(n, static_cast(x))); } } //namespace decimal } //namespace boost #endif //BOOST_DECIMAL_DETAIL_CMATH_HERMITE_HPP