Linear
Linear::Complex< T > Class Template Reference

Class for complex numbers. More...

#include <Complex.h>

Public Member Functions

 Complex (T re=0, T im=0)
 Constructor. More...
 
template<typename U >
 Complex (const Complex< U > &other)
 Constructor. More...
 
template<typename U , typename std::enable_if< std::is_convertible< T, U >::value >::type * = nullptr>
 operator Complex< U > ()
 
Complexoperator= (const Complex &other)
 Assigns the complex number to another complex number. More...
 
Complexoperator= (const T &other)
 Assigns the complex number to the real number other. More...
 
Complexoperator+= (const Complex &other)
 
Complexoperator+= (const T &other)
 
Complexoperator-= (const Complex &other)
 
Complexoperator-= (const T &other)
 
Complexoperator*= (const Complex &other)
 
Complexoperator*= (const T &other)
 
Complexoperator/= (const Complex &other)
 
Complexoperator/= (const T &other)
 
Complex< T > operator- () const
 

Static Public Member Functions

static Complex< T > i ()
 Static function. More...
 

Public Attributes

Re
 
Im
 

Friends

Complex< T > operator+ (Complex< T > z, const Complex< T > &w)
 Takes two complex numbers \(z=a+bi\) and \(w=c+di\) and returns the complex number \(z+w=(a+c)+(b+d)i\). More...
 
Complex< T > operator+ (Complex< T > z, const T &x)
 Takes a complex number \(z=a+bi\) and real number \(x\) and returns the complex number \(z+x=(a+x)+bi\). More...
 
Complex< T > operator+ (const T &x, const Complex< T > &z)
 Takes a real number \(x\) and complex number \(z=a+bi\) returns the complex number \(x+z=(x+a)+bi\). More...
 
Complex< T > operator- (Complex< T > z, const Complex< T > &w)
 Takes two complex numbers \(z=a+bi\) and \(w=c+di\) and returns the complex number \(z-w=(a-c)+(b-d)i\). More...
 
Complex< T > operator- (Complex< T > z, const T &x)
 Takes a complex number \(z=a+bi\) and real number \(x\) and returns the complex number \(z-x=(a-x)+bi\). More...
 
Complex< T > operator- (const T &x, const Complex< T > &z)
 Takes a real number \(x\) and complex number \(z=a+bi\) returns the complex number \(x-z=(x-a)-bi\). More...
 
Complex< T > operator* (Complex< T > z, const Complex< T > &w)
 Takes two complex numbers \(z=a+bi\) and \(w=c+di\) and returns the complex number \(zw=(ac-bd)+(ad+bc)i\). More...
 
Complex< T > operator* (Complex< T > z, const T &x)
 Takes a complex number \(z=a+bi\) and real number \(x\) and returns the complex number \(zx=ax+bxi\). More...
 
Complex< T > operator* (const T &x, Complex< T > z)
 Takes a real number \(x\) and complex number \(z=a+bi\) returns the complex number \(xz=xa+xbi\). More...
 
Complex< T > operator/ (Complex< T > z, const Complex< T > &w)
 Takes two complex numbers \(z=a+bi\) and \(w=c+di\) and returns the complex number \(\frac{z}{w}=\frac{1}{c^2+d^2}((ac+bd)+(bc-ad)i)\). More...
 
Complex< T > operator/ (Complex< T > z, const T &x)
 Takes a complex number \(z=a+bi\) and real number \(x\) and returns the complex number \(\frac{z}{x}=\frac{a}{x}+\frac{b}{x}i\). More...
 
Complex< T > operator/ (const T &x, const Complex< T > &z)
 Takes a real number \(x\) and complex number \(z=a+bi\) returns the complex number \(\frac{x}{z}=\frac{1}{a^2+b^2}(xa-xbi)\). More...
 
std::ostream & operator<< (std::ostream &out, const Complex< T > &z)
 Takes a complex number \(z=a+bi\) and writes to out. More...
 
bool operator== (const Complex< T > &z, const Complex< T > &w)
 Compares two complex numbers \(z=a+bi\) and \(w=c+di\). More...
 
bool operator== (const Complex< T > &z, const T &x)
 Compares a complex number \(z=a+bi\) and a real number \(x\). More...
 
bool operator== (const T &x, const Complex< T > &z)
 Compares a real number \(x\) and a complex numbers \(z=a+bi\). More...
 
bool operator!= (const Complex< T > &z, const Complex< T > &w)
 Compares two complex numbers \(z=a+bi\) and \(w=c+di\). More...
 
bool operator!= (const Complex< T > &z, const T &x)
 Compares a complex number \(z=a+bi\) and a real number \(x\). More...
 
bool operator!= (const T &x, const Complex< T > &z)
 Compares a real number \(x\) and a complex numbers \(z=a+bi\). More...
 

Detailed Description

template<typename T>
class Linear::Complex< T >

Class for complex numbers.

Parameters
TType to store the real and imaginary part as.

Constructor & Destructor Documentation

◆ Complex() [1/2]

template<typename T >
Linear::Complex< T >::Complex ( re = 0,
im = 0 
)
inline

Constructor.

Creates the complex number re+im*i.

Parameters
reThe real part of the complex number. (default = 0)
imThe imaginary part of the complex number. (default = 0)

◆ Complex() [2/2]

template<typename T >
template<typename U >
Linear::Complex< T >::Complex ( const Complex< U > &  other)
inline

Constructor.

Copies a complex number.

Parameters
otherComplex number to copy.

Member Function Documentation

◆ i()

template<typename T >
static Complex<T> Linear::Complex< T >::i ( )
inlinestatic

Static function.

Creates and returns the complex number i.

Returns
Complex

◆ operator Complex< U >()

template<typename T >
template<typename U , typename std::enable_if< std::is_convertible< T, U >::value >::type * = nullptr>
Linear::Complex< T >::operator Complex< U > ( )
inline

◆ operator*=() [1/2]

template<typename T >
Complex& Linear::Complex< T >::operator*= ( const Complex< T > &  other)
inline

◆ operator*=() [2/2]

template<typename T >
Complex& Linear::Complex< T >::operator*= ( const T &  other)
inline

◆ operator+=() [1/2]

template<typename T >
Complex& Linear::Complex< T >::operator+= ( const Complex< T > &  other)
inline

◆ operator+=() [2/2]

template<typename T >
Complex& Linear::Complex< T >::operator+= ( const T &  other)
inline

◆ operator-()

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

◆ operator-=() [1/2]

template<typename T >
Complex& Linear::Complex< T >::operator-= ( const Complex< T > &  other)
inline

◆ operator-=() [2/2]

template<typename T >
Complex& Linear::Complex< T >::operator-= ( const T &  other)
inline

◆ operator/=() [1/2]

template<typename T >
Complex& Linear::Complex< T >::operator/= ( const Complex< T > &  other)
inline

◆ operator/=() [2/2]

template<typename T >
Complex& Linear::Complex< T >::operator/= ( const T &  other)
inline

◆ operator=() [1/2]

template<typename T >
Complex& Linear::Complex< T >::operator= ( const Complex< T > &  other)
inline

Assigns the complex number to another complex number.

Parameters
otherComplex number.
Returns
Reference to complex number.

◆ operator=() [2/2]

template<typename T >
Complex& Linear::Complex< T >::operator= ( const T &  other)
inline

Assigns the complex number to the real number other.

Parameters
otherReal number
Returns
Reference to complex number.

Friends And Related Function Documentation

◆ operator!= [1/3]

template<typename T >
bool operator!= ( const Complex< T > &  z,
const Complex< T > &  w 
)
friend

Compares two complex numbers \(z=a+bi\) and \(w=c+di\).

Parameters
zComplex number.
wComplex number.
Returns
If \(a\ne c\) or \(b\ne d\) it returns true. Otherwise it returns false.

◆ operator!= [2/3]

template<typename T >
bool operator!= ( const Complex< T > &  z,
const T &  x 
)
friend

Compares a complex number \(z=a+bi\) and a real number \(x\).

Parameters
zComplex number.
xReal number.
Returns
If \(a\ne x\) or \(b\ne 0\) it returns true. Otherwise it returns false.

◆ operator!= [3/3]

template<typename T >
bool operator!= ( const T &  x,
const Complex< T > &  z 
)
friend

Compares a real number \(x\) and a complex numbers \(z=a+bi\).

Parameters
xReal number.
zComplex number.
Returns
If \(a\ne x\) or \(b\ne 0\) it returns true. Otherwise it returns false.

◆ operator* [1/3]

template<typename T >
Complex<T> operator* ( Complex< T >  z,
const Complex< T > &  w 
)
friend

Takes two complex numbers \(z=a+bi\) and \(w=c+di\) and returns the complex number \(zw=(ac-bd)+(ad+bc)i\).

Parameters
zComplex number.
wComplex number.
Returns
Complex number.

◆ operator* [2/3]

template<typename T >
Complex<T> operator* ( Complex< T >  z,
const T &  x 
)
friend

Takes a complex number \(z=a+bi\) and real number \(x\) and returns the complex number \(zx=ax+bxi\).

Parameters
zComplex number.
xReal number.
Returns
Complex number.

◆ operator* [3/3]

template<typename T >
Complex<T> operator* ( const T &  x,
Complex< T >  z 
)
friend

Takes a real number \(x\) and complex number \(z=a+bi\) returns the complex number \(xz=xa+xbi\).

Parameters
xReal number.
zComplex number.
Returns
Complex number.

◆ operator+ [1/3]

template<typename T >
Complex<T> operator+ ( Complex< T >  z,
const Complex< T > &  w 
)
friend

Takes two complex numbers \(z=a+bi\) and \(w=c+di\) and returns the complex number \(z+w=(a+c)+(b+d)i\).

Parameters
zComplex number.
wComplex number.
Returns
Complex number.

◆ operator+ [2/3]

template<typename T >
Complex<T> operator+ ( Complex< T >  z,
const T &  x 
)
friend

Takes a complex number \(z=a+bi\) and real number \(x\) and returns the complex number \(z+x=(a+x)+bi\).

Parameters
zComplex number.
xReal number.
Returns
Complex number.

◆ operator+ [3/3]

template<typename T >
Complex<T> operator+ ( const T &  x,
const Complex< T > &  z 
)
friend

Takes a real number \(x\) and complex number \(z=a+bi\) returns the complex number \(x+z=(x+a)+bi\).

Parameters
xReal number.
zComplex number.
Returns
Complex number.

◆ operator- [1/3]

template<typename T >
Complex<T> operator- ( Complex< T >  z,
const Complex< T > &  w 
)
friend

Takes two complex numbers \(z=a+bi\) and \(w=c+di\) and returns the complex number \(z-w=(a-c)+(b-d)i\).

Parameters
zComplex number.
wComplex number.
Returns
Complex number.

◆ operator- [2/3]

template<typename T >
Complex<T> operator- ( Complex< T >  z,
const T &  x 
)
friend

Takes a complex number \(z=a+bi\) and real number \(x\) and returns the complex number \(z-x=(a-x)+bi\).

Parameters
zComplex number.
xReal number.
Returns
Complex number.

◆ operator- [3/3]

template<typename T >
Complex<T> operator- ( const T &  x,
const Complex< T > &  z 
)
friend

Takes a real number \(x\) and complex number \(z=a+bi\) returns the complex number \(x-z=(x-a)-bi\).

Parameters
xReal number.
zComplex number.
Returns
Complex number.

◆ operator/ [1/3]

template<typename T >
Complex<T> operator/ ( Complex< T >  z,
const Complex< T > &  w 
)
friend

Takes two complex numbers \(z=a+bi\) and \(w=c+di\) and returns the complex number \(\frac{z}{w}=\frac{1}{c^2+d^2}((ac+bd)+(bc-ad)i)\).

Parameters
zComplex number.
wComplex number.
Returns
Complex number.

◆ operator/ [2/3]

template<typename T >
Complex<T> operator/ ( Complex< T >  z,
const T &  x 
)
friend

Takes a complex number \(z=a+bi\) and real number \(x\) and returns the complex number \(\frac{z}{x}=\frac{a}{x}+\frac{b}{x}i\).

Parameters
zComplex number.
xReal number.
Returns
Complex number.

◆ operator/ [3/3]

template<typename T >
Complex<T> operator/ ( const T &  x,
const Complex< T > &  z 
)
friend

Takes a real number \(x\) and complex number \(z=a+bi\) returns the complex number \(\frac{x}{z}=\frac{1}{a^2+b^2}(xa-xbi)\).

Parameters
xReal number.
zComplex number.
Returns
Complex number.

◆ operator<<

template<typename T >
std::ostream& operator<< ( std::ostream &  out,
const Complex< T > &  z 
)
friend

Takes a complex number \(z=a+bi\) and writes to out.

If \(z=0\), then simply \(0\) will be written. If \(z=bi\), then it will write just \(bi\). If \(z=a\), then it will write just \(a\). Otherwise the full \(a+bi\) will be written, with "+" replaced by "-" if \(b<0\).

Parameters
outReference to std::ostream.
zComplex number.

◆ operator== [1/3]

template<typename T >
bool operator== ( const Complex< T > &  z,
const Complex< T > &  w 
)
friend

Compares two complex numbers \(z=a+bi\) and \(w=c+di\).

Parameters
zComplex number.
wComplex number.
Returns
If \(a=c\) and \(b=d\) it returns true. Otherwise it returns false.

◆ operator== [2/3]

template<typename T >
bool operator== ( const Complex< T > &  z,
const T &  x 
)
friend

Compares a complex number \(z=a+bi\) and a real number \(x\).

Parameters
zComplex number.
xReal number.
Returns
If \(a=x\) and \(b=0\) it returns true. Otherwise it returns false.

◆ operator== [3/3]

template<typename T >
bool operator== ( const T &  x,
const Complex< T > &  z 
)
friend

Compares a real number \(x\) and a complex numbers \(z=a+bi\).

Parameters
xReal number.
zComplex number.
Returns
If \(a=x\) and \(b=0\) it returns true. Otherwise it returns false.

Member Data Documentation

◆ Im

template<typename T >
T Linear::Complex< T >::Im

Imaginary part of the complex number

◆ Re

template<typename T >
T Linear::Complex< T >::Re

Real part of the complex number


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