file
Functions.hFunctions usable with scalar and vector types.
Contents
Namespaces
- namespace Magnum
- Root namespace.
- namespace Magnum::Math
- Math library.
Functions
-
template<class Integral>auto div(Integral x, Integral y) -> std::
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.
-
template<std::auto reflect(const Vector<size, T>& vector, const Vector<size, T>& normal) -> Vector<size, T> new in 2020.06
size_t size, class T> - Reflect a vector.
-
template<std::auto refract(const Vector<size, T>& vector, const Vector<size, T>& normal, T eta) -> Vector<size, T> new in 2020.06
size_t size, class T> - Refract a vector.
Trigonometric functions
Unlike std::
-
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) -> std::
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<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<class T>auto min(T value, T min) -> std::
enable_if<IsScalar<T>::value, T>::type constexpr - Minimum.
-
template<class T>auto max(T a, T b) -> std::
enable_if<IsScalar<T>::value, T>::type constexpr - Maximum.
-
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 constexpr - Clamp value.
-
template<class T>auto sign(const T& scalar) -> std::
enable_if<IsScalar<T>::value, T>::type - Sign.
-
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>auto fmod(T a, T b) -> std::
enable_if<IsScalar<T>::value, T>::type new in Git master - Floating point division remainder.
-
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 - Power.
-
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.