6 #ifndef THEORETICA_PHASOR
7 #define THEORETICA_PHASOR
9 #ifndef THEORETICA_NO_PRINT
14 #include "../core/real_analysis.h"
23 template<
typename Type = real>
87 inline Type
Re()
const {
99 inline Type
Im()
const {
295 return !(*
this == z);
300 template<
typename T = Type>
311 return to_complex<T>();
318 return phasor((Type) 1.0, rad);
348 #ifndef THEORETICA_NO_PRINT
353 std::stringstream res;
Complex number in algebraic form .
Definition: complex.h:26
Type arg() const
Get the argument of the complex number.
Definition: complex.h:173
Type norm() const
Compute the norm of the complex number.
Definition: complex.h:134
Complex number in exponential form .
Definition: phasor.h:24
phasor operator+(const phasor &other) const
Add two phasors.
Definition: phasor.h:169
phasor & operator-=(const phasor &other)
Subtract a phasor from this one.
Definition: phasor.h:249
Type modulus
Modulus of the complex number.
Definition: phasor.h:28
phasor & operator=(const std::array< T, 2 > &v)
Assignment operator from a 2D array as {modulus, phase}.
Definition: phasor.h:76
complex< T > to_complex() const
Transform a phasor to a complex number.
Definition: phasor.h:301
Type Re() const
Get the real part of the complex number.
Definition: phasor.h:87
friend std::ostream & operator<<(std::ostream &out, const phasor &obj)
Stream the phasor in string representation to an output stream (std::ostream)
Definition: phasor.h:367
Type inverse() const
Compute the inverse of the complex number.
Definition: phasor.h:129
phasor conjugate() const
Compute the conjugate of the complex number.
Definition: phasor.h:111
Type sqr_norm() const
Compute the square norm of the complex number.
Definition: phasor.h:117
phasor & operator*=(const phasor &other)
Multiply this phasor by another one.
Definition: phasor.h:261
friend Type Re(const phasor &z)
Extract the real part of the complex number.
Definition: phasor.h:93
static phasor i()
Imaginary unit in exponential form.
Definition: phasor.h:323
Type Im() const
Get the imaginary part of the complex number.
Definition: phasor.h:99
phasor operator/(const phasor &other) const
Divide two phasors.
Definition: phasor.h:221
phasor & operator+=(const phasor &other)
Add a phasor to this one.
Definition: phasor.h:236
phasor operator-(const phasor &other) const
Subtract two phasors.
Definition: phasor.h:182
phasor & invert()
Invert the complex number.
Definition: phasor.h:144
phasor(Type modulus, Type phase)
Initialize from two real numbers.
Definition: phasor.h:39
friend Type Im(const phasor &z)
Extract the imaginary part of the complex number.
Definition: phasor.h:105
Type phase
Phase of the complex number.
Definition: phasor.h:31
phasor(Type r)
Construct a phasor from a real number.
Definition: phasor.h:59
phasor & operator/=(const phasor &other)
Divide this phasor by another one.
Definition: phasor.h:271
phasor operator*(const phasor &other) const
Multiply two phasors.
Definition: phasor.h:192
static phasor rotor(Type rad)
Construct a phasor representing a rotation of <rad> radians in 2 dimensions.
Definition: phasor.h:317
phasor(const complex< T > &z)
Construct a phasor from a complex number.
Definition: phasor.h:53
phasor & operator=(const phasor &z)
Assignment operator.
Definition: phasor.h:66
phasor operator*(const complex< T > &other) const
Multiply a complex number in algebraic form and a phasor.
Definition: phasor.h:202
Type arg() const
Get the argument of the complex number.
Definition: phasor.h:160
friend phasor operator*(const complex< T > &z, const phasor &w)
Multiply a complex number in algebraic form and a phasor.
Definition: phasor.h:212
std::string to_string(const std::string &separator=", ") const
Convert the phasor to string representation.
Definition: phasor.h:351
Type norm() const
Compute the norm of the complex number.
Definition: phasor.h:123
phasor(const phasor &other)
Initialize from another phasor.
Definition: phasor.h:46
bool operator!=(const phasor &z) const
Check whether two phasors are not the same.
Definition: phasor.h:294
phasor()
Initialize as 0/0.
Definition: phasor.h:35
bool operator==(const phasor &z) const
Check whether two phasors are the same.
Definition: phasor.h:288
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compiling opti...
Definition: error.h:219
std::string string(size_t length)
Generate a random string made of human-readable ASCII characters.
Definition: random.h:102
Main namespace of the library which contains all functions and objects.
Definition: algebra.h:27
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition: dual2_functions.h:183
dual2 cos(dual2 x)
Compute the cosine of a second order dual number.
Definition: dual2_functions.h:82
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition: constants.h:197
dual2 sin(dual2 x)
Compute the sine of a second order dual number.
Definition: dual2_functions.h:70
constexpr real PI
The Pi mathematical constant.
Definition: constants.h:206
real nan()
Return a quiet NaN number in floating point representation.
Definition: error.h:54