Complex< T > Class Template Reference

#include <complex.h>

Detailed Description

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

A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers and i is the imaginary unit, that satisfies the equation x2 = -1, that is, i2 = -1.[1] In this expression, a is the real part and b is the imaginary part of the complex number.

Complex numbers extend the concept of the one-dimensional number line to the two-dimensional complex plane by using the horizontal axis for the real part and the vertical axis for the imaginary part. The complex number a + bi can be identified with the point (a, b) in the complex plane. A complex number whose real part is zero is said to be purely imaginary, whereas a complex number whose imaginary part is zero is a real number. In this way, the complex numbers contain the ordinary real numbers while extending them in order to solve problems that cannot be solved with real numbers alone.

Examples for using complex numbers are the famous Mandelbrot set or the Fourier Transform of a signal. In the latter case the imaginary part stores the phase information.

Public Member Functions

 Complex ()
 
MAXON_IMPLICIT Complex (const T real)
 
MAXON_IMPLICIT Complex (const T real, const T imag)
 
const Complexoperator+= (const Complex &c)
 
const Complexoperator-= (const Complex &c)
 
const Complexoperator*= (const Complex &c)
 
Complex operator+ (const Complex &c) const
 
Complex operator- (const Complex &c) const
 
Complex operator* (const Complex &c) const
 
Complex operator* (const T s) const
 
void SetLength (const T len)
 
void SetPhase (const T phase)
 
void SetPolar (const T len, const T phase)
 
void SetExp (const T x)
 
GetSquaredLength () const
 
GetLength () const
 
GetPhase () const
 
Complex GetNormalized () const
 
Complex GetConjugate () const
 
Complex GetSqrt () const
 
Result< ComplexGetLog () const
 
Result< ComplexGetDivision (const Complex &divisor) const
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 
 MAXON_OPERATOR_EQUALITY_HASHCODE (Complex, real, imag)
 

Static Public Member Functions

static Result< void > DescribeIO (const DataSerializeInterface &stream)
 

Public Attributes

real
 
imag
 

Friends

Complex operator* (const T s, const Complex &c)
 

Constructor & Destructor Documentation

◆ Complex() [1/3]

Creates a Complex initialized with default values (all components 0.0).

◆ Complex() [2/3]

Complex ( const T  real)

Creates a Complex initialized with given real and default ( = 0.0) imaginary values.

◆ Complex() [3/3]

Complex ( const T  real,
const T  imag 
)

Creates a Complex initialized with given real and imaginary values.

Member Function Documentation

◆ operator+=()

const Complex< T > & operator+= ( const Complex< T > &  c)

Adds two Complex numbers.

◆ operator-=()

const Complex< T > & operator-= ( const Complex< T > &  c)

Subtracts two Complex numbers.

◆ operator*=()

const Complex< T > & operator*= ( const Complex< T > &  c)

Multiplies two Complex operations.

◆ operator+()

Complex< T > operator+ ( const Complex< T > &  c) const

Adds two Complex numbers.

◆ operator-()

Complex< T > operator- ( const Complex< T > &  c) const

Subtracts two Complex numbers.

◆ operator*() [1/2]

Complex< T > operator* ( const Complex< T > &  c) const

Multiplies two Complex numbers.

◆ operator*() [2/2]

Complex< T > operator* ( const T  s) const

Scales the Complex.

◆ SetLength()

void SetLength ( const T  len)

Set polar length (magnitude) in the Argand plane.

◆ SetPhase()

void SetPhase ( const T  phase)

Set polar phase (angle) in the Argand plane.

◆ SetPolar()

void SetPolar ( const T  len,
const T  phase 
)

Initialize Complex number by given polar coordinates.

◆ SetExp()

void SetExp ( const T  x)

set Complex number according to e^(i*x)

◆ GetSquaredLength()

T GetSquaredLength

Computes the squared magnitude/length/norm in the Argand plane.

Returns
length

◆ GetLength()

T GetLength ( void  ) const

Computes the magnitude/length/norm in the Argand plane.

Returns
length

◆ GetPhase()

T GetPhase

Computes the angle of the complex vector in the Argand plane.

Returns
phase

◆ GetNormalized()

Complex< T > GetNormalized

Get a complex vector with normalized length in the Argand plane.

Returns
normalized complex vector

◆ GetConjugate()

Complex< T > GetConjugate

Get the complex conjugate of a complex vector

Returns
complex conjugate

◆ GetSqrt()

Complex< T > GetSqrt

Compute the square root.

Returns
square root of vector

◆ GetLog()

Result< Complex< T > > GetLog

Compute the natural logarithm.

Returns
Log of complex vector. Returns an error if length of vector is zero

◆ GetDivision()

Result< Complex< T > > GetDivision ( const Complex< T > &  divisor) const

Divides the complex value by another complex value.

Parameters
[in]divisordivisor
Returns
The divided result. Returns an error if divisor is zero.

◆ ToString()

String ToString ( const FormatStatement formatStatement = nullptr) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Floating point values.
Returns
The converted result.

◆ DescribeIO()

Result< void > DescribeIO ( const DataSerializeInterface stream)
static

Describe all elements of this class for I/O operations.

Parameters
[in]streamThe stream that is used to register the class members.
Returns
OK on success.

◆ MAXON_OPERATOR_EQUALITY_HASHCODE()

MAXON_OPERATOR_EQUALITY_HASHCODE ( Complex< T >  ,
real  ,
imag   
)

Friends And Related Function Documentation

◆ operator*

Complex operator* ( const T  s,
const Complex< T > &  c 
)
friend

Scales the components of a Complex.

Member Data Documentation

◆ real

T real

real part

◆ imag

T imag

imaginary part