#ifndef SPROUT_MATH_COS_HPP #define SPROUT_MATH_COS_HPP #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace math { namespace detail { template inline SPROUT_CONSTEXPR T cos_impl_1(T x2, std::size_t n, std::size_t last) { return last - n == 1 ? (n % 2 ? -1 : 1) * sprout::detail::pow_n(x2, n) / sprout::math::unchecked_factorial(2 * n) : sprout::math::detail::cos_impl_1(x2, n, n + (last - n) / 2) + sprout::math::detail::cos_impl_1(x2, n + (last - n) / 2, last) ; } template inline SPROUT_CONSTEXPR T cos_impl(T x) { return T(1) + sprout::math::detail::cos_impl_1( sprout::detail::pow2(sprout::math::fmod(x, sprout::math::two_pi())), 1, sprout::math::factorial_limit() / 2 + 1 ); } template< typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType cos(FloatType x) { return x == std::numeric_limits::infinity() || x == -std::numeric_limits::infinity() ? std::numeric_limits::quiet_NaN() #if SPROUT_USE_BUILTIN_CMATH_FUNCTION : std::cos(x) #else : x == 0 ? FloatType(1) : static_cast(sprout::math::detail::cos_impl(static_cast::type>(x))) #endif ; } template< typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR double cos(IntType x) { return sprout::math::detail::cos(static_cast(x)); } } // namespace detail // // cos // template< typename ArithmeticType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR typename sprout::float_promote::type cos(ArithmeticType x) { return sprout::math::detail::cos(x); } } // namespace math using sprout::math::cos; } // namespace sprout #endif // #ifndef SPROUT_MATH_COS_HPP