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);
306 return dual(a, 0) / d;
310#ifndef THEORETICA_NO_PRINT
316 std::stringstream
res;
319 res << (b >= 0 ?
" + " :
" - ");
327 inline operator std::string() {
335 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:264
dual operator/(const dual &other) const
Dual division.
Definition dual.h:173
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
std::string to_string(const std::string &epsilon="e") const
Convert the dual number to string representation.
Definition dual.h:314
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:334
mat2 to_mat() const
Convert a dual number to matrix form.
Definition dual.h:279
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:224
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:272
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
bool operator==(const dual &other)
Check whether two dual numbers have the same real and dual parts.
Definition dual.h:258
dual & operator/=(const dual &other)
Divide this dual number by another one.
Definition dual.h:232
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
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:240
dual & operator-=(const dual &other)
Subtract a real number from this one.
Definition dual.h:201
Type & at(unsigned int i, unsigned int j)
Accesses the element at the given row and column.
Definition mat.h:471
#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
vec< real, 2 > vec2
A 2-dimensional vector with real elements.
Definition algebra_types.h:39
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
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23
real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:54