6#ifndef THEORETICA_PHASOR
7#define THEORETICA_PHASOR
9#ifndef THEORETICA_NO_PRINT
14#include "../core/real_analysis.h"
23 template<
typename Type = real>
214 z.norm() *
w.modulus,
295 return !(*
this ==
z);
300 template<
typename T = Type>
348#ifndef THEORETICA_NO_PRINT
353 std::stringstream
res;
360 inline operator std::string() {
368 return out <<
obj.to_string();
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)
Divide this phasor by another one.
Definition phasor.h:271
Type modulus
Modulus of the complex number.
Definition phasor.h:28
Type Re() const
Get the real part of the complex number.
Definition phasor.h:87
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
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 std::array< T, 2 > &v)
Assignment operator from a 2D array as {modulus, phase}.
Definition phasor.h:76
phasor operator-(const phasor &other) const
Subtract two phasors.
Definition phasor.h:182
phasor(Type modulus, Type phase)
Initialize from two real numbers.
Definition phasor.h:39
phasor & operator=(const phasor &z)
Assignment operator.
Definition phasor.h:66
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 & invert()
Invert the complex number.
Definition phasor.h:144
phasor operator*(const phasor &other) const
Multiply two phasors.
Definition phasor.h:192
complex< T > to_complex() const
Transform a phasor to a complex number.
Definition phasor.h:301
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 complex< T > &other) const
Multiply a complex number in algebraic form and a phasor.
Definition phasor.h:202
phasor & operator-=(const phasor &other)
Subtract a phasor from this one.
Definition phasor.h:249
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
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 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
phasor & operator*=(const phasor &other)
Multiply this phasor by another one.
Definition phasor.h:261
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:225
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:198
std::remove_reference_t< decltype(std::declval< Structure >()[0])> vector_element_t
Extract the type of a vector (or any indexable container) from its operator[].
Definition core_traits.h:134
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:54
dual2 cos(dual2 x)
Compute the cosine of a second order dual number.
Definition dual2_functions.h:86
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition constants.h:207
dual2 sin(dual2 x)
Compute the sine of a second order dual number.
Definition dual2_functions.h:72
constexpr real PI
The Pi mathematical constant.
Definition constants.h:216