#ifndef SPROUT_MATH_ASIN_HPP #define SPROUT_MATH_ASIN_HPP #include #include #include #include #include #include #include #include #if SPROUT_USE_BUILTIN_CMATH_FUNCTION # include #endif namespace sprout { namespace math { namespace detail { template inline SPROUT_CONSTEXPR T asin_impl_2(T x, T tmp, std::size_t n, T x2n1, T _4n) { return 2 * n > sprout::math::factorial_limit() ? tmp : sprout::math::detail::asin_impl_2( x, tmp + sprout::math::factorial(2 * n) / _4n / sprout::math::factorial(n) / sprout::math::factorial(n) / (2 * n + 1) * x2n1 , n + 1, x2n1 * x * x, _4n * 4 ) ; } template inline SPROUT_CONSTEXPR T asin_impl_1(T x) { return sprout::math::detail::asin_impl_2( x, x, 1, x * x * x, T(4) ); } template inline SPROUT_CONSTEXPR T asin_impl(T x) { return x > sprout::math::half_root_two() ? sprout::math::half_pi() - sprout::math::detail::asin_impl_1(sprout::math::sqrt(1 - x * x)) : sprout::math::detail::asin_impl_1(x) ; } template< typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType asin(FloatType x) { typedef double type; return x > 1 || x < -1 ? std::numeric_limits::quiet_NaN() : x < 0 ? -static_cast(sprout::math::detail::asin_impl(static_cast(-x))) : static_cast(sprout::math::detail::asin_impl(static_cast(x))) ; } template< typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR double asin(IntType x) { return sprout::math::detail::asin(static_cast(x)); } } // namespace detail # if SPROUT_USE_BUILTIN_CMATH_FUNCTION using std::asin; # else using sprout::math::detail::asin; # endif } // namespace math using sprout::math::asin; } // namespace sprout #endif // #ifndef SPROUT_MATH_ASIN_HPP