#ifndef SPROUT_MATH_COS_HPP #define SPROUT_MATH_COS_HPP #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::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 FloatType cos_impl(FloatType x) { typedef typename sprout::math::detail::float_compute::type type; return static_cast( type(1) + sprout::math::detail::cos_impl_1( sprout::detail::pow2(static_cast(x)), 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 == 0 ? FloatType(1) : x == std::numeric_limits::infinity() || x == -std::numeric_limits::infinity() ? std::numeric_limits::quiet_NaN() : sprout::math::detail::cos_impl(sprout::math::fmod(x, sprout::math::two_pi())) ; } 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 using NS_SPROUT_MATH_DETAIL::cos; } // namespace math using sprout::math::cos; } // namespace sprout #endif // #ifndef SPROUT_MATH_COS_HPP