13 #include <type_traits>
42 static_assert(std::is_floating_point_v<T>);
58 : m_real(static_cast<T>(other.
real()))
59 , m_imag(static_cast<T>(other.
imag()))
65 : m_real(other.
real())
66 , m_imag(other.
imag())
73 return std::complex<T>{m_real, m_imag};
114 m_real +=
static_cast<T
>(other.
real());
115 m_imag +=
static_cast<T
>(other.
imag());
130 m_real -=
static_cast<T
>(other.
real());
131 m_imag -=
static_cast<T
>(other.
imag());
147 auto const newReal = m_real *
static_cast<T
>(other.
real()) - m_imag *
static_cast<T
>(other.
imag());
148 auto const newImag = m_imag *
static_cast<T
>(other.
real()) + m_real *
static_cast<T
>(other.
imag());
320 return !(lhs == rhs);
342 template<
typename T,
typename TChar,
typename TTraits>
343 std::basic_ostream<TChar, TTraits>&
operator<<(std::basic_ostream<TChar, TTraits>& os,
Complex<T> const& x)
345 os << x.operator std::complex<T>();
350 template<
typename T,
typename TChar,
typename TTraits>
380 return std::abs(std::complex<T>(x));
404 return std::arg(std::complex<T>(x));
452 return std::cos(std::complex<T>(x));
468 return std::exp(std::complex<T>(x));
476 return std::log(std::complex<T>(x));
505 template<
typename T,
typename U>
509 auto const result =
std::pow(std::complex<T>(x), std::complex<U>(y));
510 using ValueType =
typename decltype(result)::value_type;
516 template<
typename T,
typename U>
524 template<
typename T,
typename U>
543 return std::sin(std::complex<T>(x));
567 return std::tan(std::complex<T>(x));
581 using internal::Complex;
Implementation of a complex number useable on host and device.
constexpr ALPAKA_FN_HOST_ACC T imag() const
Get the imaginary part.
constexpr ALPAKA_FN_HOST_ACC T real() const
Get the real part.
ALPAKA_FN_HOST_ACC Complex & operator-=(Complex< U > const &other)
Subtraction assignment with a complex number.
ALPAKA_FN_HOST_ACC Complex & operator/=(Complex< U > const &other)
Division assignment with a complex number.
constexpr ALPAKA_FN_HOST_ACC void imag(T value)
Set the imaginary part.
constexpr Complex(Complex const &other)=default
Copy constructor.
ALPAKA_FN_HOST_ACC Complex & operator-=(T const &other)
Subtraction assignment with a real number.
constexpr ALPAKA_FN_HOST_ACC Complex(Complex< U > const &other)
Constructor from Complex of another type.
constexpr ALPAKA_FN_HOST_ACC void real(T value)
Set the real part.
constexpr ALPAKA_FN_HOST_ACC Complex(std::complex< T > const &other)
Constructor from std::complex.
ALPAKA_FN_HOST_ACC Complex & operator*=(T const &other)
Multiplication assignment with a real number.
ALPAKA_FN_HOST_ACC Complex & operator+=(T const &other)
Addition assignment with a real number.
constexpr ALPAKA_FN_HOST_ACC Complex(T const &real=T{}, T const &imag=T{})
Constructor from the given real and imaginary parts.
ALPAKA_FN_HOST_ACC Complex & operator/=(T const &other)
Division assignment with a real number.
ALPAKA_FN_HOST_ACC Complex & operator+=(Complex< U > const &other)
Addition assignment with a complex number.
Complex & operator=(Complex const &)=default
Assignment.
ALPAKA_FN_HOST_ACC Complex & operator*=(Complex< U > const &other)
Multiplication assignment with a complex number.
T value_type
Type of the real and imaginary parts.
#define ALPAKA_FN_HOST_ACC
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > tan(Complex< T > const &x)
Tangent.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > acosh(Complex< T > const &x)
Arc hyperbolic cosine.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > proj(Complex< T > const &x)
Projection onto the Riemann sphere.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > atanh(Complex< T > const &x)
Arc hyperbolic tangent.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto pow(T const &x, Complex< U > const &y)
Complex power of a real number.
constexpr ALPAKA_FN_HOST_ACC bool operator==(Complex< T > const &lhs, Complex< T > const &rhs)
Equality of two complex numbers.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > cosh(Complex< T > const &x)
Hyperbolic cosine.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > atan(Complex< T > const &x)
Arc tangent.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC T abs(Complex< T > const &x)
Host-only math functions matching std::complex<T>.
ALPAKA_FN_HOST_ACC Complex< T > operator/(Complex< T > const &lhs, Complex< T > const &rhs)
Division of two complex numbers.
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &os, Complex< T > const &x)
Host-only output of a complex number.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > log(Complex< T > const &x)
Natural logarithm.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > sinh(Complex< T > const &x)
Hyperbolic sine.
ALPAKA_FN_HOST_ACC Complex< T > operator*(Complex< T > const &lhs, Complex< T > const &rhs)
Muptiplication of two complex numbers.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > tanh(Complex< T > const &x)
Hyperbolic tangent.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > conj(Complex< T > const &x)
Complex conjugate.
ALPAKA_FN_HOST_ACC Complex< T > operator+(Complex< T > const &val)
Host-device arithmetic operations matching std::complex<T>.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > log10(Complex< T > const &x)
Base 10 logarithm.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC T arg(Complex< T > const &x)
Argument.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > polar(T const &r, T const &theta=T())
Get a complex number with given magnitude and phase angle.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > asinh(Complex< T > const &x)
Arc hyperbolic sine.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > cos(Complex< T > const &x)
Cosine.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC T norm(Complex< T > const &x)
Squared magnitude.
std::basic_istream< TChar, TTraits > & operator>>(std::basic_istream< TChar, TTraits > &is, Complex< T > const &x)
Host-only input of a complex number.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > asin(Complex< T > const &x)
Arc sine.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > exp(Complex< T > const &x)
Exponential.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto pow(Complex< T > const &x, Complex< U > const &y)
Complex power of a complex number.
constexpr ALPAKA_FN_HOST_ACC bool operator!=(Complex< T > const &lhs, Complex< T > const &rhs)
Inequality of two complex numbers.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > sqrt(Complex< T > const &x)
Square root.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > acos(Complex< T > const &x)
Arc cosine.
ALPAKA_FN_HOST_ACC Complex< T > operator-(Complex< T > const &val)
Unary minus.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > sin(Complex< T > const &x)
Sine.
ALPAKA_FN_INLINE ALPAKA_FN_HOST_ACC auto floatEqualExactNoWarning(T a, T b) -> bool
The alpaka accelerator library.