13 #include <type_traits>
40 static_assert(std::is_floating_point_v<T>);
56 : m_real(static_cast<T>(other.
real()))
57 , m_imag(static_cast<T>(other.
imag()))
69 return std::complex<T>{m_real, m_imag};
110 m_real +=
static_cast<T
>(other.
real());
111 m_imag +=
static_cast<T
>(other.
imag());
126 m_real -=
static_cast<T
>(other.
real());
127 m_imag -=
static_cast<T
>(other.
imag());
143 auto const newReal = m_real *
static_cast<T
>(other.
real()) - m_imag *
static_cast<T
>(other.
imag());
144 auto const newImag = m_imag *
static_cast<T
>(other.
real()) + m_real *
static_cast<T
>(other.
imag());
313 return !(lhs == rhs);
335 template<
typename T,
typename TChar,
typename TTraits>
336 std::basic_ostream<TChar, TTraits>&
operator<<(std::basic_ostream<TChar, TTraits>& os, Complex<T>
const& x)
338 os << x.operator std::complex<T>();
343 template<
typename T,
typename TChar,
typename TTraits>
373 return std::abs(std::complex<T>(x));
397 return std::arg(std::complex<T>(x));
445 return std::cos(std::complex<T>(x));
461 return std::exp(std::complex<T>(x));
469 return std::log(std::complex<T>(x));
498 template<
typename T,
typename U>
502 auto const result =
std::pow(std::complex<T>(x), std::complex<U>(y));
503 using ValueType =
typename decltype(result)::value_type;
509 template<
typename T,
typename U>
517 template<
typename T,
typename U>
536 return std::sin(std::complex<T>(x));
560 return std::tan(std::complex<T>(x));
Implementation of a complex number useable on host and device.
T value_type
Type of the real and imaginary parts.
ALPAKA_FN_HOST_ACC Complex & operator-=(Complex< U > const &other)
Subtraction assignment with a complex number.
ALPAKA_FN_HOST_ACC Complex & operator+=(T const &other)
Addition assignment with a real number.
ALPAKA_FN_HOST_ACC Complex & operator*=(T const &other)
Multiplication assignment with a real number.
ALPAKA_FN_HOST_ACC Complex & operator-=(T const &other)
Subtraction assignment with a real number.
ALPAKA_FN_HOST_ACC Complex & operator*=(Complex< U > const &other)
Multiplication assignment with a complex number.
constexpr ALPAKA_FN_HOST_ACC void imag(T value)
Set the imaginary part.
constexpr ALPAKA_FN_HOST_ACC T real() const
Get the real part.
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+=(Complex< U > const &other)
Addition assignment with a complex 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/=(Complex< U > const &other)
Division assignment with a complex number.
constexpr Complex(Complex const &other)=default
Copy constructor.
constexpr ALPAKA_FN_HOST_ACC Complex(Complex< U > const &other)
Constructor from Complex of another type.
Complex & operator=(Complex const &)=default
Assignment.
ALPAKA_FN_HOST_ACC Complex & operator/=(T const &other)
Division assignment with a real number.
constexpr ALPAKA_FN_HOST_ACC T imag() const
Get the imaginary part.
#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_...
ALPAKA_FN_INLINE ALPAKA_FN_HOST_ACC auto floatEqualExactNoWarning(T a, T b) -> bool
The alpaka accelerator library.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > proj(Complex< T > const &x)
Projection onto the Riemann sphere.
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 > sqrt(Complex< T > const &x)
Square root.
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 > acosh(Complex< T > const &x)
Arc hyperbolic cosine.
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.
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 > cos(Complex< T > const &x)
Cosine.
ALPAKA_FN_HOST_ACC Complex< T > operator/(Complex< T > const &lhs, Complex< T > const &rhs)
Division of two complex numbers.
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 > cosh(Complex< T > const &x)
Hyperbolic cosine.
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 T norm(Complex< T > const &x)
Squared magnitude.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > sin(Complex< T > const &x)
Sine.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC Complex< T > sinh(Complex< T > const &x)
Hyperbolic sine.
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 > acos(Complex< T > const &x)
Arc 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 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 > tan(Complex< T > const &x)
Tangent.
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 auto pow(Complex< T > const &x, Complex< U > const &y)
Complex power 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 > atanh(Complex< T > const &x)
Arc hyperbolic tangent.
std::basic_istream< TChar, TTraits > & operator>>(std::basic_istream< TChar, TTraits > &is, Complex< T > const &x)
Host-only input of a complex number.
ALPAKA_FN_HOST_ACC Complex< T > operator+(Complex< T > const &val)
Host-device arithmetic operations matching std::complex<T>.
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 > conj(Complex< T > const &x)
Complex conjugate.
constexpr ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC T abs(Complex< T > const &x)
Host-only math functions 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 Complex< T > exp(Complex< T > const &x)
Exponential.
ALPAKA_FN_HOST_ACC Complex< T > operator*(Complex< T > const &lhs, Complex< T > const &rhs)
Muptiplication of two complex numbers.