Magnum/Math/Functions.h file

Functions usable with scalar and vector types.


namespace Magnum
Root namespace.
namespace Magnum::Math
Math library.


template<class Integral>
auto div(Integral x, Integral y) -> std::pair<Integral, Integral>
Integer division with remainder.

Trigonometric functions

Unlike std::sin() and friends, those take or return strongly-typed units to prevent degrees being accidentally interpreted as radians and such. See Deg and Rad for more information.

template<class T>
auto sin(Rad<T> angle) -> T
template<class T>
auto cos(Rad<T> angle) -> T
template<class T>
auto sincos(Rad<T> angle) -> std::pair<T, T>
Sine and cosine.
template<class T>
auto tan(Rad<T> angle) -> T
template<class T>
auto asin(T value) -> Rad<T>
Arc sine.
template<class T>
auto acos(T value) -> Rad<T>
Arc cosine.
template<class T>
auto atan(T value) -> Rad<T>
Arc tangent.

Scalar/vector functions

These functions are overloaded for both scalar and vector types, including Deg and Rad. Scalar versions function exactly as their possible STL equivalents, vector overloads perform the operations component-wise.

template<class T>
auto isInf(T value) -> std::enable_if<IsScalar<T>::value, bool>::type
If given number is a positive or negative infinity.
template<class T>
auto isNan(T value) -> std::enable_if<IsScalar<T>::value, bool>::type
If given number is a NaN.
template<class T>
auto min(T value, T min) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
template<class T>
auto max(T a, T b) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
template<class T>
auto minmax(T a, T b) -> std::enable_if<IsScalar<T>::value, std::pair<T, T>>::type
Minimum and maximum of two values.
template<class T>
auto clamp(T value, T min, T max) -> std::enable_if<IsScalar<T>::value, T>::type
Clamp value.
template<class T>
auto sign(const T& scalar) -> std::enable_if<IsScalar<T>::value, T>::type
template<class T>
auto abs(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Absolute value.
template<class T>
auto floor(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Nearest not larger integer.
template<class T>
auto round(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Round value to nearest integer.
template<class T>
auto ceil(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Nearest not smaller integer.
template<class T, class U>
auto lerp(const T& a, const T& b, U t) -> T
Linear interpolation of two values.
template<class T>
auto lerpInverted(T a, T b, T lerp) -> UnderlyingTypeOf<typename std::enable_if<IsScalar<T>::value, T>::type>
Inverse linear interpolation of two values.
template<class T, class U>
auto select(const T& a, const T& b, U t) -> T constexpr
Constant interpolation of two values.
template<class T>
auto fma(T a, T b, T c) -> std::enable_if<IsScalar<T>::value, T>::type
Fused multiply-add.

Exponential and power functions

Unlike scalar/vector functions these don't work on Deg / Rad as the resulting unit can't be easily expressed.

auto log(UnsignedInt base, UnsignedInt number) -> UnsignedInt
Integral logarithm.
auto log2(UnsignedInt number) -> UnsignedInt
Base-2 integral logarithm.
template<class T>
auto log(T number) -> T
Natural logarithm.
template<class T>
auto exp(T exponent) -> T
Natural exponential.
template<UnsignedInt exponent, class T>
auto pow(T base) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
Integral power.
template<class T>
auto pow(T base, T exponent) -> std::enable_if<IsScalar<T>::value, T>::type
template<class T>
auto sqrt(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Square root.
template<class T>
auto sqrtInverted(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Inverse square root.