Plasma Engine  2.0
Loading...
Searching...
No Matches
plMath Namespace Reference

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 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 plUInt32 NumBits ()
 Returns the number of bits in the given type. Mostly useful for unsigned integer types.
 
double GetCurveValue_Linear (double t)
 
double GetCurveValue_ConstantZero (double t)
 
double GetCurveValue_ConstantOne (double t)
 
double GetCurveValue_EaseInSine (double t)
 
double GetCurveValue_EaseOutSine (double t)
 
double GetCurveValue_EaseInOutSine (double t)
 
double GetCurveValue_EaseInQuad (double t)
 
double GetCurveValue_EaseOutQuad (double t)
 
double GetCurveValue_EaseInOutQuad (double t)
 
double GetCurveValue_EaseInCubic (double t)
 
double GetCurveValue_EaseOutCubic (double t)
 
double GetCurveValue_EaseInOutCubic (double t)
 
double GetCurveValue_EaseInQuartic (double t)
 
double GetCurveValue_EaseOutQuartic (double t)
 
double GetCurveValue_EaseInOutQuartic (double t)
 
double GetCurveValue_EaseInQuintic (double t)
 
double GetCurveValue_EaseOutQuintic (double t)
 
double GetCurveValue_EaseInOutQuintic (double t)
 
double GetCurveValue_EaseInExpo (double t)
 
double GetCurveValue_EaseOutExpo (double t)
 
double GetCurveValue_EaseInOutExpo (double t)
 
double GetCurveValue_EaseInCirc (double t)
 
double GetCurveValue_EaseOutCirc (double t)
 
double GetCurveValue_EaseInOutCirc (double t)
 
double GetCurveValue_EaseInBack (double t)
 
double GetCurveValue_EaseOutBack (double t)
 
double GetCurveValue_EaseInOutBack (double t)
 
double GetCurveValue_EaseInElastic (double t)
 
double GetCurveValue_EaseOutElastic (double t)
 
double GetCurveValue_EaseInOutElastic (double t)
 
double GetCurveValue_EaseInBounce (double t)
 
double GetCurveValue_EaseOutBounce (double t)
 
double GetCurveValue_EaseInOutBounce (double t)
 
double GetCurveValue_Conical (double t)
 
double GetCurveValue_FadeInHoldFadeOut (double t)
 
double GetCurveValue_FadeInFadeOut (double t)
 
double GetCurveValue_Bell (double t)
 
template<>
constexpr float Pi ()
 
template<>
constexpr double Pi ()
 
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 plUInt8 MaxValue ()
 
template<>
constexpr plUInt16 MaxValue ()
 
template<>
constexpr plUInt32 MaxValue ()
 
template<>
constexpr plUInt64 MaxValue ()
 
template<>
constexpr plInt8 MaxValue ()
 
template<>
constexpr plInt16 MaxValue ()
 
template<>
constexpr plInt32 MaxValue ()
 
template<>
constexpr plInt64 MaxValue ()
 
template<>
constexpr float MaxValue ()
 
template<>
constexpr double MaxValue ()
 
template<>
constexpr plUInt8 MinValue ()
 
template<>
constexpr plUInt16 MinValue ()
 
template<>
constexpr plUInt32 MinValue ()
 
template<>
constexpr plUInt64 MinValue ()
 
template<>
constexpr plInt8 MinValue ()
 
template<>
constexpr plInt16 MinValue ()
 
template<>
constexpr plInt32 MinValue ()
 
template<>
constexpr plInt64 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 plUInt32 NumBits< plUInt8 > ()
 
template<>
constexpr plUInt32 NumBits< plUInt16 > ()
 
template<>
constexpr plUInt32 NumBits< plUInt32 > ()
 
template<>
constexpr plUInt32 NumBits< plUInt64 > ()
 
template<>
constexpr plUInt32 NumBits< plInt8 > ()
 
template<>
constexpr plUInt32 NumBits< plInt16 > ()
 
template<>
constexpr plUInt32 NumBits< plInt32 > ()
 
template<>
constexpr plUInt32 NumBits< plInt64 > ()
 
template<>
constexpr plUInt32 NumBits< float > ()
 
template<>
constexpr plUInt32 NumBits< double > ()
 
template<typename T >
constexpr PL_ALWAYS_INLINE T Square (T f)
 Returns f * f.
 
template<typename T >
constexpr PL_ALWAYS_INLINE T Sign (T f)
 Returns the sign of f (i.e: -1, 1 or 0)
 
template<typename T >
constexpr PL_ALWAYS_INLINE T Abs (T f)
 Returns the absolute value of f.
 
template<typename T >
constexpr PL_ALWAYS_INLINE T Min (T f1, T f2)
 Returns the smaller value, f1 or f2.
 
template<typename T , typename... ARGS>
constexpr PL_ALWAYS_INLINE T Min (T f1, T f2, ARGS... f)
 Returns the smaller value, f1 or f2 or ...
 
template<typename T >
constexpr PL_ALWAYS_INLINE T Max (T f1, T f2)
 Returns the greater value, f1 or f2.
 
template<typename T , typename... ARGS>
constexpr PL_ALWAYS_INLINE T Max (T f1, T f2, ARGS... f)
 
template<typename T >
constexpr PL_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 PL_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.
 
PL_ALWAYS_INLINE plUInt32 FirstBitLow (plUInt32 uiBitmask)
 Returns the index of the least significant bit set.
 
PL_ALWAYS_INLINE plUInt32 FirstBitLow (plUInt64 uiBitmask)
 Returns the index of the least significant bit set.
 
PL_ALWAYS_INLINE plUInt32 FirstBitHigh (plUInt32 uiBitmask)
 Returns the index of the most significant bit set.
 
PL_ALWAYS_INLINE plUInt32 FirstBitHigh (plUInt64 uiBitmask)
 Returns the index of the most significant bit set.
 
PL_ALWAYS_INLINE plUInt32 CountTrailingZeros (plUInt32 uiBitmask)
 
PL_ALWAYS_INLINE plUInt32 CountTrailingZeros (plUInt64 uiBitmask)
 64 bit overload for CountTrailingZeros()
 
PL_ALWAYS_INLINE plUInt32 CountLeadingZeros (plUInt32 uiBitmask)
 
PL_ALWAYS_INLINE plUInt32 CountBits (plUInt32 value)
 Returns the number of bits set.
 
PL_ALWAYS_INLINE plUInt32 CountBits (plUInt64 value)
 Returns the number of bits set.
 
template<typename Type >
PL_ALWAYS_INLINE Type Bitmask_LowN (plUInt32 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 >
PL_ALWAYS_INLINE Type Bitmask_HighN (plUInt32 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 >
PL_ALWAYS_INLINE void Swap (T &ref_f1, T &ref_f2)
 Swaps the values in the two variables f1 and f2.
 
template<typename T >
PL_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 >
PL_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 >
PL_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 >
constexpr PL_FORCE_INLINE T Step (T value, T edge)
 Returns 0, if value < edge, and 1, if value >= edge.
 
constexpr PL_FORCE_INLINE bool IsPowerOf2 (plInt32 value)
 Returns true, if there exists some x with 2^x == value.
 
constexpr PL_FORCE_INLINE bool IsPowerOf2 (plUInt32 value)
 Returns true, if there exists some x with 2^x == value.
 
constexpr PL_FORCE_INLINE bool IsPowerOf2 (plUInt64 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 >
PL_ALWAYS_INLINE Type Trunc (Type f)
 Returns the integer-part of f (removes the fraction).
 
template<typename Type >
PL_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.
 
plUInt8 ColorFloatToByte (float value)
 Converts a color value from float [0;1] range to unsigned byte [0;255] range, with proper rounding.
 
plUInt16 ColorFloatToShort (float value)
 Converts a color value from float [0;1] range to unsigned short [0;65535] range, with proper rounding.
 
plInt8 ColorFloatToSignedByte (float value)
 Converts a color value from float [-1;1] range to signed byte [-127;127] range, with proper rounding.
 
plInt16 ColorFloatToSignedShort (float value)
 Converts a color value from float [-1;1] range to signed short [-32767;32767] range, with proper rounding.
 
constexpr float ColorByteToFloat (plUInt8 value)
 Converts a color value from unsigned byte [0;255] range to float [0;1] range, with proper rounding.
 
constexpr float ColorShortToFloat (plUInt16 value)
 Converts a color value from unsigned short [0;65535] range to float [0;1] range, with proper rounding.
 
constexpr float ColorSignedByteToFloat (plInt8 value)
 Converts a color value from signed byte [-128;127] range to float [-1;1] range, with proper rounding.
 
constexpr float ColorSignedShortToFloat (plInt16 value)
 Converts a color value from signed short [-32768;32767] range to float [0;1] range, with proper rounding.
 
template<typename T , typename T2 >
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.
 
PL_ALWAYS_INLINE bool IsFinite (double value)
 
PL_ALWAYS_INLINE bool IsNaN (double value)
 
PL_ALWAYS_INLINE double Floor (double f)
 
PL_ALWAYS_INLINE double Ceil (double f)
 
PL_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.
 
PL_ALWAYS_INLINE double RoundToMultiple (double f, double fMultiple)
 Rounds f to the closest value of multiple.
 
PL_ALWAYS_INLINE double Exp (double f)
 
PL_ALWAYS_INLINE double Ln (double f)
 
PL_ALWAYS_INLINE double Log2 (double f)
 
PL_ALWAYS_INLINE double Log10 (double f)
 
PL_ALWAYS_INLINE double Log (double fBase, double f)
 
PL_ALWAYS_INLINE double Pow2 (double f)
 
PL_ALWAYS_INLINE double Pow (double fBase, double fExp)
 
PL_ALWAYS_INLINE double Root (double f, double fNthRoot)
 
PL_ALWAYS_INLINE double Sqrt (double f)
 Returns the square root of f.
 
PL_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.
 
PL_ALWAYS_INLINE bool IsFinite (float value)
 
PL_ALWAYS_INLINE bool IsNaN (float value)
 
PL_ALWAYS_INLINE float Floor (float f)
 Returns the next smaller integer, closest to f. Also the SMALLER value, if f is negative.
 
PL_ALWAYS_INLINE float Ceil (float f)
 Returns the next higher integer, closest to f. Also the HIGHER value, if f is negative.
 
PL_ALWAYS_INLINE float Round (float f)
 Rounds f to the next integer.
 
PL_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.
 
PL_ALWAYS_INLINE float Sin (plAngle a)
 ***** Trigonometric Functions *****
 
PL_ALWAYS_INLINE float Cos (plAngle a)
 Takes an angle, returns its cosine.
 
PL_ALWAYS_INLINE float Tan (plAngle a)
 Takes an angle, returns its tangent.
 
PL_ALWAYS_INLINE plAngle ASin (float f)
 Returns the arcus sinus of f.
 
PL_ALWAYS_INLINE plAngle ACos (float f)
 Returns the arcus cosinus of f.
 
PL_ALWAYS_INLINE plAngle ATan (float f)
 Returns the arcus tangent of f.
 
PL_ALWAYS_INLINE plAngle ATan2 (float y, float x)
 Returns the atan2 of x and y.
 
PL_ALWAYS_INLINE float Exp (float f)
 Returns e^f.
 
PL_ALWAYS_INLINE float Ln (float f)
 Returns the logarithmus naturalis of f.
 
PL_ALWAYS_INLINE float Log2 (float f)
 Returns log (f), to the base 2.
 
PL_ALWAYS_INLINE float Log10 (float f)
 Returns log (f), to the base 10.
 
PL_ALWAYS_INLINE float Log (float fBase, float f)
 Returns log (f), to the base fBase.
 
PL_ALWAYS_INLINE float Pow2 (float f)
 Returns 2^f.
 
PL_ALWAYS_INLINE float Pow (float fBase, float fExp)
 Returns base^exp.
 
PL_ALWAYS_INLINE float Root (float f, float fNthRoot)
 Returns the n-th root of f.
 
PL_ALWAYS_INLINE float Sqrt (float f)
 Returns the square root of f.
 
PL_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.
 
constexpr PL_ALWAYS_INLINE plInt32 RoundUp (plInt32 value, plUInt16 uiMultiple)
 Returns a multiple of the given multiple that is larger than or equal to value.
 
constexpr PL_ALWAYS_INLINE plInt32 RoundDown (plInt32 value, plUInt16 uiMultiple)
 Returns a multiple of the given multiple that is smaller than or equal to value.
 
constexpr PL_ALWAYS_INLINE plUInt32 RoundUp (plUInt32 value, plUInt16 uiMultiple)
 Returns a multiple of the given multiple that is greater than or equal to value.
 
constexpr PL_ALWAYS_INLINE plUInt32 RoundDown (plUInt32 value, plUInt16 uiMultiple)
 Returns a multiple of the given multiple that is smaller than or equal to value.
 
constexpr PL_ALWAYS_INLINE bool IsOdd (plInt32 i)
 Returns true, if i is an odd number.
 
constexpr PL_ALWAYS_INLINE bool IsEven (plInt32 i)
 Returns true, if i is an even number.
 
PL_ALWAYS_INLINE plUInt32 Log2i (plUInt32 uiVal)
 Returns the integral logarithm to the base 2, that comes closest to the given integer.
 
constexpr PL_ALWAYS_INLINE int Pow2 (int i)
 
int Pow (int iBase, int iExp)
 
constexpr plInt32 Pow2 (plInt32 i)
 Returns 2^f.
 
plInt32 Pow (plInt32 iBase, plInt32 iExp)
 Returns base^exp.
 
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.
 
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 plInt32 FloatToInt (float value)
 Casts the float to an integer, removes the fractional part.
 
constexpr plInt64 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 >
Type Bitmask_LowN (plUInt32 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 >
Type Bitmask_HighN (plUInt32 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 >
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 >
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 T Step (T value, T edge)
 Returns 0, if value < edge, and 1, if value >= edge.
 
PL_FOUNDATION_DLL bool IsPowerOf (plInt32 value, plInt32 iBase)
 Returns true, if there exists some x with base^x == value.
 
PL_FOUNDATION_DLL plUInt32 PowerOfTwo_Floor (plUInt32 value)
 Returns the next power-of-two that is <= value.
 
PL_FOUNDATION_DLL plUInt64 PowerOfTwo_Floor (plUInt64 value)
 Returns the next power-of-two that is <= value.
 
PL_FOUNDATION_DLL plUInt32 PowerOfTwo_Ceil (plUInt32 value)
 Returns the next power-of-two that is >= value.
 
PL_FOUNDATION_DLL plUInt64 PowerOfTwo_Ceil (plUInt64 value)
 Returns the next power-of-two that is >= value.
 
PL_FOUNDATION_DLL plUInt32 GreatestCommonDivisor (plUInt32 a, plUInt32 b)
 Returns the greatest common divisor.
 
PL_FOUNDATION_DLL plResult TryMultiply32 (plUInt32 &out_uiResult, plUInt32 a, plUInt32 b, plUInt32 c=1, plUInt32 d=1)
 out_Result = a * b. If an overflow happens, PL_FAILURE is returned.
 
PL_FOUNDATION_DLL plUInt32 SafeMultiply32 (plUInt32 a, plUInt32 b, plUInt32 c=1, plUInt32 d=1)
 returns a * b. If an overflow happens, the program is terminated.
 
PL_FOUNDATION_DLL plResult TryMultiply64 (plUInt64 &out_uiResult, plUInt64 a, plUInt64 b, plUInt64 c=1, plUInt64 d=1)
 out_Result = a * b. If an overflow happens, PL_FAILURE is returned.
 
PL_FOUNDATION_DLL plUInt64 SafeMultiply64 (plUInt64 a, plUInt64 b, plUInt64 c=1, plUInt64 d=1)
 returns a * b. If an overflow happens, the program is terminated.
 
plResult TryConvertToSizeT (size_t &out_uiResult, plUInt64 uiValue)
 Checks whether the given 64bit value actually fits into size_t, If it doesn't PL_FAILURE is returned.
 
PL_FOUNDATION_DLL size_t SafeConvertToSizeT (plUInt64 uiValue)
 Checks whether the given 64bit value actually fits into size_t, If it doesn't the program is terminated.
 
PL_FOUNDATION_DLL float ReplaceNaN (float fValue, float fFallback)
 If 'value' is not-a-number (NaN) 'fallback' is returned, otherwise 'value' is passed through unmodified.
 
PL_FOUNDATION_DLL double ReplaceNaN (double fValue, double fFallback)
 If 'value' is not-a-number (NaN) 'fallback' is returned, otherwise 'value' is passed through unmodified.
 
plVariant Lerp (const plVariant &a, const plVariant &b, double fFactor)
 An overload of plMath::Lerp to interpolate variants. A and b must have the same type.
 

Detailed Description

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.

Function Documentation

◆ Bitmask_HighN() [1/2]

template<typename Type >
PL_ALWAYS_INLINE Type plMath::Bitmask_HighN ( plUInt32 uiNumBitsToSet)
nodiscard

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.

◆ Bitmask_HighN() [2/2]

template<typename Type >
Type plMath::Bitmask_HighN ( plUInt32 uiNumBitsToSet)
nodiscard

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.

◆ Bitmask_LowN() [1/2]

template<typename Type >
PL_ALWAYS_INLINE Type plMath::Bitmask_LowN ( plUInt32 uiNumBitsToSet)
nodiscard

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.

◆ Bitmask_LowN() [2/2]

template<typename Type >
Type plMath::Bitmask_LowN ( plUInt32 uiNumBitsToSet)
nodiscard

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.

◆ CountLeadingZeros()

plUInt32 plMath::CountLeadingZeros ( plUInt32 uiBitmask)
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

◆ CountTrailingZeros()

plUInt32 plMath::CountTrailingZeros ( plUInt32 uiBitmask)
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

◆ FirstBitHigh() [1/2]

plUInt32 plMath::FirstBitHigh ( plUInt32 uiBitmask)
nodiscard

Returns the index of the most significant bit set.

Asserts that bitmask is not 0.

◆ FirstBitHigh() [2/2]

plUInt32 plMath::FirstBitHigh ( plUInt64 uiBitmask)
nodiscard

Returns the index of the most significant bit set.

Asserts that bitmask is not 0.

◆ FirstBitLow() [1/2]

plUInt32 plMath::FirstBitLow ( plUInt32 uiBitmask)
nodiscard

Returns the index of the least significant bit set.

Asserts that bitmask is not 0.

◆ FirstBitLow() [2/2]

plUInt32 plMath::FirstBitLow ( plUInt64 uiBitmask)
nodiscard

Returns the index of the least significant bit set.

Asserts that bitmask is not 0.

◆ FloatToInt() [1/2]

PL_FORCE_INLINE plInt64 plMath::FloatToInt ( double value)
nodiscardconstexpr

Casts the float to an integer, removes the fractional part.

See also
Trunc, Round, Floor, Ceil

◆ FloatToInt() [2/2]

PL_FORCE_INLINE plInt32 plMath::FloatToInt ( float value)
nodiscardconstexpr

Casts the float to an integer, removes the fractional part.

See also
Trunc, Round, Floor, Ceil

◆ HighValue()

template<typename TYPE >
TYPE plMath::HighValue ( )
constexpr

A very large value, that is slightly smaller than sqrt(MaxValue()).

Useful to default initialize values, that may get squared in subsequent operations.

◆ Lerp()

PL_FOUNDATION_DLL plVariant plMath::Lerp ( const plVariant & a,
const plVariant & b,
double fFactor )

An overload of plMath::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.

◆ NaN()

template<typename TYPE >
TYPE plMath::NaN ( )
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.

◆ Round() [1/2]

double plMath::Round ( double f)
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).

◆ Round() [2/2]

float plMath::Round ( float f)
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).

◆ Sin()

float plMath::Sin ( plAngle a)
nodiscard

***** Trigonometric Functions *****

Takes an angle, returns its sine