Theoretica
A C++ numerical and automatic mathematical library
theoretica::complex< Type > Class Template Reference

Complex number in algebraic form \(a + ib\). More...

#include <complex.h>

Public Member Functions

 complex ()
 Default constructor, initializes the number to zero.
 
 complex (Type real_part, Type imag_part)
 Construct a complex number from its real and complex parts.
 
 complex (Type real_part)
 Construct a complex number from a real number, with zero imaginary part.
 
 complex (const complex &z)
 Copy constructor.
 
complexoperator= (const complex &z)
 Assignment operator.
 
template<typename T = Type>
complexoperator= (const std::array< T, 2 > &v)
 Assignment operator from a 2D array.
 
Type Re () const
 Get the real part of the complex number.
 
Type & Re ()
 Get the real part of the complex number.
 
Type Im () const
 Get the imaginary part of the complex number.
 
Type & Im ()
 Get the imaginary part of the complex number.
 
complex conjugate () const
 Compute the conjugate of the complex number.
 
Type sqr_norm () const
 Compute the square norm of the complex number.
 
Type norm () const
 Compute the norm of the complex number.
 
complex inverse () const
 Compute the inverse of the complex number.
 
complexinvert ()
 Invert the complex number.
 
Type arg () const
 Get the argument of the complex number.
 
complex operator+ () const
 Identity (for consistency)
 
complex operator+ (const complex &z) const
 Add two complex numbers.
 
complex operator- () const
 Get the opposite of the complex number.
 
complex operator- (const complex &z) const
 Subtract two complex numbers.
 
complex operator* (const complex &z) const
 Multiply two complex numbers.
 
complex operator/ (const complex &z) const
 Divide two complex numbers.
 
complexoperator+= (const complex &z)
 Add a complex number to this one.
 
complexoperator-= (const complex &z)
 Subtract a complex number from this one.
 
complexoperator*= (const complex &z)
 Multiply the complex number by another.
 
complexoperator/= (const complex &z)
 Divide the complex number by another.
 
complex operator+ (Type k) const
 Add a real number to the complex number.
 
complex operator- (Type k) const
 Subtract a real number from the complex number.
 
complex operator* (Type k) const
 Multiply the complex number by a real number.
 
complex operator/ (Type k) const
 Divide the complex number by a real number.
 
complexoperator+= (Type k)
 Add a real number to the complex number.
 
complexoperator-= (Type k)
 Subtract a real number from the complex number.
 
complexoperator*= (Type k)
 Multiply the complex number by a real number.
 
complexoperator/= (Type k)
 Divide the complex number by a real number.
 
bool operator== (const complex &z) const
 Check whether two complex numbers are the same.
 
bool operator!= (const complex &z) const
 Check whether two complex numbers are not the same.
 
 operator real ()
 Narrowing cast to a real number. More...
 
std::string to_string () const
 Convert the complex number to string representation.
 
 operator std::string ()
 Convert the complex number to string representation.
 

Static Public Member Functions

static complex rotor (Type rad)
 Construct a complex number representing a rotation of <rad> radians in 2 dimensions.
 
static complex i ()
 Imaginary unit.
 

Public Attributes

Type a
 Real part.
 
Type b
 Imaginary part.
 

Friends

Type Re (const complex &z)
 Extract the real part of the complex number.
 
Type & Re (complex &z)
 Extract the real part of the complex number.
 
Type Im (const complex &z)
 Extract the imaginary part of the complex number.
 
Type & Im (complex &z)
 Extract the imaginary part of the complex number.
 
complex operator+ (Type r, const complex &z)
 
complex operator- (Type r, const complex &z)
 
complex operator* (Type r, const complex &z)
 
complex operator/ (Type r, const complex &z)
 
std::ostream & operator<< (std::ostream &out, const complex &obj)
 Stream the complex number in string representation to an output stream (std::ostream)
 

Detailed Description

template<typename Type = real>
class theoretica::complex< Type >

Complex number in algebraic form \(a + ib\).

Member Function Documentation

◆ operator real()

template<typename Type = real>
theoretica::complex< Type >::operator real ( )
inline

Narrowing cast to a real number.

If the imaginary part is greater in module than the machine epsilon, NaN is returned.


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