![]() |
XII Release 0.1.0
|
This namespace provides common math-functionality as functions. More...
Functions | |
template<typename TYPE> | |
constexpr TYPE | Pi () |
Returns the natural constant Pi. | |
template<typename TYPE> | |
constexpr TYPE | e () |
Returns the natural constant e. | |
template<typename TYPE> | |
constexpr TYPE | Phi () |
Returns the constant Phi (a+b/a). | |
template<typename TYPE> | |
constexpr bool | SupportsNaN () |
Returns whether the template type supports specialized values to represent NaN. | |
template<typename TYPE> | |
constexpr TYPE | NaN () |
Returns the value for NaN as the template type. Returns zero, if the type does not support NaN. | |
template<typename TYPE> | |
constexpr bool | SupportsInfinity () |
Returns whether the template type supports specialized values to represent Infinity. | |
template<typename TYPE> | |
constexpr TYPE | Infinity () |
Returns the value for Infinity as the template type. Returns zero, if the type does not support Infinity. | |
template<typename TYPE> | |
constexpr TYPE | MaxValue () |
Returns the largest possible positive value (that is not infinity). | |
template<typename TYPE> | |
constexpr TYPE | MinValue () |
Returns the smallest possible value (that is not -infinity). Usually zero or -MaxValue(). For signed integers this will be -MaxValue() - 1. | |
template<typename TYPE> | |
constexpr TYPE | HighValue () |
A very large value, that is slightly smaller than sqrt(MaxValue()). | |
template<typename TYPE> | |
constexpr TYPE | FloatEpsilon () |
The difference between 1.0 and the next representable value for the given type. | |
template<typename TYPE> | |
constexpr TYPE | SmallEpsilon () |
template<typename TYPE> | |
constexpr TYPE | DefaultEpsilon () |
template<typename TYPE> | |
constexpr TYPE | LargeEpsilon () |
template<typename TYPE> | |
constexpr TYPE | HugeEpsilon () |
template<typename TYPE> | |
constexpr xiiUInt32 | NumBits () |
Returns the number of bits in the given type. Mostly useful for unsigned integer types. | |
double | EaseConstantZero (double t) |
double | EaseConstantQuarter (double t) |
double | EaseConstantHalf (double t) |
double | EaseConstantThreeFourths (double t) |
double | EaseConstantOne (double t) |
double | EaseInLinear (double t) |
double | EaseOutLinear (double t) |
double | EaseInOutLinear (double t) |
double | EaseInSine (double t) |
double | EaseOutSine (double t) |
double | EaseInOutSine (double t) |
double | EaseInQuad (double t) |
double | EaseOutQuad (double t) |
double | EaseInOutQuad (double t) |
double | EaseInCubic (double t) |
double | EaseOutCubic (double t) |
double | EaseInOutCubic (double t) |
double | EaseInQuartic (double t) |
double | EaseOutQuartic (double t) |
double | EaseInOutQuartic (double t) |
double | EaseInQuintic (double t) |
double | EaseOutQuintic (double t) |
double | EaseInOutQuintic (double t) |
double | EaseInExpo (double t) |
double | EaseOutExpo (double t) |
double | EaseInOutExpo (double t) |
double | EaseInCirc (double t) |
double | EaseOutCirc (double t) |
double | EaseInOutCirc (double t) |
double | EaseInBack (double t) |
double | EaseOutBack (double t) |
double | EaseInOutBack (double t) |
double | EaseInElastic (double t) |
double | EaseOutElastic (double t) |
double | EaseInOutElastic (double t) |
double | EaseInBounce (double t) |
double | EaseOutBounce (double t) |
double | EaseInOutBounce (double t) |
double | EaseConical (double t) |
double | EaseFadeInHoldFadeOut (double t) |
double | EaseFadeInFadeOut (double t) |
double | EaseBell (double t) |
template<> | |
constexpr float | Pi () |
template<> | |
constexpr double | Pi () |
template<> | |
constexpr float | Phi () |
template<> | |
constexpr double | Phi () |
template<> | |
constexpr float | e () |
template<> | |
constexpr double | e () |
template<> | |
constexpr bool | SupportsNaN< float > () |
template<> | |
constexpr bool | SupportsNaN< double > () |
template<> | |
constexpr float | NaN () |
template<> | |
constexpr double | NaN () |
template<> | |
constexpr bool | SupportsInfinity< float > () |
template<> | |
constexpr bool | SupportsInfinity< double > () |
template<> | |
constexpr float | Infinity () |
template<> | |
constexpr double | Infinity () |
template<> | |
constexpr xiiUInt8 | MaxValue () |
template<> | |
constexpr xiiUInt16 | MaxValue () |
template<> | |
constexpr xiiUInt32 | MaxValue () |
template<> | |
constexpr xiiUInt64 | MaxValue () |
template<> | |
constexpr xiiInt8 | MaxValue () |
template<> | |
constexpr xiiInt16 | MaxValue () |
template<> | |
constexpr xiiInt32 | MaxValue () |
template<> | |
constexpr xiiInt64 | MaxValue () |
template<> | |
constexpr float | MaxValue () |
template<> | |
constexpr double | MaxValue () |
template<> | |
constexpr xiiUInt8 | MinValue () |
template<> | |
constexpr xiiUInt16 | MinValue () |
template<> | |
constexpr xiiUInt32 | MinValue () |
template<> | |
constexpr xiiUInt64 | MinValue () |
template<> | |
constexpr xiiInt8 | MinValue () |
template<> | |
constexpr xiiInt16 | MinValue () |
template<> | |
constexpr xiiInt32 | MinValue () |
template<> | |
constexpr xiiInt64 | MinValue () |
template<> | |
constexpr float | MinValue () |
template<> | |
constexpr double | MinValue () |
template<> | |
constexpr float | HighValue () |
template<> | |
constexpr double | HighValue () |
template<> | |
constexpr float | FloatEpsilon () |
template<> | |
constexpr double | FloatEpsilon () |
template<> | |
constexpr xiiUInt32 | NumBits< xiiUInt8 > () |
template<> | |
constexpr xiiUInt32 | NumBits< xiiUInt16 > () |
template<> | |
constexpr xiiUInt32 | NumBits< xiiUInt32 > () |
template<> | |
constexpr xiiUInt32 | NumBits< xiiUInt64 > () |
template<> | |
constexpr xiiUInt32 | NumBits< xiiInt8 > () |
template<> | |
constexpr xiiUInt32 | NumBits< xiiInt16 > () |
template<> | |
constexpr xiiUInt32 | NumBits< xiiInt32 > () |
template<> | |
constexpr xiiUInt32 | NumBits< xiiInt64 > () |
template<> | |
constexpr xiiUInt32 | NumBits< float > () |
template<> | |
constexpr xiiUInt32 | NumBits< double > () |
template<typename T> | |
constexpr XII_ALWAYS_INLINE T | Square (T f) |
Returns f * f. | |
template<typename T> | |
constexpr XII_ALWAYS_INLINE T | Sign (T f) |
Returns the sign of f (i.e: -1, 1 or 0) | |
template<typename T> | |
constexpr XII_ALWAYS_INLINE T | Abs (T f) |
Returns the absolute value of f. | |
template<typename T> | |
constexpr XII_ALWAYS_INLINE T | Min (T f1, T f2) |
Returns the smaller value, f1 or f2. | |
template<typename T, typename... ARGS> | |
constexpr XII_ALWAYS_INLINE T | Min (T f1, T f2, ARGS... f) |
Returns the smaller value, f1 or f2 or ... | |
template<typename T> | |
constexpr XII_ALWAYS_INLINE T | Max (T f1, T f2) |
Returns the greater value, f1 or f2. | |
template<typename T, typename... ARGS> | |
constexpr XII_ALWAYS_INLINE T | Max (T f1, T f2, ARGS... f) |
template<typename T> | |
constexpr XII_ALWAYS_INLINE T | Clamp (T value, T min_val, T max_val) |
Clamps "value" to the range [min; max]. Returns "value", if it is inside the range already. | |
template<typename T> | |
constexpr XII_ALWAYS_INLINE T | Saturate (T value) |
Clamps "value" to the range [0; 1]. Returns "value", if it is inside the range already. | |
template<typename Type> | |
constexpr Type | Invert (Type f) |
Returns 1 / f. | |
XII_ALWAYS_INLINE xiiUInt32 | FirstBitLow (xiiUInt32 uiBitmask) |
Returns the index of the least significant bit set. | |
XII_ALWAYS_INLINE xiiUInt32 | FirstBitLow (xiiUInt64 uiBitmask) |
Returns the index of the least significant bit set. | |
XII_ALWAYS_INLINE xiiUInt32 | FirstBitHigh (xiiUInt32 uiBitmask) |
Returns the index of the most significant bit set. | |
XII_ALWAYS_INLINE xiiUInt32 | FirstBitHigh (xiiUInt64 uiBitmask) |
Returns the index of the most significant bit set. | |
XII_ALWAYS_INLINE xiiUInt32 | CountTrailingZeros (xiiUInt32 uiBitmask) |
XII_ALWAYS_INLINE xiiUInt32 | CountTrailingZeros (xiiUInt64 uiBitmask) |
64 bit overload for CountTrailingZeros() | |
XII_ALWAYS_INLINE xiiUInt32 | CountLeadingZeros (xiiUInt32 uiBitmask) |
XII_ALWAYS_INLINE xiiUInt32 | CountBits (xiiUInt32 value) |
Returns the number of bits set. | |
XII_ALWAYS_INLINE xiiUInt32 | CountBits (xiiUInt64 value) |
Returns the number of bits set. | |
template<typename Type> | |
XII_ALWAYS_INLINE constexpr Type | Bitmask_LowN (xiiUInt32 uiNumBitsToSet) |
Creates a bitmask in which the low N bits are set. For example for N=5, this would be '0000 ... 0001 1111'. | |
template<typename Type> | |
XII_ALWAYS_INLINE constexpr Type | Bitmask_HighN (xiiUInt32 uiNumBitsToSet) |
Creates a bitmask in which the high N bits are set. For example for N=5, this would be '1111 1000 ... 0000'. | |
template<typename T> | |
XII_ALWAYS_INLINE void | Swap (T &ref_f1, T &ref_f2) |
Swaps the values in the two variables f1 and f2. | |
template<typename T> | |
XII_FORCE_INLINE T | Lerp (T f1, T f2, float fFactor) |
Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1. | |
template<typename T> | |
XII_FORCE_INLINE T | Lerp (T f1, T f2, double fFactor) |
Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1. | |
template<typename T> | |
XII_FORCE_INLINE constexpr float | Unlerp (T fMin, T fMax, T fValue) |
Returns the interpolation factor such that Lerp(fMin, fMax, factor) == fValue. | |
template<typename T> | |
XII_FORCE_INLINE constexpr double | UnlerpDouble (T fMin, T fMax, T fValue) |
Returns the interpolation factor such that Lerp(fMin, fMax, factor) == fValue. | |
template<typename T> | |
constexpr XII_FORCE_INLINE T | Step (T value, T edge) |
Returns 0, if value < edge, and 1, if value >= edge. | |
constexpr XII_FORCE_INLINE bool | IsPowerOf2 (xiiInt32 value) |
Returns true, if there exists some x with 2^x == value. | |
constexpr XII_FORCE_INLINE bool | IsPowerOf2 (xiiUInt32 value) |
Returns true, if there exists some x with 2^x == value. | |
constexpr XII_FORCE_INLINE bool | IsPowerOf2 (xiiInt64 value) |
Returns true, if there exists some x with 2^x == value. | |
constexpr XII_FORCE_INLINE bool | IsPowerOf2 (xiiUInt64 value) |
Returns true, if there exists some x with 2^x == value. | |
template<typename Type> | |
constexpr bool | IsEqual (Type lhs, Type rhs, Type fEpsilon) |
Checks, whether fValue is in the range [fDesired - fMaxImprecision; fDesired + fMaxImprecision]. | |
template<typename T> | |
constexpr bool | IsInRange (T value, T minVal, T maxVal) |
Checks whether the value of the first parameter lies between the value of the second and third. | |
template<typename Type> | |
bool | IsZero (Type f, Type fEpsilon) |
Checks whether the given number is close to zero. | |
template<typename Type> | |
XII_ALWAYS_INLINE Type | Trunc (Type f) |
Returns the integer-part of f (removes the fraction). | |
template<typename Type> | |
XII_ALWAYS_INLINE Type | Fraction (Type f) |
Returns the fraction-part of f. | |
template<typename Type> | |
Type | SmoothStep (Type value, Type edge1, Type edge2) |
Returns 0, if value is <= edge1, 1 if value >= edge2 and the hermite interpolation in between. | |
template<typename Type> | |
Type | SmootherStep (Type value, Type edge1, Type edge2) |
Returns 0, if value is <= edge1, 1 if value >= edge2 and the second order hermite interpolation in between. | |
template<xiiUInt32 BitCount> | |
xiiUInt32 | ColorFloatToUnsignedInt (float value) |
Converts a color value from float [0;1] range to unsigned int with the given number of bits, with proper rounding. | |
xiiUInt8 | ColorFloatToByte (float value) |
Converts a color value from float [0;1] range to unsigned byte [0;255] range, with proper rounding. | |
xiiUInt16 | ColorFloatToShort (float value) |
Converts a color value from float [0;1] range to unsigned short [0;65535] range, with proper rounding. | |
xiiInt8 | ColorFloatToSignedByte (float value) |
Converts a color value from float [-1;1] range to signed byte [-127;127] range, with proper rounding. | |
xiiInt16 | ColorFloatToSignedShort (float value) |
Converts a color value from float [-1;1] range to signed short [-32767;32767] range, with proper rounding. | |
constexpr float | ColorByteToFloat (xiiUInt8 value) |
Converts a color value from unsigned byte [0;255] range to float [0;1] range, with proper rounding. | |
constexpr float | ColorShortToFloat (xiiUInt16 value) |
Converts a color value from unsigned short [0;65535] range to float [0;1] range, with proper rounding. | |
constexpr float | ColorSignedByteToFloat (xiiInt8 value) |
Converts a color value from signed byte [-128;127] range to float [-1;1] range, with proper rounding. | |
constexpr float | ColorSignedShortToFloat (xiiInt16 value) |
Converts a color value from signed short [-32768;32767] range to float [0;1] range, with proper rounding. | |
template<typename T, typename T2> | |
T | EvaluateBezierCurve (T2 t, const T &startPoint, const T &controlPoint1, const T &controlPoint2, const T &endPoint) |
Evaluates the cubic spline defined by four control points at time t and returns the interpolated result. Can be used with T as float, vec2, vec3 or vec4. | |
template<> | |
XII_ALWAYS_INLINE double | Sin (xiiAngleTemplate< double > a) |
template<> | |
XII_ALWAYS_INLINE double | Cos (xiiAngleTemplate< double > a) |
template<> | |
XII_ALWAYS_INLINE double | Tan (xiiAngleTemplate< double > a) |
template<> | |
XII_ALWAYS_INLINE xiiAngleTemplate< double > | ASin (double f) |
template<> | |
XII_ALWAYS_INLINE xiiAngleTemplate< double > | ACos (double f) |
template<> | |
XII_ALWAYS_INLINE xiiAngleTemplate< double > | ATan (double f) |
template<> | |
XII_ALWAYS_INLINE xiiAngleTemplate< double > | ATan2 (double y, double x) |
XII_ALWAYS_INLINE bool | IsFinite (double value) |
XII_ALWAYS_INLINE bool | IsNaN (double value) |
XII_ALWAYS_INLINE double | Floor (double f) |
Returns the next smaller integer, closest to f. Also the SMALLER value, if f is negative. | |
XII_ALWAYS_INLINE double | Ceil (double f) |
Returns the next higher integer, closest to f. Also the HIGHER value, if f is negative. | |
XII_ALWAYS_INLINE double | Round (double f) |
Rounds f to the next integer. | |
double | RoundDown (double f, double fMultiple) |
Returns a multiple of fMultiple that is smaller than f. | |
double | RoundUp (double f, double fMultiple) |
Returns a multiple of fMultiple that is larger than f. | |
XII_ALWAYS_INLINE double | RoundToMultiple (double f, double fMultiple) |
Rounds f to the closest value of multiple. | |
XII_ALWAYS_INLINE double | Exp (double f) |
Returns e^f. | |
XII_ALWAYS_INLINE double | Ln (double f) |
Returns the logarithmus naturalis of f. | |
XII_ALWAYS_INLINE double | Log2 (double f) |
Returns log (f), to the base 2. | |
XII_ALWAYS_INLINE double | Log10 (double f) |
Returns log (f), to the base 10. | |
XII_ALWAYS_INLINE double | Log (double fBase, double f) |
Returns log (f), to the base fBase. | |
XII_ALWAYS_INLINE double | Pow2 (double f) |
Returns 2^f. | |
XII_ALWAYS_INLINE double | Pow (double fBase, double fExp) |
Returns base^exp. | |
XII_ALWAYS_INLINE double | Root (double f, double fNthRoot) |
XII_ALWAYS_INLINE double | Sqrt (double f) |
Returns the square root of f. | |
XII_ALWAYS_INLINE double | Mod (double f, double fDiv) |
Returns "value mod div" for doubles. This also works with negative numbers, both for value and for div. | |
XII_ALWAYS_INLINE double | Hypot (double x, double y) |
Returns the hypotenuse of a given x and y term. | |
XII_ALWAYS_INLINE double | NormalizeToRange (double value, double fMin, double fMax) |
Calculates a value between 0 and 1, given the precondition that the value is between the min and the max. 0 means value = min and 1 means value = max. | |
template<> | |
XII_ALWAYS_INLINE float | Sin (xiiAngleTemplate< float > a) |
template<> | |
XII_ALWAYS_INLINE float | Cos (xiiAngleTemplate< float > a) |
template<> | |
XII_ALWAYS_INLINE float | Tan (xiiAngleTemplate< float > a) |
template<> | |
XII_ALWAYS_INLINE xiiAngleTemplate< float > | ASin (float f) |
template<> | |
XII_ALWAYS_INLINE xiiAngleTemplate< float > | ACos (float f) |
template<> | |
XII_ALWAYS_INLINE xiiAngleTemplate< float > | ATan (float f) |
template<> | |
XII_ALWAYS_INLINE xiiAngleTemplate< float > | ATan2 (float y, float x) |
XII_ALWAYS_INLINE bool | IsFinite (float value) |
XII_ALWAYS_INLINE bool | IsNaN (float value) |
XII_ALWAYS_INLINE float | Floor (float f) |
Returns the next smaller integer, closest to f. Also the SMALLER value, if f is negative. | |
XII_ALWAYS_INLINE xiiInt32 | FloorToInt (float f) |
Returns the next smaller integer, closest to f. Also the SMALLER value, if f is negative. | |
XII_ALWAYS_INLINE float | Ceil (float f) |
Returns the next higher integer, closest to f. Also the HIGHER value, if f is negative. | |
XII_ALWAYS_INLINE xiiInt32 | CeilToInt (float f) |
Returns the next higher integer, closest to f. Also the HIGHER value, if f is negative. | |
XII_ALWAYS_INLINE float | Round (float f) |
Rounds f to the next integer. | |
XII_ALWAYS_INLINE xiiInt32 | RoundToInt (float f) |
Rounds f to the next integer. | |
XII_ALWAYS_INLINE float | RoundToMultiple (float f, float fMultiple) |
Rounds f to the closest value of multiple. | |
float | RoundDown (float f, float fMultiple) |
Returns a multiple of fMultiple that is smaller than f. | |
float | RoundUp (float f, float fMultiple) |
Returns a multiple of fMultiple that is larger than f. | |
XII_ALWAYS_INLINE float | Exp (float f) |
Returns e^f. | |
XII_ALWAYS_INLINE float | Ln (float f) |
Returns the logarithmus naturalis of f. | |
XII_ALWAYS_INLINE float | Log2 (float f) |
Returns log (f), to the base 2. | |
XII_ALWAYS_INLINE float | Log10 (float f) |
Returns log (f), to the base 10. | |
XII_ALWAYS_INLINE float | Log (float fBase, float f) |
Returns log (f), to the base fBase. | |
XII_ALWAYS_INLINE float | Pow2 (float f) |
Returns 2^f. | |
XII_ALWAYS_INLINE float | Pow (float fBase, float fExp) |
Returns base^exp. | |
XII_ALWAYS_INLINE float | Root (float f, float fNthRoot) |
Returns the n-th root of f. | |
XII_ALWAYS_INLINE float | Sqrt (float f) |
Returns the square root of f. | |
XII_ALWAYS_INLINE float | Mod (float value, float fDiv) |
Returns "value mod div" for floats. This also works with negative numbers, both for value and for div. | |
XII_ALWAYS_INLINE float | Hypot (float x, float y) |
Returns the hypotenuse of a given x and y term. | |
XII_ALWAYS_INLINE float | NormalizeToRange (float value, float fMin, float fMax) |
Calculates a value between 0 and 1, given the precondition that the value is between the min and the max. 0 means value = min and 1 means value = max. | |
constexpr XII_ALWAYS_INLINE xiiInt32 | RoundUp (xiiInt32 value, xiiUInt16 uiMultiple) |
Returns a multiple of the given multiple that is larger than or equal to value. | |
constexpr XII_ALWAYS_INLINE xiiInt32 | RoundDown (xiiInt32 value, xiiUInt16 uiMultiple) |
Returns a multiple of the given multiple that is smaller than or equal to value. | |
constexpr XII_ALWAYS_INLINE xiiUInt32 | RoundUp (xiiUInt32 value, xiiUInt16 uiMultiple) |
Returns a multiple of the given multiple that is greater than or equal to value. | |
constexpr XII_ALWAYS_INLINE xiiUInt32 | RoundDown (xiiUInt32 value, xiiUInt16 uiMultiple) |
Returns a multiple of the given multiple that is smaller than or equal to value. | |
constexpr XII_ALWAYS_INLINE bool | IsOdd (xiiInt32 i) |
Returns true, if i is an odd number. | |
constexpr XII_ALWAYS_INLINE bool | IsEven (xiiInt32 i) |
Returns true, if i is an even number. | |
XII_ALWAYS_INLINE xiiUInt32 | Log2i (xiiUInt32 uiVal) |
Returns the integral logarithm to the base 2, that comes closest to the given integer. | |
constexpr XII_ALWAYS_INLINE xiiInt32 | Pow2 (xiiInt32 i) |
Returns 2^f. | |
xiiInt32 | Pow (xiiInt32 iBase, xiiInt32 iExp) |
Returns base^exp. | |
template<typename Type> | |
Type | Sin (xiiAngleTemplate< Type > a) |
***** Trigonometric Functions ***** | |
template<typename Type> | |
Type | Cos (xiiAngleTemplate< Type > a) |
Takes an angle, returns its cosine. | |
template<typename Type> | |
Type | Tan (xiiAngleTemplate< Type > a) |
Takes an angle, returns its tangent. | |
template<typename Type> | |
xiiAngleTemplate< Type > | ASin (Type f) |
Returns the arcus sinus of f. | |
template<typename Type> | |
xiiAngleTemplate< Type > | ACos (Type f) |
Returns the arcus cosinus of f. | |
template<typename Type> | |
xiiAngleTemplate< Type > | ATan (Type f) |
Returns the arcus tangent of f. | |
template<typename Type> | |
xiiAngleTemplate< Type > | ATan2 (Type y, Type x) |
Returns the atan2 of x and y. | |
template<typename T> | |
constexpr T | Square (T f) |
Returns f * f. | |
template<typename T> | |
constexpr T | Sign (T f) |
Returns the sign of f (i.e: -1, 1 or 0) | |
template<typename T> | |
constexpr T | Abs (T f) |
Returns the absolute value of f. | |
template<typename T> | |
constexpr T | Min (T f1, T f2) |
Returns the smaller value, f1 or f2. | |
template<typename T, typename... ARGS> | |
constexpr T | Min (T f1, T f2, ARGS... f) |
Returns the smaller value, f1 or f2 or ... | |
template<typename T> | |
constexpr T | Max (T f1, T f2) |
Returns the greater value, f1 or f2. | |
template<typename T> | |
constexpr T | Clamp (T value, T min_val, T max_val) |
Clamps "value" to the range [min; max]. Returns "value", if it is inside the range already. | |
constexpr xiiUInt32 | WrapUInt (xiiUInt32 uiValue, xiiUInt32 uiExcludedMaxValue) |
Wraps uiValue around the maximum value, so that it stays within the range [0; uiExcludedMaxValue-1]. | |
constexpr xiiInt32 | WrapInt (xiiInt32 iValue, xiiUInt32 uiExcludedMaxValue) |
Wraps iValue around the maximum value, so that it stays within the range [0; uiExcludedMaxValue-1]. | |
constexpr xiiInt32 | WrapInt (xiiInt32 iValue, xiiInt32 iMinValue, xiiInt32 iExcludedMaxValue) |
Wraps iValue around the minimum and maximum value, so that it stays within the range [iMinValue; iExcludedMaxValue-1]. | |
float | WrapFloat01 (float fValue) |
Wraps a float value around to stay within the [0; 1] range. | |
float | WrapFloat (float fValue, float fMinValue, float fMaxValue) |
Wraps a float value around to stay within the [min; max] range. | |
template<typename T> | |
constexpr T | Saturate (T value) |
Clamps "value" to the range [0; 1]. Returns "value", if it is inside the range already. | |
template<typename Type> | |
Type | Trunc (Type f) |
Returns the integer-part of f (removes the fraction). | |
constexpr xiiInt32 | FloatToInt (float value) |
Casts the float to an integer, removes the fractional part. | |
constexpr xiiInt64 | FloatToInt (double value) |
Casts the float to an integer, removes the fractional part. | |
template<typename Type> | |
Type | Fraction (Type f) |
Returns the fraction-part of f. | |
template<typename Type> | |
constexpr Type | Bitmask_LowN (xiiUInt32 uiNumBitsToSet) |
Creates a bitmask in which the low N bits are set. For example for N=5, this would be '0000 ... 0001 1111'. | |
template<typename Type> | |
constexpr Type | Bitmask_HighN (xiiUInt32 uiNumBitsToSet) |
Creates a bitmask in which the high N bits are set. For example for N=5, this would be '1111 1000 ... 0000'. | |
template<typename T> | |
void | Swap (T &ref_f1, T &ref_f2) |
Swaps the values in the two variables f1 and f2. | |
template<typename T> | |
T | Lerp (T f1, T f2, float fFactor) |
Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1. | |
template<typename T> | |
T | Lerp (T f1, T f2, double fFactor) |
Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1. | |
template<typename T> | |
constexpr float | Unlerp (T fMin, T fMax, T fValue) |
Returns the interpolation factor such that Lerp(fMin, fMax, factor) == fValue. | |
template<typename T> | |
constexpr double | UnlerpDouble (T fMin, T fMax, T fValue) |
Returns the interpolation factor such that Lerp(fMin, fMax, factor) == fValue. | |
template<typename T> | |
constexpr T | Step (T value, T edge) |
Returns 0, if value < edge, and 1, if value >= edge. | |
XII_FOUNDATION_DLL bool | IsPowerOf (xiiInt32 value, xiiInt32 iBase) |
Returns true, if there exists some x with base^x == value. | |
XII_FOUNDATION_DLL xiiUInt32 | PowerOfTwo_Floor (xiiUInt32 value) |
Returns the next power-of-two that is <= value. | |
XII_FOUNDATION_DLL xiiUInt64 | PowerOfTwo_Floor (xiiUInt64 value) |
Returns the next power-of-two that is <= value. | |
XII_FOUNDATION_DLL xiiUInt32 | PowerOfTwo_Ceil (xiiUInt32 value) |
Returns the next power-of-two that is >= value. | |
XII_FOUNDATION_DLL xiiUInt64 | PowerOfTwo_Ceil (xiiUInt64 value) |
Returns the next power-of-two that is >= value. | |
XII_FOUNDATION_DLL xiiUInt32 | GreatestCommonDivisor (xiiUInt32 a, xiiUInt32 b) |
Returns the greatest common divisor. | |
XII_FOUNDATION_DLL xiiResult | TryMultiply32 (xiiUInt32 &out_uiResult, xiiUInt32 a, xiiUInt32 b, xiiUInt32 c=1, xiiUInt32 d=1) |
out_Result = a * b. If an overflow happens, XII_FAILURE is returned. | |
XII_FOUNDATION_DLL xiiUInt32 | SafeMultiply32 (xiiUInt32 a, xiiUInt32 b, xiiUInt32 c=1, xiiUInt32 d=1) |
returns a * b. If an overflow happens, the program is terminated. | |
XII_FOUNDATION_DLL xiiResult | TryMultiply64 (xiiUInt64 &out_uiResult, xiiUInt64 a, xiiUInt64 b, xiiUInt64 c=1, xiiUInt64 d=1) |
out_Result = a * b. If an overflow happens, XII_FAILURE is returned. | |
XII_FOUNDATION_DLL xiiUInt64 | SafeMultiply64 (xiiUInt64 a, xiiUInt64 b, xiiUInt64 c=1, xiiUInt64 d=1) |
returns a * b. If an overflow happens, the program is terminated. | |
xiiResult | TryConvertToSizeT (size_t &out_uiResult, xiiUInt64 uiValue) |
Checks whether the given 64bit value actually fits into size_t, If it doesn't XII_FAILURE is returned. | |
XII_FOUNDATION_DLL size_t | SafeConvertToSizeT (xiiUInt64 uiValue) |
Checks whether the given 64bit value actually fits into size_t, If it doesn't the program is terminated. | |
XII_FOUNDATION_DLL float | ReplaceNaN (float fValue, float fFallback) |
If 'value' is not-a-number (NaN) 'fallback' is returned, otherwise 'value' is passed through unmodified. | |
XII_FOUNDATION_DLL double | ReplaceNaN (double fValue, double fFallback) |
If 'value' is not-a-number (NaN) 'fallback' is returned, otherwise 'value' is passed through unmodified. | |
xiiVariant | Lerp (const xiiVariant &a, const xiiVariant &b, double fFactor) |
An overload of xiiMath::Lerp to interpolate variants. A and b must have the same type. | |
This namespace provides common math-functionality as functions.
It is a namespace, instead of a static class, because that allows it to be extended at other locations, which is especially useful when adding custom types.
|
nodiscardconstexpr |
Creates a bitmask in which the high N bits are set. For example for N=5, this would be '1111 1000 ... 0000'.
For N >= 32 all bits will be set.
|
nodiscardconstexpr |
Creates a bitmask in which the high N bits are set. For example for N=5, this would be '1111 1000 ... 0000'.
For N >= 32 all bits will be set.
|
nodiscardconstexpr |
Creates a bitmask in which the low N bits are set. For example for N=5, this would be '0000 ... 0001 1111'.
For N >= 32 all bits will be set.
|
nodiscardconstexpr |
Creates a bitmask in which the low N bits are set. For example for N=5, this would be '0000 ... 0001 1111'.
For N >= 32 all bits will be set.
|
nodiscard |
Returns the next higher integer, closest to f. Also the HIGHER value, if f is negative.
This function is identical to 'Ceil()' except that it already returns the result cast to an int.
|
nodiscard |
Returns the number of zeros at the start (most significant part) of a bitmask.
E.g. 0b0111 -> 29 0b0011 -> 30 0b0001 -> 31 0b0000 -> 32 Returns 32 when the input is 0
|
nodiscard |
Returns the number of zeros at the end (least significant part) of a bitmask.
E.g. 0b0111 -> 0 0b0110 -> 1 0b0100 -> 2 Returns 32 when the input is 0
|
nodiscard |
Returns the index of the most significant bit set.
Asserts that bitmask is not 0.
|
nodiscard |
Returns the index of the most significant bit set.
Asserts that bitmask is not 0.
|
nodiscard |
Returns the index of the least significant bit set.
Asserts that bitmask is not 0.
|
nodiscard |
Returns the index of the least significant bit set.
Asserts that bitmask is not 0.
|
nodiscardconstexpr |
|
nodiscardconstexpr |
|
nodiscard |
Returns the next smaller integer, closest to f. Also the SMALLER value, if f is negative.
This function is identical to 'Floor()' except that it already returns the result cast to an int.
|
constexpr |
A very large value, that is slightly smaller than sqrt(MaxValue()).
Useful to default initialize values, that may get squared in subsequent operations.
XII_FOUNDATION_DLL xiiVariant xiiMath::Lerp | ( | const xiiVariant & | a, |
const xiiVariant & | b, | ||
double | fFactor ) |
An overload of xiiMath::Lerp to interpolate variants. A and b must have the same type.
If the type can't be interpolated like e.g. strings, a is returned for a fFactor less than 0.5, b is returned for a fFactor greater or equal to 0.5.
|
constexpr |
Returns the value for NaN as the template type. Returns zero, if the type does not support NaN.
Do not use this for comparisons, it will fail. Use it to initialize data (e.g. in debug builds), to detect uninitialized variables. Use the function IsNaN() to check whether a value is not a number.
|
nodiscard |
Rounds f to the next integer.
If f is positive 0.5 is rounded UP (i.e. to 1), if f is negative, -0.5 is rounded DOWN (i.e. to -1).
|
nodiscard |
Rounds f to the next integer.
If f is positive 0.5 is rounded UP (i.e. to 1), if f is negative, -0.5 is rounded DOWN (i.e. to -1).
|
nodiscard |
Rounds f to the next integer.
If f is positive 0.5 is rounded UP (i.e. to 1), if f is negative, -0.5 is rounded DOWN (i.e. to -1).
This function is identical to 'Round()' except that it already returns the result cast to an int.
|
nodiscard |
***** Trigonometric Functions *****
Takes an angle, returns its sine.
|
nodiscard |
Wraps a float value around to stay within the [min; max] range.
Both fMinValue and fMaxValue are inclusive. Both values may be negative, but fMinValue has to be strictly smaller than fMaxValue.
|
nodiscard |
Wraps a float value around to stay within the [0; 1] range.
Wrapping happens in both positive and negative direction. Ie -0.1f will be wrapped to 0.9f and 1.1f will be wrapped to 0.1f. Note that here the value 1.0f is included in the range. Only values larger than 1.0f get wrapped back to zero. Therefore it is different to what 'Fraction' would return.
|
nodiscardconstexpr |
Wraps iValue around the minimum and maximum value, so that it stays within the range [iMinValue; iExcludedMaxValue-1].
Ie a value of iExcludedMaxValue would be wrapped to iMinValue, and (iExcludedMaxValue+1) to (iMinValue+1), etc. Values below iMinValue are wrapped back around to a large value, ie (iMinValue-1) would be wrapped to (iExcludedMaxValue-1).
Both iMinValue and iExcludedMaxValue can be negative, but iMinValue has to be strictly smaller than iExcludedMaxValue.
|
nodiscardconstexpr |
Wraps iValue around the maximum value, so that it stays within the range [0; uiExcludedMaxValue-1].
Ie a value of uiExcludedMaxValue would be wrapped to 0, and (uiExcludedMaxValue+1) to 1, etc. Negative values are wrapped back around to a large value, ie -1 would be wrapped to (uiExcludedMaxValue-1). A value of 0 for uiExcludedMaxValue is invalid and results in a division by zero error.
|
nodiscardconstexpr |
Wraps uiValue around the maximum value, so that it stays within the range [0; uiExcludedMaxValue-1].
Ie a value of uiExcludedMaxValue would be wrapped to 0, and (uiExcludedMaxValue+1) to 1, etc. A value of 0 for uiExcludedMaxValue is invalid and results in a division by zero error.