/*============================================================================= 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_POW_HPP #define SPROUT_COMPLEX_POW_HPP #include #include #include #include #include #include namespace sprout { // // pow // // G.6.4.1 The cpow functions // 1 The cpow functions raise floating-point exceptions if appropriate for the calculation of // the parts of the result, and may raise spurious exceptions.317) // // 317) This allows cpow(z, c) to be implemented as cexp(c clog(z)) without precluding // implementations that treat special cases more carefully. // template inline SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, sprout::complex const& y) { return x == T() ? T() : sprout::exp(y * sprout::log(x)) ; } namespace detail { template inline SPROUT_CONSTEXPR sprout::complex pow_impl(sprout::complex const& t, T const& y) { return sprout::polar(sprout::exp(y * t.real()), y * t.imag()); } } // namespace detail template inline SPROUT_CONSTEXPR sprout::complex pow(sprout::complex const& x, T const& y) { return x == T() ? T() : x.imag() == T() && x.real() > T() ? sprout::math::pow(x.real(), y) : sprout::detail::pow_impl(sprout::log(x), y) ; } template inline SPROUT_CONSTEXPR sprout::complex pow(T const& x, sprout::complex const& y) { return x > T() ? sprout::polar(sprout::pow(x, y.real()), y.imag() * sprout::log(x)) : sprout::pow(sprout::complex(x), y) ; } } // namespace sprout #endif // #ifndef SPROUT_COMPLEX_POW_HPP