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);
293 return dual2(a, 0, 0) / d;
297#ifndef THEORETICA_NO_PRINT
303 const std::string&
epsilon2 =
"ε²")
const {
305 std::stringstream
res;
308 res << (b >= 0 ?
" + " :
" - ");
313 res << (c >= 0 ?
" + " :
" - ");
323 inline operator std::string() {
331 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:221
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:261
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:330
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:235
void from_vec(const vec3 &v)
Initialize from a vector.
Definition dual2.h:270
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:229
bool operator==(const dual2 &other) const
Check whether two dual numbers have the same real and dual parts.
Definition dual2.h:255
real Re() const
Return real part.
Definition dual2.h:85
std::string to_string(const std::string &epsilon1="ε", const std::string &epsilon2="ε²") const
Convert the dual number to string representation.
Definition dual2.h:302
dual2 operator+() const
Identity (for consistency)
Definition dual2.h:116
real Dual1() const
Return first order dual part.
Definition dual2.h:90
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
dual2 cube(dual2 x)
Return the cube of a second order dual number.
Definition dual2_functions.h:29