6#ifndef THEORETICA_DUAL_H
7#define THEORETICA_DUAL_H
9#ifndef THEORETICA_NO_PRINT
14#include "../core/error.h"
15#include "../core/constants.h"
16#include "../algebra/algebra_types.h"
144 return dual(a +
r, b);
159 return dual(a -
r, b);
169 return dual(a *
r, b *
r);
180 return dual(a /
r, b /
r);
308 return dual(a, 0) / d;
312#ifndef THEORETICA_NO_PRINT
318 std::stringstream
res;
321 res << (b >= 0 ?
" + " :
" - ");
329 inline operator std::string() {
337 return out <<
obj.to_string();
Dual number class.
Definition dual.h:28
dual & operator+=(real r)
Sum a real number to this dual number.
Definition dual.h:194
vec2 to_vec() const
Convert a dual number to a vector.
Definition dual.h:266
dual operator/(const dual &other) const
Dual division.
Definition dual.h:173
bool operator==(const dual &other) const
Check whether two dual numbers have the same real and dual parts.
Definition dual.h:260
dual(const vec2 &v)
Initialize from a vec2.
Definition dual.h:48
dual conjugate() const
Get the dual conjugate.
Definition dual.h:117
dual operator*(real r) const
Multiply a dual number by a real number.
Definition dual.h:168
dual & operator+=(const dual &other)
Add a dual number to this one.
Definition dual.h:185
const real & Dual() const
Return dual part.
Definition dual.h:96
dual operator-(const dual &other) const
Subtract two dual numbers.
Definition dual.h:153
const real & Re() const
Return real part.
Definition dual.h:75
friend real & Dual(dual &d)
Extract the real part of the dual number.
Definition dual.h:112
real & Re()
Return real part.
Definition dual.h:80
friend real & Re(dual &d)
Extract the real part of the dual number.
Definition dual.h:91
friend std::ostream & operator<<(std::ostream &out, const dual &obj)
Stream the dual number in string representation to an output stream (std::ostream)
Definition dual.h:336
mat2 to_mat() const
Convert a dual number to matrix form.
Definition dual.h:281
dual & operator=(const std::array< real, 2 > &v)
Initialize a dual number from a std::array.
Definition dual.h:68
dual operator+(const dual &other) const
Sum two dual numbers.
Definition dual.h:138
dual & operator*=(const dual &other)
Multiply this dual number by another one.
Definition dual.h:216
dual & operator-=(real r)
Subtract a real number from this dual number.
Definition dual.h:209
dual & operator*=(real r)
Multiply this dual number by a real number.
Definition dual.h:225
dual inverse() const
Get the inverse of a dual number.
Definition dual.h:122
friend real Re(const dual &d)
Extract the real part of the dual number.
Definition dual.h:85
void from_vec(const vec2 &v)
Initialize from a vector.
Definition dual.h:274
dual & operator=(real x)
Initialize a dual number from a real number.
Definition dual.h:61
dual operator/(real r) const
Divide a dual number by a real number.
Definition dual.h:179
dual operator-() const
Get the opposite of a dual number.
Definition dual.h:148
dual operator-(real r) const
Subtract a real number from a dual number.
Definition dual.h:158
dual & operator/=(const dual &other)
Divide this dual number by another one.
Definition dual.h:233
dual(real real_part, real dual_part)
Initialize from two real numbers.
Definition dual.h:38
dual(real real_part)
Initialize from a real number.
Definition dual.h:42
real & Dual()
Return dual part.
Definition dual.h:101
dual operator*(const dual &other) const
Multiply two dual numbers.
Definition dual.h:163
dual operator+() const
Identity (for consistency)
Definition dual.h:133
dual operator+(real r) const
Sum a real number to a dual number.
Definition dual.h:143
std::string to_string(const std::string &epsilon="ε") const
Convert the dual number to string representation.
Definition dual.h:316
dual & operator=(const vec2 &v)
Initialize a dual number from a vec2.
Definition dual.h:54
dual()
Default constructor, initialize with null values.
Definition dual.h:35
friend real Dual(const dual &d)
Extract the real part of the dual number.
Definition dual.h:106
dual & operator/=(real r)
Divide a dual number by a real number.
Definition dual.h:242
dual & operator-=(const dual &other)
Subtract a real number from this one.
Definition dual.h:201
A statically allocated N-dimensional vector with elements of the given type.
Definition vec.h:92
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compilation op...
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:207
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:242
Vector make_error()
Create a vector representing an error state, with all NaN values.
Definition algebra.h:103
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:74
@ DivByZero
Division by zero.
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23