6#ifndef THEORETICA_COMPLEX_FUNCTIONS
7#define THEORETICA_COMPLEX_FUNCTIONS
10#include "../core/real_analysis.h"
28 return complex<T>(z.a, -z.b);
43 inline complex<T>
square(complex<T> z) {
54 inline complex<T>
cube(complex<T> z) {
73 return complex<T>(
nan(),
nan());
76 return complex<T>(0, 0);
80 const real theta = p * z.arg();
89 inline complex<T>
exp(complex<T> z) {
90 return complex<T>(
cos(z.Im()),
sin(z.Im())) *
exp(z.Re());
105 inline complex<T>
sin(complex<T> z) {
108 return (
exp(t) -
exp(-t)) * complex<T>(0, -0.5);
115 inline complex<T>
cos(complex<T> z) {
118 return (
exp(t) +
exp(-t)) / 2.0;
125 inline complex<T>
tan(complex<T> z) {
127 const complex<T> t =
exp(z * complex<T>(0, 2));
128 return (t - complex<T>(1, 0)) / (t + complex<T>(1, 0)) * complex<T>(0, -1);
135 inline complex<T>
sqrt(complex<T> z) {
138 return complex<T>(0);
149 inline complex<T>
ln(complex<T> z) {
150 return complex<T>(
ln(z.norm()), z.arg());
157 inline complex<T>
asin(complex<T> z) {
161 T real_part = (z.Re() > 1.0) ? 1.0 : ((z.Re() < -1.0) ? -1.0 : z.Re());
162 return complex<T>(
asin(real_part), 0);
173 inline complex<T>
acos(complex<T> z) {
177 const T real_part = (z.Re() > 1.0) ? 1.0 : ((z. Re() < -1.0) ? -1.0 : z.Re());
178 return complex<T>(
acos(real_part), 0);
182 return ln(z +
sqrt(
square(z) - complex<T>(1, 0))) * complex<T>(0, -1);
189 inline complex<T>
atan(complex<T> z) {
Complex number in algebraic form .
Definition complex.h:26
static constexpr complex i()
Imaginary unit.
Definition complex.h:336
real Re() const
Return real part.
Definition dual2.h:85
#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
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 ln(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition dual2_functions.h:151
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:198
dual2 asin(dual2 x)
Compute the arcsine of a second order dual number.
Definition dual2_functions.h:204
complex< T > identity(complex< T > z)
Complex identity.
Definition complex_analysis.h:19
dual2 exp(dual2 x)
Compute the exponential of a second order dual number.
Definition dual2_functions.h:138
complex< T > inverse(complex< T > z)
Compute the conjugate of a complex number.
Definition complex_analysis.h:35
constexpr real INVSQR2
The inverse of the square root of 2.
Definition constants.h:264
dual2 conjugate(dual2 x)
Return the conjugate of a second order dual number.
Definition dual2_functions.h:35
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
@ ImpossibleOperation
Mathematically impossible operation.
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition constants.h:207
dual2 tan(dual2 x)
Compute the tangent of a second order dual number.
Definition dual2_functions.h:100
dual2 acos(dual2 x)
Compute the arcosine of a second order dual number.
Definition dual2_functions.h:223
int sgn(real x)
Return the sign of x (1 if positive, -1 if negative, 0 if null)
Definition real_analysis.h:259
complex< T > powf(complex< T > z, real p)
Compute a complex number raised to a real power.
Definition complex_analysis.h:67
dual2 sin(dual2 x)
Compute the sine of a second order dual number.
Definition dual2_functions.h:72
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23
dual2 atan(dual2 x)
Compute the arctangent of a second order dual number.
Definition dual2_functions.h:242
dual2 cube(dual2 x)
Return the cube of a second order dual number.
Definition dual2_functions.h:29