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 {
195 phase + other.phase);
204 phase + other.arg());
212 z.norm() * w.modulus,
229 phase - other.phase);
236 if(
phase == other.phase) {
249 if(
phase == other.phase)
262 phase += other.phase;
279 phase -= other.phase;
293 return !(*
this == z);
298 template<
typename T = Type>
308 inline operator complex<T> () {
309 return to_complex<T>();
316 return phasor((Type) 1.0, rad);
329 inline friend phasor operator+(Type r,
const phasor& z) {
333 inline friend phasor operator-(Type r,
const phasor& z) {
346#ifndef THEORETICA_NO_PRINT
349 inline std::string
to_string(
const std::string& separator =
", ")
const {
351 std::stringstream res;
358 inline operator std::string() {
366 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:269
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
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:321
phasor inverse() const
Compute the inverse of the complex number.
Definition phasor.h:129
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:219
phasor & operator+=(const phasor &other)
Add a phasor to this one.
Definition phasor.h:234
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:299
static phasor rotor(Type rad)
Construct a phasor representing a rotation of <rad> radians in 2 dimensions.
Definition phasor.h:315
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:201
phasor & operator-=(const phasor &other)
Subtract a phasor from this one.
Definition phasor.h:247
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:210
std::string to_string(const std::string &separator=", ") const
Convert the phasor to string representation.
Definition phasor.h:349
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:365
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:259
bool operator!=(const phasor &z) const
Check whether two phasors are not the same.
Definition phasor.h:292
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:286
#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:238
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
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:78
dual2 cos(dual2 x)
Compute the cosine of a second order dual number.
Definition dual2_functions.h:86
@ DivByZero
Division by zero.
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