6#ifndef THEORETICA_COMPLEX_H
7#define THEORETICA_COMPLEX_H
9#ifndef THEORETICA_NO_PRINT
16#include "../core/error.h"
17#include "../core/real_analysis.h"
25 template<
typename Type = real>
65 template<
typename T = Type>
129 return a *
a +
b *
b;
252 return (*
this =
operator*(
z.inverse()));
318 return (
a ==
z.a) && (
b ==
z.b);
324 return !(*
this ==
z);
373#ifndef THEORETICA_NO_PRINT
378 std::stringstream
res;
384 res << (
b >= 0 ?
" + " :
" - ");
396 inline operator std::string() {
404 return out <<
obj.to_string();
Complex number in algebraic form .
Definition complex.h:26
complex operator*(const complex &z) const
Multiply two complex numbers.
Definition complex.h:215
bool operator!=(const complex &z) const
Check whether two complex numbers are not the same.
Definition complex.h:323
static complex rotor(Type rad)
Construct a complex number representing a rotation of <rad> radians in 2 dimensions.
Definition complex.h:330
friend Type Re(const complex &z)
Extract the real part of the complex number.
Definition complex.h:86
std::string to_string() const
Convert the complex number to string representation.
Definition complex.h:376
Type a
Real part.
Definition complex.h:30
Type & Im()
Get the imaginary part of the complex number.
Definition complex.h:104
friend std::ostream & operator<<(std::ostream &out, const complex &obj)
Stream the complex number in string representation to an output stream (std::ostream)
Definition complex.h:403
complex & operator+=(const complex &z)
Add a complex number to this one.
Definition complex.h:230
complex operator-() const
Get the opposite of the complex number.
Definition complex.h:203
complex & operator-=(const complex &z)
Subtract a complex number from this one.
Definition complex.h:236
complex(Type real_part, Type imag_part)
Construct a complex number from its real and complex parts.
Definition complex.h:43
complex operator+(const complex &z) const
Add two complex numbers.
Definition complex.h:197
friend Type & Im(complex &z)
Extract the imaginary part of the complex number.
Definition complex.h:116
bool operator==(const complex &z) const
Check whether two complex numbers are the same.
Definition complex.h:317
Type sqr_norm() const
Compute the square norm of the complex number.
Definition complex.h:128
complex & operator*=(Type k)
Multiply the complex number by a real number.
Definition complex.h:299
complex()
Default constructor, initializes the number to zero.
Definition complex.h:38
friend Type Im(const complex &z)
Extract the imaginary part of the complex number.
Definition complex.h:110
complex(const complex &z)
Copy constructor.
Definition complex.h:53
complex & invert()
Invert the complex number.
Definition complex.h:154
complex operator+() const
Identity (for consistency)
Definition complex.h:191
complex & operator=(const std::array< T, 2 > &v)
Assignment operator from a 2D array.
Definition complex.h:66
complex operator/(const complex &z) const
Divide two complex numbers.
Definition complex.h:224
complex inverse() const
Compute the inverse of the complex number.
Definition complex.h:140
Type Re() const
Get the real part of the complex number.
Definition complex.h:74
complex operator*(Type k) const
Multiply the complex number by a real number.
Definition complex.h:269
complex(Type real_part)
Construct a complex number from a real number, with zero imaginary part.
Definition complex.h:49
Type b
Imaginary part.
Definition complex.h:33
complex operator/(Type k) const
Divide the complex number by a real number.
Definition complex.h:275
complex & operator*=(const complex &z)
Multiply the complex number by another.
Definition complex.h:242
static complex i()
Imaginary unit.
Definition complex.h:336
complex operator-(Type k) const
Subtract a real number from the complex number.
Definition complex.h:263
complex & operator/=(Type k)
Divide the complex number by a real number.
Definition complex.h:305
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 operator-(const complex &z) const
Subtract two complex numbers.
Definition complex.h:209
Type & Re()
Get the real part of the complex number.
Definition complex.h:80
complex & operator+=(Type k)
Add a real number to the complex number.
Definition complex.h:287
complex & operator=(const complex &z)
Assignment operator.
Definition complex.h:57
complex operator+(Type k) const
Add a real number to the complex number.
Definition complex.h:257
friend Type & Re(complex &z)
Extract the real part of the complex number.
Definition complex.h:92
complex & operator-=(Type k)
Subtract a real number from the complex number.
Definition complex.h:293
Type Im() const
Get the imaginary part of the complex number.
Definition complex.h:98
complex & operator/=(const complex &z)
Divide the complex number by another.
Definition complex.h:251
complex conjugate() const
Compute the conjugate of the complex number.
Definition complex.h:122
#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
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
double real
A real number, defined as a floating point type.
Definition constants.h:198
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition dual2_functions.h:54
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
real atan2(real y, real x)
Compute the 2 argument arctangent.
Definition real_analysis.h:1098
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
real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:54