Magnum/Math/Functions.h file

Functions usable with scalar and vector types.

Namespaces

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

Functions

template<class Integral>
auto div(Integral x, Integral y) -> Containers::Pair<Integral, Integral>
Integer division with remainder.
auto binomialCoefficient(UnsignedInt n, UnsignedInt k) -> UnsignedLong new in Git master
Binomial coefficient.
auto popcount(UnsignedInt number) -> UnsignedInt new in Git master
Count of bits set in a number.
auto popcount(UnsignedLong number) -> UnsignedInt new in Git master
template<std::size_t size, class T>
auto reflect(const Vector<size, T>& vector, const Vector<size, T>& normal) -> Vector<size, T> new in 2020.06
Reflect a vector.
template<std::size_t size, class T>
auto refract(const Vector<size, T>& vector, const Vector<size, T>& normal, T eta) -> Vector<size, T> new in 2020.06
Refract a vector.

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
Sine.
template<class T>
auto cos(Rad<T> angle) -> T
Cosine.
template<class T>
auto sincos(Rad<T> angle) -> Containers::Pair<T, T>
Sine and cosine.
template<class T>
auto tan(Rad<T> angle) -> T
Tangent.
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 new in 2019.10
If given number is a positive or negative infinity.
template<std::size_t size, class T>
auto isInf(const Vector<size, T>& value) -> BitVector<size> new in 2019.10
template<class T>
auto isNan(T value) -> std::enable_if<IsScalar<T>::value, bool>::type new in 2019.10
If given number is a NaN.
template<std::size_t size, class T>
auto isNan(const Vector<size, T>& value) -> BitVector<size> new in 2019.10
template<class T>
auto min(T value, T min) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
Minimum.
template<std::size_t size, class T>
auto min(const Vector<size, T>& value, const Vector<size, T>& min) -> Vector<size, T>
template<std::size_t size, class T>
auto min(const Vector<size, T>& value, T min) -> Vector<size, T>
template<class T>
auto max(T a, T b) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
Maximum.
template<std::size_t size, class T>
auto max(const Vector<size, T>& value, const Vector<size, T>& max) -> Vector<size, T>
template<std::size_t size, class T>
auto max(const Vector<size, T>& value, T max) -> Vector<size, T>
template<class T>
auto minmax(T a, T b) -> std::enable_if<IsScalar<T>::value, Containers::Pair<T, T>>::type
Minimum and maximum of two values.
template<std::size_t size, class T>
auto minmax(const Vector<size, T>& a, const Vector<size, T>& b) -> Containers::Pair<Vector<size, T>, Vector<size, T>>
template<class T>
auto clamp(T value, T min, T max) -> std::enable_if<IsScalar<T>::value, T>::type constexpr
Clamp value.
template<std::size_t size, class T>
auto clamp(const Vector<size, T>& value, const Vector<size, T>& min, const Vector<size, T>& max) -> Vector<size, T>
template<std::size_t size, class T>
auto clamp(const Vector<size, T>& value, T min, T max) -> Vector<size, T>
template<class T>
auto sign(T scalar) -> std::enable_if<IsScalar<T>::value, UnderlyingTypeOf<T>>::type
Sign.
template<std::size_t size, class T>
auto sign(const Vector<size, T>& a) -> Vector<size, UnderlyingTypeOf<T>>
template<class T>
auto abs(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Absolute value.
template<std::size_t size, class T>
auto abs(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto floor(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Nearest not larger integer.
template<std::size_t size, class T>
auto floor(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto round(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Round value to nearest integer.
template<std::size_t size, class T>
auto round(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto ceil(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Nearest not smaller integer.
template<std::size_t size, class T>
auto ceil(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto fmod(T a, T b) -> std::enable_if<IsScalar<T>::value, T>::type new in Git master
Floating point division remainder.
template<std::size_t size, class T>
auto fmod(const Vector<size, T>& a, const Vector<size, T>& b) -> Vector<size, T> new in Git master
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 lerp(const T& a, const T& b, bool t) -> T
template<std::size_t size, class T>
auto lerp(const Vector<size, T>& a, const Vector<size, T>& b, const BitVector<size>& t) -> Vector<size, T>
template<std::size_t size>
auto lerp(const BitVector<size>& a, const BitVector<size>& b, const BitVector<size>& t) -> BitVector<size>
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<std::size_t size, class T>
auto lerpInverted(const Vector<size, T>& a, const Vector<size, T>& b, const Vector<size, T>& lerp) -> Vector<size, UnderlyingTypeOf<T>>
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.
template<std::size_t size, class T>
auto fma(const Vector<size, T>& a, const Vector<size, T>& b, const Vector<size, T>& c) -> Vector<size, T>

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<UnsignedInt exponent, std::size_t size, class T>
auto pow(const Vector<size, T>& base) -> Vector<size, T>
template<class T>
auto pow(T base, T exponent) -> std::enable_if<IsScalar<T>::value, T>::type
Power.
template<std::size_t size, class T>
auto pow(const Vector<size, T>& base, T exponent) -> Vector<size, T>
template<class T>
auto sqrt(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Square root.
template<std::size_t size, class T>
auto sqrt(const Vector<size, T>& a) -> Vector<size, T>
template<class T>
auto sqrtInverted(T a) -> std::enable_if<IsScalar<T>::value, T>::type
Inverse square root.
template<std::size_t size, class T>
auto sqrtInverted(const Vector<size, T>& a) -> Vector<size, T>