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

Dual number.

Template parameters
T Underlying data type

Public types

using Type = T
Underlying data type.

Constructors, destructors, conversion operators

Dual() constexpr noexcept
Default constructor.
Dual(ZeroInitT) 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 dual number from real and dual part.
template<class U>
Dual(const Dual<U>& other) explicit constexpr noexcept
Construct dual number from another of different type.
Dual(const Dual<T>&) noexcept defaulted constexpr
Copy constructor.

Public functions

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.
auto real() const -> T constexpr
auto dual() -> T&
Dual part.
auto dual() const -> T constexpr
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 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 dual number from another of different type.

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

Dual<Float> floatingPoint(1.3f, 2.7f);
Dual<Byte> integral(floatingPoint);
// integral == {1, 2}

template<class T>
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() 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 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>
Corrade::Utility::Debug& operator<<(Corrade::Utility::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>
std::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} \]