| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifndef _LIBCPP___MATH_SPECIAL_FUNCTIONS_H |
| #define _LIBCPP___MATH_SPECIAL_FUNCTIONS_H |
|
|
| #include <__config> |
| #include <__math/copysign.h> |
| #include <__math/traits.h> |
| #include <__type_traits/enable_if.h> |
| #include <__type_traits/is_integral.h> |
| #include <limits> |
|
|
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| # pragma GCC system_header |
| #endif |
|
|
| _LIBCPP_BEGIN_NAMESPACE_STD |
|
|
| #if _LIBCPP_STD_VER >= 17 |
|
|
| template <class _Real> |
| _LIBCPP_HIDE_FROM_ABI _Real __hermite(unsigned __n, _Real __x) { |
| |
| |
| |
| |
|
|
| |
| if (__math::isnan(__x)) |
| return __x; |
|
|
| _Real __H_0{1}; |
| if (__n == 0) |
| return __H_0; |
|
|
| _Real __H_n_prev = __H_0; |
| _Real __H_n = 2 * __x; |
| for (unsigned __i = 1; __i < __n; ++__i) { |
| _Real __H_n_next = 2 * (__x * __H_n - __i * __H_n_prev); |
| __H_n_prev = __H_n; |
| __H_n = __H_n_next; |
| } |
|
|
| if (!__math::isfinite(__H_n)) { |
| |
| |
| |
| _Real __inf = std::numeric_limits<_Real>::infinity(); |
| return (__n & 1) ? __math::copysign(__inf, __x) : __inf; |
| } |
| return __H_n; |
| |
| } |
|
|
| inline _LIBCPP_HIDE_FROM_ABI double hermite(unsigned __n, double __x) { return std::__hermite(__n, __x); } |
|
|
| inline _LIBCPP_HIDE_FROM_ABI float hermite(unsigned __n, float __x) { |
| |
| return static_cast<float>(std::hermite(__n, static_cast<double>(__x))); |
| } |
|
|
| inline _LIBCPP_HIDE_FROM_ABI long double hermite(unsigned __n, long double __x) { return std::__hermite(__n, __x); } |
|
|
| inline _LIBCPP_HIDE_FROM_ABI float hermitef(unsigned __n, float __x) { return std::hermite(__n, __x); } |
|
|
| inline _LIBCPP_HIDE_FROM_ABI long double hermitel(unsigned __n, long double __x) { return std::hermite(__n, __x); } |
|
|
| template <class _Integer, std::enable_if_t<std::is_integral_v<_Integer>, int> = 0> |
| _LIBCPP_HIDE_FROM_ABI double hermite(unsigned __n, _Integer __x) { |
| return std::hermite(__n, static_cast<double>(__x)); |
| } |
|
|
| #endif |
|
|
| _LIBCPP_END_NAMESPACE_STD |
|
|
| #endif |
|
|