// 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_ACOS_HPP #define BOOST_DECIMAL_DETAIL_CMATH_ACOS_HPP #include #include #include #include #include #include #include #include #include #ifndef BOOST_DECIMAL_BUILD_MODULE #include #include #endif namespace boost { namespace decimal { namespace detail { template constexpr auto acos_impl(const T x) noexcept BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T) { #ifndef BOOST_DECIMAL_FAST_MATH if (isnan(x)) { return x; } #endif constexpr auto half_pi {numbers::pi_v / 2}; const auto absx {fabs(static_cast(x))}; T result {}; if (absx > 1) { result = std::numeric_limits::quiet_NaN(); } else if (x < T{-5, -1}) { result = numbers::pi_v - 2 * detail::asin_series(sqrt((1 - absx) / 2)); } else if (x < -std::numeric_limits::epsilon()) { result = half_pi + detail::asin_series(absx); } else if (x < T{5, -1}) { result = half_pi - detail::asin_series(x); } else { result = half_pi - (half_pi - 2 * detail::asin_series(sqrt((1 - x) / 2))); } return result; } } // namespace detail BOOST_DECIMAL_EXPORT template constexpr auto acos(const T x) noexcept BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T) { using evaluation_type = detail::evaluation_type_t; return static_cast(detail::acos_impl(static_cast(x))); } } //namespace decimal } //namespace boost #endif //BOOST_DECIMAL_DETAIL_CMATH_ACOS_HPP