template<class T>
Magnum::Math::Dual class

Dual number.

Template parameters
T Underlying data type

Usually denoted as the following in equations, with $ a_0 $ being the real() part and $ a_\epsilon $ the dual() part:

\[ \hat a = a_0 + \epsilon a_\epsilon \]

Public types

using Type = T
Underlying data type.

Constructors, destructors, conversion operators

Dual() constexpr noexcept
Default constructor.
Dual(ZeroInitT) explicit constexpr noexcept
Construct zero-initialized dual number.
Dual(NoInitT) explicit noexcept
Construct without initializing the contents.
Dual(const T& real, const T& dual = T()) constexpr noexcept
Construct a dual number from real and dual part.
template<class U>
Dual(const Dual<U>& other) explicit constexpr noexcept
Construct a dual number from another of different type.

Public functions

auto data() -> T*
Raw data.
auto data() const -> const T*
auto operator==(const Dual<T>& other) const -> bool
Equality comparison.
auto operator!=(const Dual<T>& other) const -> bool
Non-equality comparison.
auto real() -> T&
Real part ( $ a_0 $ )
auto real() const -> const T constexpr
auto dual() -> T&
Dual part ( $ a_\epsilon $ )
auto dual() const -> const T constexpr
auto operator+() const -> Dual<T> new in Git master
Promotion.
auto operator+=(const Dual<T>& other) -> Dual<T>&
Add and assign dual number.
auto operator+(const Dual<T>& other) const -> Dual<T>
Add dual number.
auto operator-() const -> Dual<T>
Negated dual number.
auto operator-=(const Dual<T>& other) -> Dual<T>&
Subtract and assign dual number.
auto operator-(const Dual<T>& other) const -> Dual<T>
Subtract dual number.
template<class U>
auto operator*(const Dual<U>& other) > -> auto
Multiply by dual number.
template<class U, class V = typename std::enable_if<!Implementation::IsDual<U>::value, void>::type>
auto operator*(const U& other) const -> Dual<decltype(std::declval<T>)*std::declval<U>))>
Multiply by real number.
template<class U>
auto operator/(const Dual<U>& other) > -> auto
Divide by dual number.
template<class U, class V = typename std::enable_if<!Implementation::IsDual<U>::value, Dual<decltype(std::declval<T>()/std::declval<U>())>, ::type>
auto operator/(const U& other) const -> V
Divide by real number.
auto conjugated() const -> Dual<T>
Conjugated dual number.

Function documentation

template<class T>
Magnum::Math::Dual<T>::Dual() constexpr noexcept

Default constructor.

Both parts are default-constructed.

template<class T>
Magnum::Math::Dual<T>::Dual(const T& real, const T& dual = T()) constexpr noexcept

Construct a dual number from real and dual part.

\[ \hat a = a_0 + \epsilon a_\epsilon \]

template<class T> template<class U>
Magnum::Math::Dual<T>::Dual(const Dual<U>& other) explicit constexpr noexcept

Construct a dual number from another of different type.

Performs only default casting on the values, no rounding or anything else. Example usage:

Math::Dual<Float> floatingPoint{1.3f, 2.7f};
Math::Dual<Byte> integral{floatingPoint}; // {1, 2}

template<class T>
T* Magnum::Math::Dual<T>::data()

Raw data.

Contrary to what Doxygen shows, returns reference to an one-dimensional fixed-size array of two elements, i.e. T(&)[2].

template<class T>
const T* Magnum::Math::Dual<T>::data() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Dual<T>::real()

Real part ( $ a_0 $ )

template<class T>
const T Magnum::Math::Dual<T>::real() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Dual<T>::dual()

Dual part ( $ a_\epsilon $ )

template<class T>
const T Magnum::Math::Dual<T>::dual() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
Dual<T> Magnum::Math::Dual<T>::operator+() const new in Git master

Promotion.

Returns the value as-is.

template<class T>
Dual<T>& Magnum::Math::Dual<T>::operator+=(const Dual<T>& other)

Add and assign dual number.

The computation is done in-place.

\[ \hat a + \hat b = a_0 + b_0 + \epsilon (a_\epsilon + b_\epsilon) \]

template<class T>
Dual<T> Magnum::Math::Dual<T>::operator+(const Dual<T>& other) const

Add dual number.

template<class T>
Dual<T> Magnum::Math::Dual<T>::operator-() const

Negated dual number.

\[ -\hat a = -a_0 - \epsilon a_\epsilon \]

template<class T>
Dual<T>& Magnum::Math::Dual<T>::operator-=(const Dual<T>& other)

Subtract and assign dual number.

The computation is done in-place.

\[ \hat a - \hat b = a_0 - b_0 + \epsilon (a_\epsilon - b_\epsilon) \]

template<class T>
Dual<T> Magnum::Math::Dual<T>::operator-(const Dual<T>& other) const

Subtract dual number.

template<class T> template<class U>
auto Magnum::Math::Dual<T>::operator*(const Dual<U>& other) >

Multiply by dual number.

\[ \hat a \hat b = a_0 b_0 + \epsilon (a_0 b_\epsilon + a_\epsilon b_0) \]

template<class T> template<class U, class V = typename std::enable_if<!Implementation::IsDual<U>::value, void>::type>
Dual<decltype(std::declval<T>)*std::declval<U>))> Magnum::Math::Dual<T>::operator*(const U& other) const

Multiply by real number.

Equivalent to the above assuming that $ b_\epsilon = 0 $ .

\[ \hat a \hat b = a_0 b_0 + \epsilon (a_0 b_\epsilon + a_\epsilon b_0) = a_0 b_0 + \epsilon a_\epsilon b_0 \]

template<class T> template<class U>
auto Magnum::Math::Dual<T>::operator/(const Dual<U>& other) >

Divide by dual number.

\[ \frac{\hat a}{\hat b} = \frac{a_0}{b_0} + \epsilon \frac{a_\epsilon b_0 - a_0 b_\epsilon}{b_0^2} \]

template<class T> template<class U, class V = typename std::enable_if<!Implementation::IsDual<U>::value, Dual<decltype(std::declval<T>()/std::declval<U>())>, ::type>
V Magnum::Math::Dual<T>::operator/(const U& other) const

Divide by real number.

Equivalent to the above assuming that $ b_\epsilon = 0 $ .

\[ \frac{\hat a}{\hat b} = \frac{a_0}{b_0} + \epsilon \frac{a_\epsilon b_0 - a_0 b_\epsilon}{b_0^2} = \frac{a_0}{b_0} + \epsilon \frac{a_\epsilon}{b_0} \]

template<class T>
Dual<T> Magnum::Math::Dual<T>::conjugated() const

Conjugated dual number.

\[ \overline{\hat a} = a_0 - \epsilon a_\epsilon \]

template<class T> template<class T, class U, class V = typename std::enable_if<!Implementation::IsDual<T>::value, Dual<decltype(std::declval<T>()*std::declval<U>())>, ::type>
V operator*(const T& a, const Dual<U>& b)

Multiply real number by dual number.

Equivalent to Dual::operator*(const Dual<U>&) const assuming that $ a_\epsilon = 0 $ .

\[ \hat a \hat b = a_0 b_0 + \epsilon (a_0 b_\epsilon + a_\epsilon b_0) = a_0 b_0 + \epsilon a_0 b_\epsilon \]

template<class T> template<class T>
Debug& operator<<(Debug& debug, const Dual<T>& value)

Debug output operator.

template<class T> template<class T>
Dual<T> sqrt(const Dual<T>& dual)

Square root of dual number.

\[ \sqrt{\hat a} = \sqrt{a_0} + \epsilon \frac{a_\epsilon}{2 \sqrt{a_0}} \]

template<class T> template<class T>
Containers::Pair<Dual<T>, Dual<T>> sincos(const Dual<Rad<T>>& angle)

Sine and cosine of dual angle.

\[ \begin{array}{rcl} sin(\hat a) & = & sin(a_0) + \epsilon a_\epsilon cos(a_0) \\ cos(\hat a) & = & cos(a_0) - \epsilon a_\epsilon sin(a_0) \end{array} \]