/*============================================================================= Copyright (c) 2011-2017 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_COMPLEX_ACOS_HPP #define SPROUT_COMPLEX_ACOS_HPP #include #include #include #include #include #include #include #include namespace sprout { // // acos // // G.6.1.1 The cacos functions // cacos(conj(z)) = conj(cacos(z)). // cacos(}0 + i0) returns p /2 - i0. // cacos(}0 + iNaN) returns p /2 + iNaN. // cacos(x + i‡) returns p /2 - i‡, for finite x. // cacos(x + iNaN) returns NaN + iNaN and optionally raises the eeinvalidff floating-point exception, for nonzero finite x. // cacos(-‡+ iy) returns p - i‡, for positive-signed finite y. // cacos(+‡+ iy) returns +0 - i‡, for positive-signed finite y. // cacos(-‡+ i‡) returns 3p /4 - i‡. // cacos(+‡+ i‡) returns p /4 - i‡. // cacos(}‡+ iNaN) returns NaN } i‡ (where the sign of the imaginary part of the result is unspecified). // cacos(NaN + iy) returns NaN + iNaN and optionally raises the eeinvalidff floating-point exception, for finite y. // cacos(NaN + i‡) returns NaN - i‡. // cacos(NaN + iNaN) returns NaN + iNaN. // namespace detail { template inline SPROUT_CONSTEXPR sprout::complex acos_impl(sprout::complex const& t) { return sprout::complex(sprout::math::half_pi() - t.real(), -t.imag()); } } // namespace detail template inline SPROUT_CONSTEXPR sprout::complex acos(sprout::complex const& x) { typedef sprout::complex type; return sprout::math::isnan(x.real()) ? sprout::math::isnan(x.imag()) ? x : sprout::math::isinf(x.imag()) ? type(x.real(), -x.imag()) : type(x.real(), sprout::numeric_limits::quiet_NaN()) : sprout::math::isnan(x.imag()) ? sprout::math::isinf(x.real()) ? type(sprout::numeric_limits::quiet_NaN(), x.real()) : x.real() == 0 ? type(sprout::math::half_pi(), x.imag()) : type(sprout::numeric_limits::quiet_NaN(), sprout::numeric_limits::quiet_NaN()) : x.real() == sprout::numeric_limits::infinity() ? sprout::math::isinf(x.imag()) ? type(sprout::math::quarter_pi(), -x.imag()) : type(T(0), sprout::math::copysign(sprout::numeric_limits::infinity(), -x.imag())) : x.real() == -sprout::numeric_limits::infinity() ? sprout::math::isinf(x.imag()) ? type(sprout::math::three_quarters_pi(), -x.imag()) : type(sprout::math::pi(), sprout::math::copysign(sprout::numeric_limits::infinity(), -x.imag())) : sprout::math::isinf(x.imag()) ? type(sprout::math::half_pi(), sprout::math::copysign(sprout::numeric_limits::infinity(), -x.imag())) : x.real() == 0 && x.imag() == 0 ? type(sprout::math::half_pi(), -x.imag()) : sprout::detail::acos_impl(sprout::asin(x)) ; } } // namespace sprout #endif // #ifndef SPROUT_COMPLEX_ACOS_HPP