PixelLightAPI  .
Static Public Member Functions | Static Public Attributes
PLMath::Math Class Reference

Static class with some useful math constants and functions. More...

#include <Math.h>

List of all members.

Static Public Member Functions

static bool IsNotANumber (float fValue)
 Checks whether the given float-precision floating-point value is not a number (NAN)
static bool IsNotANumber (double dValue)
 Checks whether the given double-precision floating-point value is not a number (NAN)
static bool IsFinite (float fValue)
 Checks whether the given float-precision floating-point value is finite.
static bool IsFinite (double dValue)
 Checks whether the given double-precision floating-point value is finite.
static bool IsPowerOfTwo (int nNumber)
 Check's whether the given the number is a power of 2.
static int GetNearestPowerOfTwo (int nNumber, bool bLower=true)
 Returns the nearest power of 2.
static PLCore::uint32 GetRand ()
 Returns a positive random number.
static int GetRandNeg ()
 Returns a positive or negative random number.
static float GetRandFloat ()
 Returns a positive float random number between 0..1.
static float GetRandNegFloat ()
 Returns a positive or negative float random number between -1..1.
static float GetRandMinMaxFloat (float fMin, float fMax)
 Returns a float random number between the given minimum/maximum.
static bool AreEqual (float f1, float f2, float fEpsilon=Math::Epsilon)
 Returns a whether to given numbers are equal or not.
static bool AreEqual (double d1, double d2, double dEpsilon=Math::Epsilon)
 Returns a whether to given numbers are equal or not.
static float Min (float a, float b)
 Returns the minimum of the 2 given values.
static int Min (int a, int b)
static PLCore::uint32 Min (PLCore::uint32 a, PLCore::uint32 b)
static float Max (float a, float b)
 Returns the maximum of the 2 given values.
static int Max (int a, int b)
static PLCore::uint32 Max (PLCore::uint32 a, PLCore::uint32 b)
static float Min (float a, float b, float c, float d)
 Returns the minimum of the 4 given values.
static int Min (int a, int b, int c, int d)
static PLCore::uint32 Min (PLCore::uint32 a, PLCore::uint32 b, PLCore::uint32 c, PLCore::uint32 d)
static float Max (float a, float b, float c, float d)
 Returns the maximum of the 4 given values.
static int Max (int a, int b, int c, int d)
static PLCore::uint32 Max (PLCore::uint32 a, PLCore::uint32 b, PLCore::uint32 c, PLCore::uint32 d)
static float Sign (float x)
 Returns the sign of the given value.
static float ClampToInterval (float fValue, float fMin, float fMax)
 Ensures that the given value is within the given interval [fMin, fMax] by clamping the value.
static float WrapToInterval (float fValue, float fMin, float fMax)
 Ensures that the given value is within the given interval [fMin, fMax] by wrapping the value.
static int Abs (int x)
 Returns the absolute value of the given value.
static float Abs (float x)
 Returns the absolute value of the given value.
static double Abs (double x)
 Returns the absolute value of the given value.
static void Swap (float &a, float &b)
 Swaps two given values.
static float Saturate (float fValue)
 Clamps the value between 0.0 and 1.0.
static float Floor (float fValue)
 Returns the floor of the given value.
static float Ceil (float fValue)
 Returns the ceil of the given value.
static float Round (float fValue, PLCore::uint32 nPrecision=0)
 Returns the rounded value of the given value.
static float Sin (float fAngle)
 Returns the sine of a given angle.
static double Sin (double dAngle)
 Returns the sine of a given angle.
static float ASin (float fValue)
 Returns the arcsine of a given value.
static double ASin (double dValue)
 Returns the arcsine of a given value.
static float Cos (float fAngle)
 Returns the cosine (cos) of a given angle.
static double Cos (double dAngle)
 Returns the cosine (cos) of a given angle.
static float ACos (float fValue)
 Returns the arccosine of a given value.
static double ACos (double dValue)
 Returns the arccosine of a given value.
static float Tan (float fAngle)
 Returns the tangent (tan) of a given angle.
static double Tan (double dAngle)
 Returns the tangent (tan) of a given angle.
static float ATan (float fValue)
 Returns the arctangent of a given value.
static double ATan (double dValue)
 Returns the arctangent of a given value.
static float ATan2 (float fX, float fY)
 Returns the arctangent of of y/x.
static double ATan2 (double dX, double dY)
 Returns the arctangent of of y/x.
static float Sqrt (float fValue)
 Returns the square-root of a given value.
static double Sqrt (double dValue)
 Returns the square-root of a given value.
static float FastInvSqrt (float fValue)
 Returns the inverse square-root of a given value.
static float Pow (float x, float y)
 Returns x raised to the power of y.
static double Pow (double x, double y)
 Returns x raised to the power of y.
static double Pow (int x, int y)
 Returns x raised to the power of y.
static float Log (float x)
 Returns the natural logarithm of a given number.
static double Log (double x)
 Returns the natural logarithm of a given number.
static float Log2 (float x)
 Returns the base 2 logarithm for a given number, as long as it is not negative, or zero.
static double Log2 (double x)
 Returns the base 2 logarithm for a given number, as long as it is not negative, or zero.
static float Exp (float x)
 Returns the e number raised to the power x.
static double Exp (double x)
 Returns the e number raised to the power x.

Static Public Attributes

static PLMATH_API const double Pi
static PLMATH_API const double Pi2
static PLMATH_API const double PiHalf
static PLMATH_API const double DegToRad
static PLMATH_API const double RadToDeg
static PLMATH_API const double Epsilon
static PLMATH_API const double Log2Const
static PLMATH_API const int RandMax

Detailed Description

Static class with some useful math constants and functions.


Member Function Documentation

bool PLMath::Math::IsNotANumber ( float  fValue) [inline, static]

Checks whether the given float-precision floating-point value is not a number (NAN)

Returns:
'true' if the value is not a number, else 'false'
bool PLMath::Math::IsNotANumber ( double  dValue) [inline, static]

Checks whether the given double-precision floating-point value is not a number (NAN)

Returns:
'true' if the value is not a number, else 'false'
bool PLMath::Math::IsFinite ( float  fValue) [inline, static]

Checks whether the given float-precision floating-point value is finite.

Returns:
'true' if the value is finite, (–INF < fValue < +INF) else 'false' (infinite or not a number)
bool PLMath::Math::IsFinite ( double  dValue) [inline, static]

Checks whether the given double-precision floating-point value is finite.

Returns:
'true' if the value is finite, (–INF < dValue < +INF) else 'false' (infinite or not a number)
bool PLMath::Math::IsPowerOfTwo ( int  nNumber) [inline, static]

Check's whether the given the number is a power of 2.

Parameters:
[in]nNumberNumber to check
Returns:
'true' if the number is a power of 2, else 'false'
int PLMath::Math::GetNearestPowerOfTwo ( int  nNumber,
bool  bLower = true 
) [inline, static]

Returns the nearest power of 2.

Parameters:
[in]nNumberNumber to check
[in]bLower'true' take the lower nearest number, else 'false' takes the higher one
Returns:
The nearest power of 2, if it couldn't be found 'nNumber'
PLCore::uint32 PLMath::Math::GetRand ( ) [inline, static]

Returns a positive random number.

Returns:
A positive random number
int PLMath::Math::GetRandNeg ( ) [inline, static]

Returns a positive or negative random number.

Returns:
A positive or negative random number
float PLMath::Math::GetRandFloat ( ) [inline, static]

Returns a positive float random number between 0..1.

Returns:
A positive float random number between 0..1
float PLMath::Math::GetRandNegFloat ( ) [inline, static]

Returns a positive or negative float random number between -1..1.

Returns:
A positive or negative float random number between -1..1
float PLMath::Math::GetRandMinMaxFloat ( float  fMin,
float  fMax 
) [inline, static]

Returns a float random number between the given minimum/maximum.

Parameters:
[in]fMinMinimum (inclusive), must be <= maximum
[in]fMaxMaximum (inclusive), must be >= minimum
Returns:
A float random number between the given minimum/maximum
bool PLMath::Math::AreEqual ( float  f1,
float  f2,
float  fEpsilon = Math::Epsilon 
) [inline, static]

Returns a whether to given numbers are equal or not.

Parameters:
[in]f1First number
[in]f2Second number
[in]fEpsilonError tolerance
Returns:
'true' if the given numbers are equal, else 'false'
bool PLMath::Math::AreEqual ( double  d1,
double  d2,
double  dEpsilon = Math::Epsilon 
) [inline, static]

Returns a whether to given numbers are equal or not.

Parameters:
[in]d1First number
[in]d2Second number
[in]dEpsilonError tolerance
Returns:
'true' if the given numbers are equal, else 'false'
float PLMath::Math::Min ( float  a,
float  b 
) [inline, static]

Returns the minimum of the 2 given values.

Parameters:
[in]aFirst value
[in]bSecond value
Returns:
The minimum of the 2 given values
int PLMath::Math::Min ( int  a,
int  b 
) [inline, static]
PLCore::uint32 PLMath::Math::Min ( PLCore::uint32  a,
PLCore::uint32  b 
) [inline, static]
float PLMath::Math::Max ( float  a,
float  b 
) [inline, static]

Returns the maximum of the 2 given values.

Parameters:
[in]aFirst value
[in]bSecond value
Returns:
The maximum of the 2 given values
int PLMath::Math::Max ( int  a,
int  b 
) [inline, static]
PLCore::uint32 PLMath::Math::Max ( PLCore::uint32  a,
PLCore::uint32  b 
) [inline, static]
float PLMath::Math::Min ( float  a,
float  b,
float  c,
float  d 
) [inline, static]

Returns the minimum of the 4 given values.

Parameters:
[in]aFirst value
[in]bSecond value
[in]cThird value
[in]dFourth value
Returns:
The minimum of the 4 given values
int PLMath::Math::Min ( int  a,
int  b,
int  c,
int  d 
) [inline, static]
PLCore::uint32 PLMath::Math::Min ( PLCore::uint32  a,
PLCore::uint32  b,
PLCore::uint32  c,
PLCore::uint32  d 
) [inline, static]
float PLMath::Math::Max ( float  a,
float  b,
float  c,
float  d 
) [inline, static]

Returns the maximum of the 4 given values.

Parameters:
[in]aFirst value
[in]bSecond value
[in]cThird value
[in]dFourth value
Returns:
The maximum of the 4 given values
int PLMath::Math::Max ( int  a,
int  b,
int  c,
int  d 
) [inline, static]
PLCore::uint32 PLMath::Math::Max ( PLCore::uint32  a,
PLCore::uint32  b,
PLCore::uint32  c,
PLCore::uint32  d 
) [inline, static]
float PLMath::Math::Sign ( float  x) [inline, static]

Returns the sign of the given value.

Parameters:
[in]xValue to check
Returns:
'-1' if the given value is negative, else '1'
float PLMath::Math::ClampToInterval ( float  fValue,
float  fMin,
float  fMax 
) [inline, static]

Ensures that the given value is within the given interval [fMin, fMax] by clamping the value.

Parameters:
[in]fValueValue to check
[in]fMinMinimum of the interval, must be < fMax!
[in]fMaxMaximum of the interval, must be > fMin!
Returns:
The value within the interval [fMin, fMax]
float PLMath::Math::WrapToInterval ( float  fValue,
float  fMin,
float  fMax 
) [inline, static]

Ensures that the given value is within the given interval [fMin, fMax] by wrapping the value.

Parameters:
[in]fValueValue to check
[in]fMinMinimum of the interval, must be < fMax!
[in]fMaxMaximum of the interval, must be > fMin!
Returns:
The value within the interval [fMin, fMax]
int PLMath::Math::Abs ( int  x) [inline, static]

Returns the absolute value of the given value.

Parameters:
[in]xValue to return the absolute value from
Returns:
Absolute value of the given value
float PLMath::Math::Abs ( float  x) [inline, static]

Returns the absolute value of the given value.

Parameters:
[in]xValue to return the absolute value from
Returns:
Absolute value of the given value
double PLMath::Math::Abs ( double  x) [inline, static]

Returns the absolute value of the given value.

Parameters:
[in]xValue to return the absolute value from
Returns:
Absolute value of the given value
void PLMath::Math::Swap ( float &  a,
float &  b 
) [inline, static]

Swaps two given values.

Parameters:
[in,out]aFirst value
[in,out]bSecond value
float PLMath::Math::Saturate ( float  fValue) [inline, static]

Clamps the value between 0.0 and 1.0.

Parameters:
[in]fValueValue to clamp
Returns:
Clamped value
float PLMath::Math::Floor ( float  fValue) [inline, static]

Returns the floor of the given value.

Parameters:
[in]fValueValue to return the floor from
Returns:
The floor of the given value
Remarks:
This function returns a floating-point value representing the largest integer value that is less than or equal to the given value.
float PLMath::Math::Ceil ( float  fValue) [inline, static]

Returns the ceil of the given value.

Parameters:
[in]fValueValue to return the ceil from
Returns:
The ceil of the given value
Remarks:
This function returns a floating-point value representing the smallest integer value that is greater than or equal to the given value.
float PLMath::Math::Round ( float  fValue,
PLCore::uint32  nPrecision = 0 
) [inline, static]

Returns the rounded value of the given value.

Parameters:
[in]fValueValue to return the rounded value from
[in]nPrecisionNumber of digits after the comma
Returns:
The rounded value of the given value
float PLMath::Math::Sin ( float  fAngle) [inline, static]

Returns the sine of a given angle.

Returns the sine of the given angle.

Parameters:
[in]fAngleAngle in radians
Returns:
Sine of the given angle
Note:
  • If the given angle is greater than or equal to 263, or less than or equal to –263, a loss of significance in the result occurs
  • Sine of 0 is 0
double PLMath::Math::Sin ( double  dAngle) [inline, static]

Returns the sine of a given angle.

Returns the sine of the given angle.

Parameters:
[in]dAngleAngle in radians
Returns:
Sine of the given angle
See also:
float PLMath::Math::ASin ( float  fValue) [inline, static]

Returns the arcsine of a given value.

Parameters:
[in]fValueValue between –1 and 1 whose arcsine is to be calculated
Returns:
Arcsine of the given value
Remarks:
This function returns the arcsine of the given value in the range –p/2 to p/2 radians. If the given value is less than –1 or greater than 1, ASin returns an indefinite (same as a quiet NaN).
double PLMath::Math::ASin ( double  dValue) [inline, static]

Returns the arcsine of a given value.

Parameters:
[in]dValueValue between –1 and 1 whose arcsine is to be calculated
Returns:
Arcsine of the given value
See also:
float PLMath::Math::Cos ( float  fAngle) [inline, static]

Returns the cosine (cos) of a given angle.

Parameters:
[in]fAngleAngle in radians
Returns:
Cosine of the given angle
Note:
  • If the given angle is greater than or equal to 263, or less than or equal to –263, a loss of significance in the result occurs
  • Cosine of 0 is 1
double PLMath::Math::Cos ( double  dAngle) [inline, static]

Returns the cosine (cos) of a given angle.

Parameters:
[in]dAngleAngle in radians
Returns:
Cosine of the given angle
See also:
float PLMath::Math::ACos ( float  fValue) [inline, static]

Returns the arccosine of a given value.

Parameters:
[in]fValueValue between –1 and 1 whose arccosine is to be calculated
Returns:
Arccosine of the given value
Remarks:
This function returns the arccosine of the given value in the range –p/2 to p/2 radians. If the given value is less than –1 or greater than 1, ACos returns an indefinite (same as a quiet NaN).
double PLMath::Math::ACos ( double  dValue) [inline, static]

Returns the arccosine of a given value.

Parameters:
[in]dValueValue between –1 and 1 whose arccosine is to be calculated
Returns:
Arccosine of the given value
See also:
float PLMath::Math::Tan ( float  fAngle) [inline, static]

Returns the tangent (tan) of a given angle.

Parameters:
[in]fAngleAngle in radians
Returns:
Tangent of the given angle
Note:
  • If the given angle is greater than or equal to 263, or less than or equal to –263, a loss of significance in the result occurs
  • Tangent of 0 is 0
double PLMath::Math::Tan ( double  dAngle) [inline, static]

Returns the tangent (tan) of a given angle.

Parameters:
[in]dAngleAngle in radians
Returns:
Tangent of the given angle
See also:
float PLMath::Math::ATan ( float  fValue) [inline, static]

Returns the arctangent of a given value.

Parameters:
[in]fValueValue between –1 and 1 whose arccosine is to be calculated
Returns:
Arccosine of the given value
double PLMath::Math::ATan ( double  dValue) [inline, static]

Returns the arctangent of a given value.

Parameters:
[in]dValueValue between –1 and 1 whose arccosine is to be calculated
Returns:
Arccosine of the given value
float PLMath::Math::ATan2 ( float  fX,
float  fY 
) [inline, static]

Returns the arctangent of of y/x.

Parameters:
[in]fXAny number
[in]fYAny number
Returns:
Arccosine of y/x
Remarks:
Returns a value in the range –p to p radians, using the signs of both parameters to determine the quadrant of the return value
Note:
  • If fX is 0, this function returns 0
  • If both parameters are 0, the function returns 0
double PLMath::Math::ATan2 ( double  dX,
double  dY 
) [inline, static]

Returns the arctangent of of y/x.

Parameters:
[in]dXAny number
[in]dYAny number
Returns:
Arccosine of y/x
See also:
float PLMath::Math::Sqrt ( float  fValue) [inline, static]

Returns the square-root of a given value.

Parameters:
[in]fValueNonnegative floating-point value, if negative, this function returns an indefinite (same as a quiet NaN)
Returns:
The square-root of the given value, indefinite on error
double PLMath::Math::Sqrt ( double  dValue) [inline, static]

Returns the square-root of a given value.

Parameters:
[in]dValueNonnegative floating-point value, if negative, this function returns an indefinite (same as a quiet NaN)
Returns:
The square-root of the given value, indefinite on error
float PLMath::Math::FastInvSqrt ( float  fValue) [inline, static]

Returns the inverse square-root of a given value.

Parameters:
[in]fValueNonnegative floating-point value, if negative, this function returns an indefinite (same as a quiet NaN)
Returns:
The inverse square-root of the given value, indefinite on error
Remarks:
This method is slightly faster then writing "1/Sqrt(<value>)", but may return invalid results. So, be careful when using this method and only use it when you're sure that the results are correct in your use case.
float PLMath::Math::Pow ( float  x,
float  y 
) [inline, static]

Returns x raised to the power of y.

Parameters:
[in]xBase
[in]yExponent
Returns:
x raised to the power of y
double PLMath::Math::Pow ( double  x,
double  y 
) [inline, static]

Returns x raised to the power of y.

Parameters:
[in]xBase
[in]yExponent
Returns:
x raised to the power of y
double PLMath::Math::Pow ( int  x,
int  y 
) [inline, static]

Returns x raised to the power of y.

Parameters:
[in]xBase
[in]yExponent
Returns:
x raised to the power of y
float PLMath::Math::Log ( float  x) [inline, static]

Returns the natural logarithm of a given number.

Parameters:
[in]xGiven number
Returns:
The natural logarithm of the given number
double PLMath::Math::Log ( double  x) [inline, static]

Returns the natural logarithm of a given number.

Parameters:
[in]xGiven number
Returns:
The natural logarithm of the given number
float PLMath::Math::Log2 ( float  x) [inline, static]

Returns the base 2 logarithm for a given number, as long as it is not negative, or zero.

Parameters:
[in]xGiven number
Returns:
The base 2 logarithm for the given number, as long as it is not negative, or zero
Remarks:
Log(x)/Log(2)
double PLMath::Math::Log2 ( double  x) [inline, static]

Returns the base 2 logarithm for a given number, as long as it is not negative, or zero.

Parameters:
[in]xGiven number
Returns:
The base 2 logarithm for the given number, as long as it is not negative, or zero
Remarks:
Log(x)/Log(2)
float PLMath::Math::Exp ( float  x) [inline, static]

Returns the e number raised to the power x.

Parameters:
[in]xGiven number
Returns:
The e number raised to the power x
double PLMath::Math::Exp ( double  x) [inline, static]

Returns the e number raised to the power x.

Parameters:
[in]xGiven number
Returns:
The e number raised to the power x

Member Data Documentation

PLMATH_API const double PLMath::Math::Pi [static]

3.14159265358979323846

PLMATH_API const double PLMath::Math::Pi2 [static]

6.28318530717958623200 (Pi*2)

PLMATH_API const double PLMath::Math::PiHalf [static]

1.57079632679489655800 (Pi/2)

PLMATH_API const double PLMath::Math::DegToRad [static]

0.01745329251994329576 (Pi/180)

PLMATH_API const double PLMath::Math::RadToDeg [static]

57.2957795130823208768 (180/Pi)

PLMATH_API const double PLMath::Math::Epsilon [static]

1.192092896e-07F

PLMATH_API const double PLMath::Math::Log2Const [static]

0.693147180559945309417

PLMATH_API const int PLMath::Math::RandMax [static]

Maximum random value (0x7fff)


The documentation for this class was generated from the following files:


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:20
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported