MathLib
Loading...
Searching...
No Matches
Public Member Functions | List of all members
BasicDual< T > Class Template Reference

#include <math/Dual.hpp>

Public Types

Types
using value_type = T
 The underlying implementation type.
 

Public Member Functions

constexpr BasicDual< T > conjugate () const
 
constexpr T magnitude () const
 
Constructors
constexpr BasicDual ()=default
 Defaults to (0,0)
 
constexpr BasicDual (const T &r)
 
constexpr BasicDual (const T &r, const T &d)
 
Invalid Value Check
bool isNaN () const
 
bool isInf () const
 

Static Public Member Functions

Constants
static constexpr BasicDual< T > identity ()
 
static constexpr BasicDual< T > zero ()
 
Convenience Creation Functions
static constexpr BasicDual< T > make_pure (const T &input)
 

Public Attributes

Element Access
T real {}
 
T dual {}
 

Friends

Equality
constexpr bool operator== (const BasicDual< T > &left, const BasicDual< T > &right)
 
template<std::floating_point OT = T>
requires std::is_floating_point_v<T>
constexpr bool approximately_equal_to (const BasicDual< T > &value_to_test, const BasicDual< T > &value_it_should_be, OT tolerance=OT{0.0002})
 
Operators
constexpr BasicDual< T > operator* (const BasicDual< T > &left, const BasicDual< T > &right)
 Defines multiplication of two Duals.
 
template<std::floating_point OT = double>
constexpr BasicDual< T > operator* (OT scalar, const BasicDual< T > &d)
 
template<std::floating_point OT = double>
constexpr BasicDual< T > operator* (const BasicDual< T > &d, OT scalar)
 
constexpr BasicDual< T > operator/ (const BasicDual< T > &left, const BasicDual< T > &right)
 Defines division of two Duals.
 
template<std::floating_point OT = double>
constexpr BasicDual< T > operator/ (OT scalar, const BasicDual< T > &d)
 
template<std::floating_point OT = double>
constexpr BasicDual< T > operator/ (const BasicDual< T > &left, OT scalar)
 
constexpr BasicDual< T > operator+ (const BasicDual< T > &left, const BasicDual< T > &right)
 Defines addition of two Duals.
 
template<std::floating_point OT = double>
constexpr BasicDual< T > operator+ (OT scalar, const BasicDual< T > &d)
 Defines addition of a floating-point scalar and a Dual.
 
template<std::floating_point OT = double>
constexpr BasicDual< T > operator+ (const BasicDual< T > &left, OT scalar)
 Defines addition of a Dual and a floating-point scalar.
 
constexpr BasicDual< T > operator- (const BasicDual< T > &left, const BasicDual< T > &right)
 Defines subtraction of two Duals.
 
template<std::floating_point OT = double>
constexpr BasicDual< T > operator- (OT scalar, const BasicDual< T > &d)
 Defines subtraction of a floating-point scalar and a Dual.
 
template<std::floating_point OT = double>
constexpr BasicDual< T > operator- (const BasicDual< T > &left, OT scalar)
 Defines subtraction of a Dual and a floating-point scalar.
 
Check
template<std::floating_point OT = T>
requires std::is_floating_point_v<T>
bool check_if_equal (const BasicDual< T > &input, const BasicDual< T > &near_to, OT tolerance=OT{0.0002})
 
template<std::floating_point OT = T>
requires std::is_floating_point_v<T>
bool check_if_not_equal (const BasicDual< T > &input, const BasicDual< T > &near_to, OT tolerance=OT{0.0002})
 
Assert
template<std::floating_point OT = T>
requires std::is_floating_point_v<T>
void CHECK_IF_EQUAL (const BasicDual< T > &input, const BasicDual< T > &near_to, OT tolerance=OT{0.0002})
 
template<std::floating_point OT = T>
requires std::is_floating_point_v<T>
void CHECK_IF_NOT_EQUAL (const BasicDual< T > &input, const BasicDual< T > &near_to, OT tolerance=OT{0.0002})
 
template<std::floating_point OT = T>
requires std::is_floating_point_v<T>
void CHECK_IF_ZERO (const BasicDual< T > &input, OT tolerance=OT{0.0002})
 
Global Functions
constexpr T dot (const BasicDual< T > &left, const BasicDual< T > &right)
 
constexpr BasicDual< T > dualscalar_sqrt (const BasicDual< T > &input)
 
constexpr T dualscalar_normsquared (const BasicDual< T > &d)
 
constexpr T accumulate (const BasicDual< T > &input)
 
constexpr BasicDual< T > conjugate (const BasicDual< T > &input)
 
std::string format (const BasicDual< T > &input)
 

Related Symbols

(Note that these are not member symbols.)

Type Aliases
using Dualf = BasicDual< float >
 
using Duald = BasicDual< double >
 
using Dual = BasicDual< double >
 
using Duall = BasicDual< long double >
 

Detailed Description

template<class T>
class Math::BasicDual< T >

Class representing the concept of a dual number

Definition at line 25 of file Dual.hpp.

Member Typedef Documentation

◆ value_type

template<class T >
using value_type = T

The underlying implementation type.

Definition at line 31 of file Dual.hpp.

Constructor & Destructor Documentation

◆ BasicDual() [1/3]

template<class T >
constexpr BasicDual ( )
constexprdefault

Defaults to (0,0)

◆ BasicDual() [2/3]

template<class T >
constexpr BasicDual ( const T &  r)
inlineconstexpr

Sets the real part to r and leaves the dual part as 0

Note
We don't make this an explicit constructor so that we may take advantage of operators using the hidden-friend idiom and allow for minimal code while allowing natural conversions to promote a scalar to a BasicDual to occur.

Definition at line 46 of file Dual.hpp.

◆ BasicDual() [3/3]

template<class T >
constexpr BasicDual ( const T &  r,
const T &  d 
)
inlineconstexpr

Definition at line 48 of file Dual.hpp.

Member Function Documentation

◆ conjugate()

template<class T >
constexpr BasicDual< T > conjugate ( ) const
inlineconstexpr

Definition at line 58 of file Dual.hpp.

◆ identity()

template<class T >
static constexpr BasicDual< T > identity ( )
inlinestaticconstexpr

Definition at line 54 of file Dual.hpp.

◆ isInf()

template<class T >
bool isInf ( ) const
inline

Definition at line 97 of file Dual.hpp.

◆ isNaN()

template<class T >
bool isNaN ( ) const
inline

Definition at line 89 of file Dual.hpp.

◆ magnitude()

template<class T >
constexpr T magnitude ( ) const
inlineconstexpr

Definition at line 66 of file Dual.hpp.

◆ make_pure()

template<class T >
static constexpr BasicDual< T > make_pure ( const T &  input)
inlinestaticconstexpr

Creates a pure BasicDual with input

Parameters
input
Postcondition
output.real == 0 output.dual == input
Note
A pure BasicDual is one which has the real component set to 0

Definition at line 80 of file Dual.hpp.

◆ zero()

template<class T >
static constexpr BasicDual< T > zero ( )
inlinestaticconstexpr

Definition at line 55 of file Dual.hpp.

Friends And Related Symbol Documentation

◆ accumulate

template<class T >
constexpr T accumulate ( const BasicDual< T > &  input)
friend

Accumulates the components of the input BasicDual

Returns
A scalar that is the sum of the components

Definition at line 454 of file Dual.hpp.

◆ approximately_equal_to

template<class T >
template<std::floating_point OT = T>
requires std::is_floating_point_v<T>
constexpr bool approximately_equal_to ( const BasicDual< T > &  value_to_test,
const BasicDual< T > &  value_it_should_be,
OT  tolerance = OT{0.0002} 
)
friend

Compare two values for equality with a tolerance

Parameters
inputThe first value to compare
near_toThe second value to compare
toleranceThe minimum value for being considered equal
Returns
true if the two are equal within tolerance , false otherwise
See also
Equality

Definition at line 146 of file Dual.hpp.

◆ conjugate

template<class T >
constexpr BasicDual< T > conjugate ( const BasicDual< T > &  input)
friend

Computes the conjugate of the input

Note
This will just call input.conjugate()

Definition at line 463 of file Dual.hpp.

◆ dot

template<class T >
constexpr T dot ( const BasicDual< T > &  left,
const BasicDual< T > &  right 
)
friend

Calculates the dot-product of two Duals

Returns
The dot-product of the two inputs
Note
This treats the BasicDual number as a pair of numbers, or 2D vector, and calculates the dot product as as expected of that.

Definition at line 418 of file Dual.hpp.

◆ dualscalar_normsquared

template<class T >
constexpr T dualscalar_normsquared ( const BasicDual< T > &  d)
friend

Calculates the square of the norm

Definition at line 441 of file Dual.hpp.

◆ dualscalar_sqrt

template<class T >
constexpr BasicDual< T > dualscalar_sqrt ( const BasicDual< T > &  input)
friend

Calculates the square root of a BasicDual

This treats the input as a BasicDual scalar and calculates the square root based on that expectation.

Returns
The BasicDual as a dual scalar

Definition at line 431 of file Dual.hpp.

◆ format

template<class T >
std::string format ( const BasicDual< T > &  input)
friend

Definition at line 468 of file Dual.hpp.

◆ operator==

template<class T >
constexpr bool operator== ( const BasicDual< T > &  left,
const BasicDual< T > &  right 
)
friend

Defines equality of two Duals

Note
Uses approximately_equal_to under-the-hood
Use C++20's ability to generate the operator !=() from operator ==()
See also
Equality

Definition at line 129 of file Dual.hpp.

Member Data Documentation

◆ dual

template<class T >
T dual {}

Definition at line 110 of file Dual.hpp.

◆ real

template<class T >
T real {}

Definition at line 109 of file Dual.hpp.


The documentation for this class was generated from the following file: