/*============================================================================= Copyright (c) 2011-2014 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_VALUES_HPP #define SPROUT_COMPLEX_VALUES_HPP #include #include #include #include #include #include #include namespace sprout { template SPROUT_CONSTEXPR T norm(sprout::complex const& x); // 26.4.7, values: template inline SPROUT_CONSTEXPR T const& real(sprout::complex const& x) { return x.real(); } template inline SPROUT_CONSTEXPR T const& imag(sprout::complex const& x) { return x.imag(); } template inline SPROUT_CXX14_CONSTEXPR T& real(sprout::complex& x) { return x.real(); } template inline SPROUT_CXX14_CONSTEXPR T& imag(sprout::complex& x) { return x.imag(); } template inline SPROUT_CONSTEXPR T abs(sprout::complex const& x) { return sprout::sqrt(sprout::norm(x)); } template inline SPROUT_CONSTEXPR T arg(sprout::complex const& x) { return sprout::atan2(x.imag(), x.real()); } template inline SPROUT_CONSTEXPR T norm(sprout::complex const& x) { return x.real() * x.real() + x.imag() * x.imag(); } template inline SPROUT_CONSTEXPR sprout::complex conj(sprout::complex const& x) { return sprout::complex(x.real(), -x.imag()); } namespace detail { template inline SPROUT_CONSTEXPR sprout::complex proj_impl(sprout::complex const& x, T const& den) { return sprout::complex( T(2) * x.real() / den, T(2) * x.imag() / den ); } } // detail template inline SPROUT_CONSTEXPR sprout::complex proj(sprout::complex const& x) { return sprout::detail::proj_impl( x, sprout::norm(x) + T(1) ); } template inline SPROUT_CONSTEXPR sprout::complex polar(T const& rho, T const& theta = 0) { return sprout::complex(rho * sprout::cos(theta), rho * sprout::sin(theta)); } } // namespace sprout #endif // #ifndef SPROUT_COMPLEX_VALUES_HPP