6#ifndef THEORETICA_DUAL2_H
7#define THEORETICA_DUAL2_H
9#ifndef THEORETICA_NO_PRINT
14#include "../core/error.h"
15#include "../core/constants.h"
16#include "../algebra/algebra_types.h"
101 return dual2(a, -b, -c);
117 return dual2(a, b, c);
127 return dual2(a +
r, b, c);
132 return dual2(-a, -b, -c);
142 return dual2(a -
r, b, c);
289 return dual2(a, 0, 0) / d;
293#ifndef THEORETICA_NO_PRINT
299 const std::string&
epsilon2 =
"e2")
const {
301 std::stringstream
res;
304 res << (b >= 0 ?
" + " :
" - ");
309 res << (c >= 0 ?
" + " :
" - ");
319 inline operator std::string() {
327 return out <<
obj.to_string();
Second order dual number class.
Definition dual2.h:29
dual2(real real_part, real dual1_part)
Initialize from two real numbers.
Definition dual2.h:44
dual2 operator*(const dual2 &other) const
Multiply two dual numbers.
Definition dual2.h:146
dual2 conjugate() const
Get the dual conjugate.
Definition dual2.h:100
dual2 & operator-=(const dual2 &other)
Subtract a real number from this one.
Definition dual2.h:192
dual2 & operator*=(const dual2 &other)
Multiply this dual number by another one.
Definition dual2.h:208
dual2 operator+(real r) const
Sum a real number to a dual number.
Definition dual2.h:126
dual2 & operator*=(real r)
Multiply this dual number by a real number.
Definition dual2.h:217
dual2 operator+(const dual2 &other) const
Sum two dual numbers.
Definition dual2.h:121
dual2 operator/(const dual2 &other) const
Dual division.
Definition dual2.h:158
vec3 to_vec() const
Convert a dual number to a vector.
Definition dual2.h:257
std::string to_string(const std::string &epsilon1="e1", const std::string &epsilon2="e2") const
Convert the dual number to string representation.
Definition dual2.h:298
dual2 inverse() const
Get the inverse of a dual number.
Definition dual2.h:105
dual2 operator/(real r) const
Divide a dual number by a real number.
Definition dual2.h:163
friend std::ostream & operator<<(std::ostream &out, const dual2 &obj)
Stream the dual number in string representation to an output stream (std::ostream)
Definition dual2.h:326
dual2()
Default constructor, initialize with null values.
Definition dual2.h:37
dual2 operator-(const dual2 &other) const
Subtract two dual numbers.
Definition dual2.h:136
dual2 & operator+=(real r)
Sum a real number to this dual number.
Definition dual2.h:185
dual2(const vec3 &v)
Initialize from a vec3.
Definition dual2.h:54
dual2(real real_part)
Initialize from a real number.
Definition dual2.h:48
real Dual2() const
Return second order dual part.
Definition dual2.h:95
dual2 & operator/=(real r)
Divide a dual number by a real number.
Definition dual2.h:231
void from_vec(const vec3 &v)
Initialize from a vector.
Definition dual2.h:266
dual2 operator*(real r) const
Multiply a dual number by a real number.
Definition dual2.h:153
dual2 & operator+=(const dual2 &other)
Add a dual2 number from this one.
Definition dual2.h:175
dual2 operator-(real r) const
Subtract a real number from a dual number.
Definition dual2.h:141
dual2 & operator=(real x)
Initialize a dual number from a real number.
Definition dual2.h:69
dual2(real real_part, real dual1_part, real dual2_part)
Initialize from two real numbers.
Definition dual2.h:40
dual2 & operator=(const std::array< real, 3 > &v)
Initialize a dual number from a std::array.
Definition dual2.h:77
dual2 & operator-=(real r)
Subtract a real number from this dual number.
Definition dual2.h:201
dual2 & operator=(const vec3 &v)
Initialize a dual number from a vec3.
Definition dual2.h:61
dual2 operator-() const
Get the opposite of a dual number.
Definition dual2.h:131
dual2 & operator/=(const dual2 &other)
Divide this dual number by another one.
Definition dual2.h:225
real Re() const
Return real part.
Definition dual2.h:85
dual2 operator+() const
Identity (for consistency)
Definition dual2.h:116
bool operator==(const dual2 &other)
Check whether two dual numbers have the same real and dual parts.
Definition dual2.h:251
real Dual1() const
Return first order dual part.
Definition dual2.h:90
#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 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
vec< real, 3 > vec3
A 3-dimensional vector with real elements.
Definition algebra_types.h:42
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
dual2 cube(dual2 x)
Return the cube of a second order dual number.
Definition dual2_functions.h:29