/*============================================================================= Copyright (c) 2011-2018 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_POLER_HPP #define SPROUT_COMPLEX_POLER_HPP #include #include #include #include #include #include #include #include #include #include #include namespace sprout { // // polar // namespace detail { template inline SPROUT_CONSTEXPR sprout::complex polar_impl(T const& x, T const& y) { return sprout::complex( sprout::math::isnan(x) ? T() : x, sprout::math::isnan(y) ? T() : y ); } } // namespace detail template inline SPROUT_CONSTEXPR sprout::complex polar(T const& rho, T const& theta = T()) { typedef sprout::complex type; return sprout::math::isnan(rho) || sprout::math::signbit(rho) ? type(sprout::numeric_limits::quiet_NaN(), sprout::numeric_limits::quiet_NaN()) : sprout::math::isnan(theta) ? sprout::math::isinf(rho) ? type(rho, theta) : type(theta, theta) : sprout::math::isinf(theta) ? sprout::math::isinf(rho) ? type(rho, sprout::numeric_limits::quiet_NaN()) : type(sprout::numeric_limits::quiet_NaN(), sprout::numeric_limits::quiet_NaN()) : sprout::detail::polar_impl(rho * sprout::math::cos(theta), rho * sprout::math::sin(theta)) ; } template< typename ArithmeticType1, typename ArithmeticType2, typename sprout::enabler_if::value && std::is_arithmetic::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR typename sprout::complex_promote::type polar(ArithmeticType1 const& rho, ArithmeticType2 const& theta) { typedef typename sprout::complex_promote::type::value_type value_type; return sprout::polar(static_cast(rho), static_cast(theta)); } } // namespace sprout #endif // #ifndef SPROUT_COMPLEX_POLER_HPP