HILA
Loading...
Searching...
No Matches
Complex< T > Class Template Reference

Complex definition. More...

#include <cmplx.h>

Inheritance diagram for Complex< T >:

Public Member Functions

T abs () const
 Compute absolute value of Complex number.
 
T arg () const
 Compute argument of Complex number.
 
 Complex ()=default
 Default constructo.
 
 Complex (const Complex< T > &a)=default
 Copy constructor.
 
Complex< T > conj () const
 Compute conjugate of Complex number.
 
template<typename A >
Complex< T > conj_mul (const Complex< A > &b) const
 Conjugate multiply method.
 
Complex< T > dagger () const
 Compute dagger of Complex number.
 
Complex< T > & gaussian_random (double width=1.0)
 Produces complex gaussian random values.
 
T & imag ()
 Imaginary part of Complex number.
 
T imag () const
 Imaginary part of Complex number.
 
template<typename T >
Complex< T > mul_add (const Complex< T > &a, const Complex< T > &b, const Complex< T > &c)
 Multiply add with Complex numbers.
 
template<typename A >
Complex< T > mul_conj (const Complex< A > &b) const
 Multiply conjugate method.
 
template<typename A , typename B , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
bool operator!= (const A a, const Complex< B > &b)
 Compare non-equality of Scalar and Complex number.
 
template<typename A , typename B , std::enable_if_t< hila::is_arithmetic< B >::value, int > = 0>
bool operator!= (const Complex< A > &a, const B b)
 Compare non-equality of Complex number and Scalar.
 
template<typename A , typename B >
bool operator!= (const Complex< A > &a, const Complex< B > &b)
 Compare non-equality of two complex numbers.
 
template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator* (const A &a, const Complex< T > &c)
 Multiplication operator Scalar * Complex.
 
template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator* (const Complex< T > &c, const A &a)
 Multiplication operator Complex * Scalar.
 
template<typename T1 , typename T2 , typename Tr = hila::type_mul<T1, T2>>
Complex< Tr > operator* (const Complex< T1 > &a, const Complex< T2 > &b)
 Multiplication operator Complex * Complex.
 
template<typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
Complex< T > & operator*= (const A a) &
 Real multiply assign operator.
 
template<typename A >
Complex< T > & operator*= (const Complex< A > &lhs) &
 Complex multiply assignment operator.
 
Complex< T > operator+ () const
 Unary + operator.
 
template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator+ (const A &a, const Complex< T > &c)
 Addition operator Scalar + Complex.
 
template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator+ (const Complex< T > &c, const A &a)
 Addition operator Complex + Scalar.
 
template<typename T1 , typename T2 , typename Tr = hila::type_plus<T1, T2>>
Complex< Tr > operator+ (const Complex< T1 > &a, const Complex< T2 > &b)
 Addition operator Complex + Complex.
 
Complex< T > & operator++ ()
 Single increment operator.
 
Complex< T > operator++ (int)
 Multiple increment operator.
 
template<typename A , std::enable_if_t< hila::is_assignable< T &, A >::value, int > = 0>
Complex< T > & operator+= (const A &a) &
 Real addition assignment operator.
 
template<typename A >
Complex< T > & operator+= (const Complex< A > &lhs)
 Complex addition assignment operator.
 
Complex< T > operator- () const
 Unary - operator.
 
template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator- (const A &a, const Complex< T > &c)
 Subtraction operator Scalar - Complex.
 
template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator- (const Complex< T > &c, const A &a)
 Subtraction operator Complex - Scalar.
 
template<typename T1 , typename T2 , typename Tr = hila::type_plus<T1, T2>>
Complex< Tr > operator- (const Complex< T1 > &a, const Complex< T2 > &b)
 Subtraction operator Complex - Complex.
 
Complex< T > & operator-- ()
 Single decrement operator.
 
Complex< T > operator-- (int)
 Multiple decrement operator.
 
template<typename A >
Complex< T > & operator-= (const Complex< A > &lhs) &
 Complex subtraction assignment operator.
 
template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator/ (const A &a, const Complex< T > &c)
 Division operator Scalar / Complex.
 
template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator/ (const Complex< T > &c, const A &a)
 Division operator Complex / Scalar.
 
template<typename T1 , typename T2 , typename Tr = hila::type_mul<T1, T2>>
Complex< Tr > operator/ (const Complex< T1 > &a, const Complex< T2 > &b)
 Division operator Complex / Complex.
 
template<typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
Complex< T > & operator/= (const A &a) &
 Real divide assignment operator.
 
template<typename A >
Complex< T > & operator/= (const Complex< A > &lhs) &
 Complex divide assignment operator.
 
Complex< T > & operator= (const Complex< T > &s) &=default
 Assignment operator.
 
template<typename A , typename B , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
bool operator== (const A a, const Complex< B > &b)
 Compare equality of Scalar and Complex.
 
template<typename A , typename B , std::enable_if_t< hila::is_arithmetic< B >::value, int > = 0>
bool operator== (const Complex< A > &a, const B b)
 Compare equality of Complex and scalar.
 
template<typename A , typename B >
bool operator== (const Complex< A > &a, const Complex< B > &b)
 Compare equality of two complex numbersTwo numbers are equal, if the real and imaginary components are respectively equal.
 
Complex< T > polar (const T r, const T theta)
 Stores and returns Complex number given in polar coordinates.
 
Complex< T > & random ()
 Assign random values to Complex real and imaginary part.
 
T & real ()
 Real part of Complex number.
 
T real () const
 Real part of Complex number.
 
T squarenorm () const
 Compute square norm of Complex number.
 

Related Symbols

(Note that these are not member symbols.)

constexpr Imaginary_t< double > operator""_i (long double a)
 
Mathematical functions
Returns
Complex T
template<typename T >
Complex< T > exp (const Complex< T > z)
 \(\exp(z)\)
 
template<typename T , std::enable_if_t< hila::is_arithmetic< T >::value, int > = 0>
Complex< T > expi (T a)
 \(\exp(i\cdot x)\)
 
template<typename T >
Complex< T > exp (const Imaginary_t< T > im)
 \(\exp(\Im(z))\)
 
template<typename T >
Complex< T > log (Complex< T > z)
 \(\log{z}\)
 
template<typename T >
Complex< T > sqrt (Complex< T > z)
 \(\sqrt{z}\)
 
template<typename T >
Complex< T > cbrt (Complex< T > z)
 \(\sqrt[3]{z}\)
 
template<typename A , typename B >
auto pow (Complex< A > z, Complex< B > p)
 pow(z.p) = \(z^p\) = \(exp(p*log(z))\)
 
template<typename T , typename S , std::enable_if_t< hila::is_arithmetic< S >::value, int > = 0>
Complex< T > pow (Complex< T > z, S p)
 pow(z.p) with scalar power
 
template<typename T , typename S , std::enable_if_t< hila::is_arithmetic< S >::value, int > = 0>
Complex< T > pow (S z, Complex< T > p)
 pow(z.p) with scalar base
 
template<typename T >
Complex< T > sin (Complex< T > z)
 
template<typename T >
Complex< T > cos (Complex< T > z)
 
template<typename T >
Complex< T > tan (Complex< T > z)
 \(\tan(z) = \frac{\sin(z)}{\cos(z)}\) - rely on optimizer to simplify
 
template<typename T >
Complex< T > sinh (Complex< T > z)
 
template<typename T >
Complex< T > cosh (Complex< T > z)
 
template<typename T >
Complex< T > tanh (Complex< T > z)
 \(\tanh(z)\)
 
template<typename T >
Complex< T > atan (Complex< T > z)
 \(\arctan(z)\)
 
template<typename T >
Complex< T > asin (Complex< T > z)
 \(\arcsin(z)\)
 
template<typename T >
Complex< T > acos (Complex< T > z)
 \(\arccos(z)\)
 
template<typename T >
Complex< T > atanh (Complex< T > z)
 \(\text{artanh}(z)\)
 
template<typename T >
Complex< T > asinh (Complex< T > z)
 \(\text{arsinh}(z)\)
 
template<typename T >
Complex< T > acosh (Complex< T > z)
 \(\text{arcosh}(z)\)
 

Detailed Description

template<typename T>
class Complex< T >

Complex definition.

Define complex type as a class. This allows Hilapp to replace the internal type with a vector.

NOTE: T must be arithmetic and integrable. In the following documentation MyType refers to T, as in an arithmetic and integrable type.

Parameters
reReal part
imImaginary part
Template Parameters
TArithmetic type
Examples
/home/runner/work/HILA/HILA/libraries/plumbing/field.h.

Definition at line 58 of file cmplx.h.

Constructor & Destructor Documentation

◆ Complex() [1/2]

template<typename T >
Complex< T >::Complex ( )
default

Default constructo.

Complex definition.
Definition cmplx.h:58

The default constructor initializes Complex::re and Complex::im to 0

◆ Complex() [2/2]

template<typename T >
Complex< T >::Complex ( const Complex< T > &  a)
default

Copy constructor.

Initialize form already existing Complex number

MyType a,b;
Complex<MyType> B = C; // B.re = a, B.im = b
double random()
Real valued uniform random number generator.
Definition hila_gpu.cpp:121

Equivalent initializing is Complex<MyType> B(C)

Real constructor:

Initialize only real element and sets imaginary to 0

Complex<MyType> C(a); // C.re = a, C.im = 0

Not equivalent to Complex<MyType> C = a

Zero constructor:

Initialize to zero with nullpointer trick

Complex<MyType> C = 0; // C.re = 0, C.im = 0

Equivalent to Complex<MyType> C and Complex<MyType> C(0)

Member Function Documentation

◆ abs()

template<typename T >
T Complex< T >::abs ( ) const
inline

Compute absolute value of Complex number.

Essentially sqrt(squarenorm(z)):

\begin{align} |z| = \sqrt{\Re(z)^2 + \Im(z)^2}\end{align}

Returns
T

Definition at line 260 of file cmplx.h.

◆ arg()

template<typename T >
T Complex< T >::arg ( ) const
inline

Compute argument of Complex number.

\begin{align} \arg(z) = \arctan2(\Im(z)),\Re(z)\end{align}

Returns
T

Definition at line 271 of file cmplx.h.

◆ conj()

template<typename T >
Complex< T > Complex< T >::conj ( ) const
inline

Compute conjugate of Complex number.

\begin{align} z &= x + i\cdot y \\ \Rightarrow z^* &= x - i\cdot y\end{align}

Returns
Complex<T>

Definition at line 283 of file cmplx.h.

◆ conj_mul()

template<typename T >
template<typename A >
Complex< T > Complex< T >::conj_mul ( const Complex< A > &  b) const
inline

Conjugate multiply method.

Conjugate a (*this) and multiply with give argument b: a.conj_mul(b) \( \equiv a^* \cdot b\)

Template Parameters
AType for Complex number b
Parameters
bnumber to multiply with
Returns
Complex<T>

Definition at line 654 of file cmplx.h.

◆ dagger()

template<typename T >
Complex< T > Complex< T >::dagger ( ) const
inline

Compute dagger of Complex number.

Alias to Complex::conj

\begin{align} z^* = z^\dagger \end{align}

Returns
Complex<T>

Definition at line 294 of file cmplx.h.

◆ gaussian_random()

template<typename T >
Complex< T > & Complex< T >::gaussian_random ( double  width = 1.0)
inline

Produces complex gaussian random values.

Uses hila::gaussrand2 for both real and imaignary part Assigns same random value for both real and imaginary part

Parameters
widthgaussian_random
Returns
Complex<T>&
Examples
/home/runner/work/HILA/HILA/libraries/plumbing/field.h.

Definition at line 339 of file cmplx.h.

◆ imag() [1/2]

template<typename T >
T & Complex< T >::imag ( )
inline

Imaginary part of Complex number.

Pass by reference

Returns
T & Imaginary part

Definition at line 185 of file cmplx.h.

◆ imag() [2/2]

template<typename T >
T Complex< T >::imag ( ) const
inline

Imaginary part of Complex number.

Pass by value if Complex number is defined as const

Returns
T Imaginary part

Definition at line 166 of file cmplx.h.

◆ mul_add()

template<typename T >
Complex< T > mul_add ( const Complex< T > &  a,
const Complex< T > &  b,
const Complex< T > &  c 
)
inline

Multiply add with Complex numbers.

Defined as

mul_add(a,b,c) = a*b + c;
Complex< T > mul_add(const Complex< T > &a, const Complex< T > &b, const Complex< T > &c)
Multiply add with Complex numbers.
Definition cmplx.h:1140
Template Parameters
TArithmetic type of a,b and c
Parameters
aComplex number to multiply
bComplex number to multiply
cComplex number to add to result of multiplication
Returns
Complex<T>

Definition at line 1140 of file cmplx.h.

◆ mul_conj()

template<typename T >
template<typename A >
Complex< T > Complex< T >::mul_conj ( const Complex< A > &  b) const
inline

Multiply conjugate method.

Multiply a (*this) with conjugate of given argument b: a.mul_conj(b) \( \equiv a \cdot b^*\)

Template Parameters
AType for Complex number b
Parameters
bnumber to conjugate and multiply withv
Returns
Complex<T>

Definition at line 670 of file cmplx.h.

◆ operator!=() [1/3]

template<typename A , typename B , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
bool operator!= ( const A  a,
const Complex< B > &  b 
)
inline

Compare non-equality of Scalar and Complex number.

Negation of operator==()

Template Parameters
AArithmetic type of a
BArithmetic type of b
Parameters
aScalar to compare
bComplex number to compare
Returns
true if values are not arithmetically equal

Definition at line 1249 of file cmplx.h.

◆ operator!=() [2/3]

template<typename A , typename B , std::enable_if_t< hila::is_arithmetic< B >::value, int > = 0>
bool operator!= ( const Complex< A > &  a,
const B  b 
)
inline

Compare non-equality of Complex number and Scalar.

Negation of operator==()

Template Parameters
AArithmetic type of a
BArithmetic type of b
Parameters
aComplex number to compare
bScalar to compare
Returns
true if values are not arithmetically equal

Definition at line 1233 of file cmplx.h.

◆ operator!=() [3/3]

template<typename A , typename B >
bool operator!= ( const Complex< A > &  a,
const Complex< B > &  b 
)
inline

Compare non-equality of two complex numbers.

Negation of operator==()

Template Parameters
AArithmetic type of a
BArithmetic type of b
Parameters
aComplex number to compare
bComplex number to compare
Returns
true if values are not arithmetically equal

Definition at line 1217 of file cmplx.h.

◆ operator*() [1/3]

template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator* ( const A &  a,
const Complex< T > &  c 
)
inline

Multiplication operator Scalar * Complex.

Multiplication between Complex and scalar is defined in the usual way

\begin{align}z,z_1 &= x + iy \in \mathbb{C}, a \in \mathbb{R} \\ z * a &= (x\cdot a + iy\cdot a)\end{align}

z = a * z_1;
Template Parameters
TArithmetic type of c
AArithmetic type of a
Parameters
cComplex number to multiply
aScalar to multiply
Returns
auto

Definition at line 1050 of file cmplx.h.

◆ operator*() [2/3]

template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator* ( const Complex< T > &  c,
const A &  a 
)
inline

Multiplication operator Complex * Scalar.

Multiplication between Complex and scalar is defined in the usual way

\begin{align}z,z_1 &= x + iy \in \mathbb{C}, a \in \mathbb{R} \\ z_1 * a &= (x\cdot a + iy\cdot a)\end{align}

z = z_1 * a;
Template Parameters
TArithmetic type of c
AArithmetic type of a
Parameters
cComplex number to multiply
aScalar to multiply
Returns
auto

Definition at line 1030 of file cmplx.h.

◆ operator*() [3/3]

template<typename T1 , typename T2 , typename Tr = hila::type_mul<T1, T2>>
Complex< Tr > operator* ( const Complex< T1 > &  a,
const Complex< T2 > &  b 
)
inline

Multiplication operator Complex * Complex.

Defined in the usual way

\begin{align}z, z_1 &= x + iy, z_2 = x' + iy' \in \mathbb{C} \\ z_1 z_2 &= (x + iy)(x' + iy') = (xx'-yy') + i(xy' + yx')\end{align}

z = z_1 * z_2;
Template Parameters
T1Arithmetic type of a
T2Arithmetic type of b
TrResulting type after multiplication
Parameters
a
b
Returns
Complex<Tr>

Definition at line 1010 of file cmplx.h.

◆ operator*=() [1/2]

template<typename T >
template<typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
Complex< T > & Complex< T >::operator*= ( const A  a) &
inline

Real multiply assign operator.

Multiply assign by real number to both components of Complex number

z *= 2; // z.re = 2, z.im = 2
Template Parameters
AType for real value a
Parameters
aReal value to multiply
Returns
Complex<T>&

Definition at line 497 of file cmplx.h.

◆ operator*=() [2/2]

template<typename T >
template<typename A >
Complex< T > & Complex< T >::operator*= ( const Complex< A > &  lhs) &
inline

Complex multiply assignment operator.

Standard Complex number multiplication

\begin{align}z &= x + iy, w = x' + iy' \\ z w &= (x + iy)(x' + iy') = (xx'-yy') + i(xy' + yx')\end{align}

//
// z,w get values
//
z*=w; // z = zw as defined above
Template Parameters
AType for Complex number multiply
Parameters
lhsComplex number to multiply
Returns
Complex<T>&

Definition at line 477 of file cmplx.h.

◆ operator+() [1/4]

template<typename T >
Complex< T > Complex< T >::operator+ ( ) const
inline

Unary + operator.

Identity operation

z == +z;
Returns
Complex<Tr>

Definition at line 357 of file cmplx.h.

◆ operator+() [2/4]

template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator+ ( const A &  a,
const Complex< T > &  c 
)
inline

Addition operator Scalar + Complex.

Defined in the usual way. \(z,z_1 \in \mathbb{C}, a \in \mathbb{R}\)

z = a + z_1;
Template Parameters
TArithmetic type of c
AArithmetic type of a
Parameters
aScalar to sum
cComplex number to sum
Returns
auto

Definition at line 929 of file cmplx.h.

◆ operator+() [3/4]

template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator+ ( const Complex< T > &  c,
const A &  a 
)
inline

Addition operator Complex + Scalar.

Defined in the usual way. \(z,z_1 \in \mathbb{C}, a \in \mathbb{R}\)

z = z_1 + a;
Template Parameters
TArithmetic type of c
AArithmetic type of a
Parameters
cComplex number to sum
aScalar to sum
Returns
auto

Definition at line 911 of file cmplx.h.

◆ operator+() [4/4]

template<typename T1 , typename T2 , typename Tr = hila::type_plus<T1, T2>>
Complex< Tr > operator+ ( const Complex< T1 > &  a,
const Complex< T2 > &  b 
)
inline

Addition operator Complex + Complex.

Addition between Complex numbers is defined in the usual way:

\begin{align} z_1, z_2 &\in \mathbf{C} \\ z_1 + z_2 &= \Re(z_1) + \Re(z_2) + [\Im(z_1) + \Im(z_2)]i \end{align}

z = z_1 + z_2;
Template Parameters
T1Type for first complex number
T2Type for second complex number
TrConversion type between T1 and T2
Parameters
aFirst complex number
bSecond complex number
Returns
Complex<Tr>

Definition at line 892 of file cmplx.h.

◆ operator++() [1/2]

template<typename T >
Complex< T > & Complex< T >::operator++ ( )
inline

Single increment operator.

Increments real part of Complex number

z++; // z.re = 2, z.im = 1
Returns
Complex<T>&

Definition at line 575 of file cmplx.h.

◆ operator++() [2/2]

template<typename T >
Complex< T > Complex< T >::operator++ ( int  )
inline

Multiple increment operator.

Increments real part of Complex number

z++2; // z.re = 4, z.im = 1
Returns
Complex<T>&

Definition at line 609 of file cmplx.h.

◆ operator+=() [1/2]

template<typename T >
template<typename A , std::enable_if_t< hila::is_assignable< T &, A >::value, int > = 0>
Complex< T > & Complex< T >::operator+= ( const A &  a) &
inline

Real addition assignment operator.

Add assign only to real part of Complex number

z += 1; // z.re = 1, z.im = 0

Definition at line 414 of file cmplx.h.

◆ operator+=() [2/2]

template<typename T >
template<typename A >
Complex< T > & Complex< T >::operator+= ( const Complex< A > &  lhs)
inline

Complex addition assignment operator.

z += w; // z.re = 1, z.im = 1
Template Parameters
ATyppe of Complex number to add
Parameters
lhsComplex number to add
Returns
Complex<T>&

Definition at line 394 of file cmplx.h.

◆ operator-() [1/4]

template<typename T >
Complex< T > Complex< T >::operator- ( ) const
inline

Unary - operator.

Negates Complex number

z = -z; // Results in -Re.z and -Im.z
Returns
Complex<T>

Definition at line 372 of file cmplx.h.

◆ operator-() [2/4]

template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator- ( const A &  a,
const Complex< T > &  c 
)
inline

Subtraction operator Scalar - Complex.

Defined in the usual way. \(z,z_1 \in \mathbb{C}, a \in \mathbb{R}\)

z = a - z_1;
Template Parameters
TArithmetic type of c
AArithmetic type of a
Parameters
aScalar
cComplex number to subtract
Returns
auto

Definition at line 988 of file cmplx.h.

◆ operator-() [3/4]

template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator- ( const Complex< T > &  c,
const A &  a 
)
inline

Subtraction operator Complex - Scalar.

Defined in the usual way. \(z,z_1 \in \mathbb{C}, a \in \mathbb{R}\)

z = z_1 - a;
Template Parameters
TArithmetic type of c
AArithmetic type of a
Parameters
cComplex number
aScalar to subtract
Returns
auto

Definition at line 970 of file cmplx.h.

◆ operator-() [4/4]

template<typename T1 , typename T2 , typename Tr = hila::type_plus<T1, T2>>
Complex< Tr > operator- ( const Complex< T1 > &  a,
const Complex< T2 > &  b 
)
inline

Subtraction operator Complex - Complex.

Subtraction between Complex numbers is defined in the usual way

\begin{align} z_1, z_2 &\in \mathbf{C} \\ z_1 - z_2 &= \Re(z_1) - \Re(z_2) + [\Im(z_1) - \Im(z_2)]i\end{align}

z = z_1 - z_2;
Template Parameters
T1Arithmetic type of a
T2Arithmetic type of b
TrResulting type after subtraction
Parameters
aFirst complex number
bSecond complex number to subtract
Returns
Complex<Tr>

Definition at line 952 of file cmplx.h.

◆ operator--() [1/2]

template<typename T >
Complex< T > & Complex< T >::operator-- ( )
inline

Single decrement operator.

Decrement real part of Complex number

z--; // z.re = 0, z.im = 1
Returns
Complex<T>&

Definition at line 592 of file cmplx.h.

◆ operator--() [2/2]

template<typename T >
Complex< T > Complex< T >::operator-- ( int  )
inline

Multiple decrement operator.

Decrement real part of Complex number

z--2; // z.re = 0, z.im = 1
Returns
Complex<T>&

Definition at line 628 of file cmplx.h.

◆ operator-=()

template<typename T >
template<typename A >
Complex< T > & Complex< T >::operator-= ( const Complex< A > &  lhs) &
inline

Complex subtraction assignment operator.

z -= w; // z.re = -1, z.im = -1
Template Parameters
AType for complex number to subtract
Parameters
lhsComplex number to subtract
Returns
Complex<T>&

Definition at line 434 of file cmplx.h.

◆ operator/() [1/3]

template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator/ ( const A &  a,
const Complex< T > &  c 
)
inline

Division operator Scalar / Complex.

Defined in the usual way

\begin{align} z,z_1=x + iy &\in \mathbb{C}, a \in \mathbb{R} \\ \frac{a}{z_1} &= \frac{az^*}{|z|^2} \end{align}

z = a / z_1;
Template Parameters
TArithmetic type of c
AArithmetic type of a
Parameters
cComplex number to divide
aScalar to divide with
Returns
auto

Definition at line 1120 of file cmplx.h.

◆ operator/() [2/3]

template<typename T , typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
auto operator/ ( const Complex< T > &  c,
const A &  a 
)
inline

Division operator Complex / Scalar.

Defined in the usual way

\begin{align}z, z_1=x + iy &\in \mathbb{C}, a \in \mathbb{R} \\ \frac{z_1}{a} &= \frac{x}{a} + i\cdot \frac{y}{a} \end{align}

z = z_1 / a;
Template Parameters
TArithmetic type of c
AArithmetic type of a
Parameters
cComplex number to divide
aScalar to divide with
Returns
auto

Definition at line 1099 of file cmplx.h.

◆ operator/() [3/3]

template<typename T1 , typename T2 , typename Tr = hila::type_mul<T1, T2>>
Complex< Tr > operator/ ( const Complex< T1 > &  a,
const Complex< T2 > &  b 
)
inline

Division operator Complex / Complex.

Defined in the usual way

\begin{align} z,z_1,z_2 &\in \mathbb{C} \\ \frac{z_1}{z_2} &= \frac{z_1\cdot z_2^{*}}{|z_2|^2} \end{align}

z =z_1 / z_2;
Template Parameters
T1Arithmetic type of a
T2Arithmetic type of b
TrResulting type after division
Parameters
aComplex number to divide
bComplex number to divide with
Returns
Complex<Tr>

Definition at line 1078 of file cmplx.h.

◆ operator/=() [1/2]

template<typename T >
template<typename A , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
Complex< T > & Complex< T >::operator/= ( const A &  a) &
inline

Real divide assignment operator.

Divide assign by real number to both components of Complex number

z /= 2; // z.re = 1, z.im = 1
Template Parameters
AType for real value to divide
Parameters
aReal value to divide
Returns
Complex<T>&

Definition at line 554 of file cmplx.h.

◆ operator/=() [2/2]

template<typename T >
template<typename A >
Complex< T > & Complex< T >::operator/= ( const Complex< A > &  lhs) &
inline

Complex divide assignment operator.

Standard Complex number division

\begin{align}z &= x + iy, w = x' + iy' \\ \frac{z}{w} &= \frac{x + iy}{x' + iy'} = \frac{(xx'+ yy') + i( yx' - xy')}{|w|^2}\end{align}

//
// z,w get values
//
z/=w; // z = z/w as defined above
Template Parameters
AType for Complex number divide
Parameters
lhsComplex number to divide
Returns
Complex<T>&

Definition at line 533 of file cmplx.h.

◆ operator=()

template<typename T >
Complex< T > & Complex< T >::operator= ( const Complex< T > &  s) &
inlinedefault

Assignment operator.

The following ways of assigning a Complex object are

Assignment for Complex:

B = C; // B.re = C.re, B.im = C.im

Assignment from real:

Assigns real part and imaginary part to zero

B = a; // B.re = a, B.im = 0
Parameters
s
Returns
Complex<T>&

◆ operator==() [1/3]

template<typename A , typename B , std::enable_if_t< hila::is_arithmetic< A >::value, int > = 0>
bool operator== ( const A  a,
const Complex< B > &  b 
)
inline

Compare equality of Scalar and Complex.

Two numbers are equal, if the arithmetic values are equal: thus, complex and real comparison (a + i b) == a is true if b == 0.

Template Parameters
AArithmetic type of a
BArithmetic type of b
Parameters
bComplex number to compare
aScalar to compare
Returns
true if values compare to equal

Definition at line 1201 of file cmplx.h.

◆ operator==() [2/3]

template<typename A , typename B , std::enable_if_t< hila::is_arithmetic< B >::value, int > = 0>
bool operator== ( const Complex< A > &  a,
const B  b 
)
inline

Compare equality of Complex and scalar.

Two numbers are equal, if the arithmetic values are equal: thus, complex and real comparison (a + i b) == a is true if b == 0.

Template Parameters
AArithmetic type of a
BArithmetic type of b
Parameters
aComplex number to compare
bScalar to compare
Returns
true if values compare to equal

Definition at line 1182 of file cmplx.h.

◆ operator==() [3/3]

template<typename A , typename B >
bool operator== ( const Complex< A > &  a,
const Complex< B > &  b 
)
inline

Compare equality of two complex numbersTwo numbers are equal, if the real and imaginary components are respectively equal.

Template Parameters
AArithmetic type of a
BArithmetic type of b
Parameters
aComplex number to compare
bComplex number to compare
Returns
true if values compare to equal

Definition at line 1163 of file cmplx.h.

◆ polar()

template<typename T >
Complex< T > Complex< T >::polar ( const T  r,
const T  theta 
)
inline

Stores and returns Complex number given in polar coordinates.

\begin{align} z = r\cdot e^{i\theta} \end{align}

double r = 1;
double theta = 3.14159265358979/2; // pi/2
c.polar(r,theta); // c.re = 0, c.im = 1
Complex< T > polar(const T r, const T theta)
Stores and returns Complex number given in polar coordinates.
Definition cmplx.h:314
Parameters
rRadius of Complex number
thetaAngle of complex number in radians
Returns
Complex<T> Complex number

Definition at line 314 of file cmplx.h.

◆ random()

template<typename T >
Complex< T > & Complex< T >::random ( )
inline

Assign random values to Complex real and imaginary part.

Uses hila::random for both real and imaginary part

Returns
Complex<T>&

Definition at line 326 of file cmplx.h.

◆ real() [1/2]

template<typename T >
T & Complex< T >::real ( )
inline

Real part of Complex number.

Pass by reference

Returns
T & Real part

Definition at line 176 of file cmplx.h.

◆ real() [2/2]

template<typename T >
T Complex< T >::real ( ) const
inline

Real part of Complex number.

Pass by value if Complex number is defined as const

Returns
T Real part

Definition at line 157 of file cmplx.h.

◆ squarenorm()

template<typename T >
T Complex< T >::squarenorm ( ) const
inline

Compute square norm of Complex number.

\begin{align} |z|^2 = \Re(z)^2 + \Im(z)^2\end{align}

Returns
T Squared norm

Definition at line 249 of file cmplx.h.

Friends And Related Symbol Documentation

◆ cos()

template<typename T >
Complex< T > cos ( Complex< T >  z)
related

\begin{align}\cos(z) &= \cos(\Re{z})\cos(i \Im(z)) - \sin(\Re{z})\sin(i \Im{z}) \\ &= \cos(\Re{z})\cosh(\Im(z)) - i \sin(\Re{z})\sinh(\Im(z))\end{align}

Definition at line 1579 of file cmplx.h.

◆ cosh()

template<typename T >
Complex< T > cosh ( Complex< T >  z)
related

cosh(z) = cosh(re)cosh(i im) - sinh(re)sinh(i im) = cosh(re)cos(im) - i sinh(re)sin(im)

Definition at line 1599 of file cmplx.h.

◆ operator""_i()

template<typename T >
constexpr Imaginary_t< double > operator""_i ( long double  a)
related

Operators to implement imaginary unit 1_i, enablig expressions 3 + 2_i etc. This is defined as an user-defined literal, which requires an underscore.

Definition at line 1653 of file cmplx.h.

◆ sin()

template<typename T >
Complex< T > sin ( Complex< T >  z)
related

\begin{align}sin(z) &= \sin(\Re(z) + i \Im(z)) \\ &= \sin(\Re(z))\cos(i \Im(z)) + \cos(\Re(z))\sin(i \Im(z)) \\ &= \sin(\Re(z)) \cosh(\Im(z)) + i \cos(\Re(z)) \sinh(\Im(z)) \end{align}

Definition at line 1572 of file cmplx.h.

◆ sinh()

template<typename T >
Complex< T > sinh ( Complex< T >  z)
related

sinh(z) = sinh(re)cosh(i im) + cosh(re)sinh(i im) = sinh(re)cos(im) + i cosh(re)sin(im)

Definition at line 1592 of file cmplx.h.


The documentation for this class was generated from the following file: