2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2014-01-08 07:48:12 +00:00
|
|
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2012-08-28 16:16:12 +00:00
|
|
|
#ifndef SPROUT_COMPLEX_VALUES_HPP
|
|
|
|
#define SPROUT_COMPLEX_VALUES_HPP
|
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/complex/complex.hpp>
|
|
|
|
#include <sprout/complex/operators.hpp>
|
|
|
|
#include <sprout/math/sin.hpp>
|
|
|
|
#include <sprout/math/cos.hpp>
|
|
|
|
#include <sprout/math/atan2.hpp>
|
|
|
|
#include <sprout/math/sqrt.hpp>
|
2014-07-12 17:49:50 +00:00
|
|
|
#include <sprout/math/isinf.hpp>
|
|
|
|
#include <sprout/math/copysign.hpp>
|
|
|
|
#include <sprout/limits.hpp>
|
2012-08-28 16:16:12 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR T
|
|
|
|
norm(sprout::complex<T> const& x);
|
2012-08-28 16:16:12 +00:00
|
|
|
|
|
|
|
// 26.4.7, values:
|
|
|
|
template<typename T>
|
2014-04-18 02:34:28 +00:00
|
|
|
inline SPROUT_CONSTEXPR T const&
|
2012-10-05 15:58:56 +00:00
|
|
|
real(sprout::complex<T> const& x) {
|
2012-08-28 16:16:12 +00:00
|
|
|
return x.real();
|
|
|
|
}
|
|
|
|
template<typename T>
|
2014-04-18 02:34:28 +00:00
|
|
|
inline SPROUT_CONSTEXPR T const&
|
2012-10-05 15:58:56 +00:00
|
|
|
imag(sprout::complex<T> const& x) {
|
2012-08-28 16:16:12 +00:00
|
|
|
return x.imag();
|
|
|
|
}
|
|
|
|
template<typename T>
|
2014-04-18 10:33:48 +00:00
|
|
|
inline SPROUT_CONSTEXPR T&
|
2014-04-18 02:34:28 +00:00
|
|
|
real(sprout::complex<T>& x) {
|
|
|
|
return x.real();
|
|
|
|
}
|
|
|
|
template<typename T>
|
2014-04-18 10:33:48 +00:00
|
|
|
inline SPROUT_CONSTEXPR T&
|
2014-04-18 02:34:28 +00:00
|
|
|
imag(sprout::complex<T>& x) {
|
|
|
|
return x.imag();
|
|
|
|
}
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR T
|
|
|
|
abs(sprout::complex<T> const& x) {
|
2012-08-28 16:16:12 +00:00
|
|
|
return sprout::sqrt(sprout::norm(x));
|
|
|
|
}
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR T
|
|
|
|
arg(sprout::complex<T> const& x) {
|
2012-08-28 16:16:12 +00:00
|
|
|
return sprout::atan2(x.imag(), x.real());
|
|
|
|
}
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR T
|
|
|
|
norm(sprout::complex<T> const& x) {
|
2012-08-28 16:16:12 +00:00
|
|
|
return x.real() * x.real() + x.imag() * x.imag();
|
|
|
|
}
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::complex<T>
|
|
|
|
conj(sprout::complex<T> const& x) {
|
2012-08-28 16:16:12 +00:00
|
|
|
return sprout::complex<T>(x.real(), -x.imag());
|
|
|
|
}
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::complex<T>
|
|
|
|
proj(sprout::complex<T> const& x) {
|
2014-07-12 17:49:50 +00:00
|
|
|
return sprout::isinf(x.real()) || sprout::isinf(x.imag())
|
|
|
|
? sprout::complex<T>(sprout::numeric_limits<T>::infinity(), sprout::copysign(T(), x.imag()))
|
|
|
|
: x;
|
2012-08-28 16:16:12 +00:00
|
|
|
}
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::complex<T>
|
|
|
|
polar(T const& rho, T const& theta = 0) {
|
2012-08-28 16:16:12 +00:00
|
|
|
return sprout::complex<T>(rho * sprout::cos(theta), rho * sprout::sin(theta));
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_COMPLEX_VALUES_HPP
|