// 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_LAGUERRE_HPP #define BOOST_DECIMAL_DETAIL_CMATH_LAGUERRE_HPP #include #include #include #include #include #ifndef BOOST_DECIMAL_BUILD_MODULE #include #include #endif namespace boost { namespace decimal { namespace detail { template constexpr auto laguerre_next(const unsigned n, const T1 x, const T2 Ln, const T3 Lnm1) { using promoted_type = promote_args_t; return ((2 * n + 1 - static_cast(x)) * static_cast(Ln) - n * static_cast(Lnm1)) / (n + 1); } // Implement Laguerre polynomials via recurrence: template constexpr auto laguerre_impl(const unsigned n, const T x) { T p0 {UINT64_C(1)}; T p1 {UINT64_C(1) - x}; if (n == 0) { return p0; } unsigned c = 1; while(c < n) { std::swap(p0, p1); p1 = laguerre_next(c, x, p0, p1); ++c; } return p1; } } //namespace detail BOOST_DECIMAL_EXPORT template constexpr auto laguerre(const unsigned n, const T x) BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T) { using evaluation_type = detail::evaluation_type_t; return static_cast(detail::laguerre_impl(n, static_cast(x))); } } //namespace decimal } //namespace boost #endif //BOOST_DECIMAL_DETAIL_CMATH_LAGUERRE_HPP