Functions | |
| template<class T > | |
| T | clamp (T number, T lo, T hi) |
| clamp "number" to a range between lo and hi | |
| template<class T > | |
| bool | quadraticFormula (T &r1, T &r2, const T &a, const T &b, const T &c) |
| Uses the quadratic formula to compute the 2 roots of the given 2nd degree polynomial in the form of Ax^2 + Bx + C. | |
C Math Abstraction | |
| template<typename T > | |
| T | abs (T iValue) |
| float | abs (float iValue) |
| double | abs (double iValue) |
| int | abs (int iValue) |
| long | abs (long iValue) |
| template<typename T > | |
| T | ceil (T fValue) |
| float | ceil (float fValue) |
| double | ceil (double fValue) |
| template<typename T > | |
| T | floor (T fValue) |
| float | floor (float fValue) |
| double | floor (double fValue) |
| template<typename T > | |
| int | sign (T iValue) |
| template<typename T > | |
| T | zeroClamp (T value, T eps=static_cast< T >(0)) |
| Clamps the given value down to zero if it is within epsilon of zero. | |
| template<typename T > | |
| T | aCos (T fValue) |
| float | aCos (float fValue) |
| double | aCos (double fValue) |
| template<typename T > | |
| T | aSin (T fValue) |
| float | aSin (float fValue) |
| double | aSin (double fValue) |
| template<typename T > | |
| T | aTan (T fValue) |
| double | aTan (double fValue) |
| float | aTan (float fValue) |
| template<typename T > | |
| T | aTan2 (T fY, T fX) |
| float | aTan2 (float fY, float fX) |
| double | aTan2 (double fY, double fX) |
| template<typename T > | |
| T | cos (T fValue) |
| float | cos (float fValue) |
| double | cos (double fValue) |
| template<typename T > | |
| T | exp (T fValue) |
| float | exp (float fValue) |
| double | exp (double fValue) |
| template<typename T > | |
| T | log (T fValue) |
| double | log (double fValue) |
| float | log (float fValue) |
| double | pow (double fBase, double fExponent) |
| float | pow (float fBase, float fExponent) |
| template<typename T > | |
| T | sin (T fValue) |
| double | sin (double fValue) |
| float | sin (float fValue) |
| template<typename T > | |
| T | tan (T fValue) |
| double | tan (double fValue) |
| float | tan (float fValue) |
| template<typename T > | |
| T | sqr (T fValue) |
| template<typename T > | |
| T | sqrt (T fValue) |
| double | sqrt (double fValue) |
| float | fastInvSqrt (float x) |
| Fast inverse square root. | |
| float | fastInvSqrt2 (float x) |
| float | fastInvSqrt3 (float x) |
| void | seedRandom (unsigned int seed) |
| Seeds the pseudorandom number generator with the given seed. | |
| float | unitRandom () |
| get a random number between 0 and 1 | |
| float | rangeRandom (float x1, float x2) |
| return a random number between x1 and x2 RETURNS: random number between x1 and x2 | |
| float | deg2Rad (float fVal) |
| double | deg2Rad (double fVal) |
| float | rad2Deg (float fVal) |
| double | rad2Deg (double fVal) |
| template<class T > | |
| bool | isEqual (const T &a, const T &b, const T &tolerance) |
| Is almost equal? test for equality within some tolerance... | |
| template<class T > | |
| T | trunc (T val) |
| cut off the digits after the decimal place | |
| template<class T > | |
| T | round (T p) |
| round to nearest integer | |
| template<class T > | |
| T | Min (const T &x, const T &y) |
| min returns the minimum of 2 values | |
| template<class T > | |
| T | Min (const T &x, const T &y, const T &z) |
| min returns the minimum of 3 values | |
| template<class T > | |
| T | Min (const T &w, const T &x, const T &y, const T &z) |
| min returns the minimum of 4 values | |
| template<class T > | |
| T | Max (const T &x, const T &y) |
| max returns the maximum of 2 values | |
| template<class T > | |
| T | Max (const T &x, const T &y, const T &z) |
| max returns the maximum of 3 values | |
| template<class T > | |
| T | Max (const T &w, const T &x, const T &y, const T &z) |
| max returns the maximum of 4 values | |
| template<class T > | |
| T | factorial (T rhs) |
| Compute the factorial. | |
Scalar type interpolation (for doubles, floats, etc...) | |
| template<class T , typename U > | |
| void | lerp (T &result, const U &lerp, const T &a, const T &b) |
| Linear Interpolation between number [a] and [b]. | |
Variables | |
Mathematical constants | |
| const float | TWO_PI = 6.28318530717958647692f |
| const float | PI = 3.14159265358979323846f |
| const float | PI_OVER_2 = 1.57079632679489661923f |
| const float | PI_OVER_4 = 0.78539816339744830962f |
| T gmtl::Math::abs | ( | T | iValue | ) | [inline] |
| float gmtl::Math::abs | ( | float | iValue | ) | [inline] |
| int gmtl::Math::abs | ( | int | iValue | ) | [inline] |
Definition at line 63 of file Math.h.
{ return ::abs(iValue); }
| long gmtl::Math::abs | ( | long | iValue | ) | [inline] |
| double gmtl::Math::abs | ( | double | iValue | ) | [inline] |
| double gmtl::Math::aCos | ( | double | fValue | ) | [inline] |
Definition at line 159 of file Math.h.
{
if ( -1.0 < fValue )
{
if ( fValue < 1.0 )
return static_cast<double>(::acos(fValue));
else
return 0.0;
}
else
{
return static_cast<double>(gmtl::Math::PI);
}
}
| T gmtl::Math::aCos | ( | T | fValue | ) | [inline] |
| float gmtl::Math::aCos | ( | float | fValue | ) | [inline] |
Definition at line 139 of file Math.h.
{
if ( -1.0f < fValue )
{
if ( fValue < 1.0f )
{
#ifdef NO_ACOSF
return static_cast<float>(::acos(fValue));
#else
return static_cast<float>(::acosf(fValue));
#endif
}
else
return 0.0f;
}
else
{
return static_cast<float>(gmtl::Math::PI);
}
}
| T gmtl::Math::aSin | ( | T | fValue | ) | [inline] |
| float gmtl::Math::aSin | ( | float | fValue | ) | [inline] |
Definition at line 176 of file Math.h.
{
if ( -1.0f < fValue )
{
if ( fValue < 1.0f )
{
#ifdef NO_ASINF
return static_cast<float>(::asin(fValue));
#else
return static_cast<float>(::asinf(fValue));
#endif
}
else
return static_cast<float>(-gmtl::Math::PI_OVER_2);
}
else
{
return static_cast<float>(gmtl::Math::PI_OVER_2);
}
}
| double gmtl::Math::aSin | ( | double | fValue | ) | [inline] |
Definition at line 196 of file Math.h.
{
if ( -1.0 < fValue )
{
if ( fValue < 1.0 )
return static_cast<double>(::asin(fValue));
else
return static_cast<double>(-gmtl::Math::PI_OVER_2);
}
else
{
return static_cast<double>(gmtl::Math::PI_OVER_2);
}
}
| T gmtl::Math::aTan | ( | T | fValue | ) | [inline] |
| double gmtl::Math::aTan | ( | double | fValue | ) | [inline] |
| float gmtl::Math::aTan | ( | float | fValue | ) | [inline] |
| T gmtl::Math::aTan2 | ( | T | fY, | |
| T | fX | |||
| ) | [inline] |
| float gmtl::Math::aTan2 | ( | float | fY, | |
| float | fX | |||
| ) | [inline] |
| double gmtl::Math::aTan2 | ( | double | fY, | |
| double | fX | |||
| ) | [inline] |
| double gmtl::Math::ceil | ( | double | fValue | ) | [inline] |
| T gmtl::Math::ceil | ( | T | fValue | ) | [inline] |
| float gmtl::Math::ceil | ( | float | fValue | ) | [inline] |
| T gmtl::Math::clamp | ( | T | number, | |
| T | lo, | |||
| T | hi | |||
| ) | [inline] |
| T gmtl::Math::cos | ( | T | fValue | ) | [inline] |
| float gmtl::Math::cos | ( | float | fValue | ) | [inline] |
| double gmtl::Math::cos | ( | double | fValue | ) | [inline] |
| float gmtl::Math::deg2Rad | ( | float | fVal | ) | [inline] |
Definition at line 464 of file Math.h.
{
return static_cast<float>(fVal * static_cast<float>(gmtl::Math::PI / 180.0));
}
| double gmtl::Math::deg2Rad | ( | double | fVal | ) | [inline] |
Definition at line 468 of file Math.h.
{
return static_cast<double>(fVal * static_cast<double>(gmtl::Math::PI / 180.0));
}
| T gmtl::Math::exp | ( | T | fValue | ) | [inline] |
| float gmtl::Math::exp | ( | float | fValue | ) | [inline] |
| double gmtl::Math::exp | ( | double | fValue | ) | [inline] |
| T gmtl::Math::factorial | ( | T | rhs | ) | [inline] |
Compute the factorial.
give - an object who's type has operator++, operator=, operator<=, and operator*= defined. it should be a single valued scalar type such as an int, float, double etc.... NOTE: This could be faster with a lookup table, but then wouldn't work templated : kevin
Definition at line 553 of file Math.h.
{
T lhs = static_cast<T>(1);
for( T x = static_cast<T>(1); x <= rhs; ++x )
{
lhs *= x;
}
return lhs;
}
| float gmtl::Math::fastInvSqrt | ( | float | x | ) | [inline] |
Fast inverse square root.
Definition at line 351 of file Math.h.
{
GMTL_STATIC_ASSERT(sizeof(float) == sizeof(int),
Union_type_sizes_do_not_match);
// Use an approach to data type reinterpretation that is safe with GCC
// strict aliasing enabled. This is called type-punning, and it is valid
// when done with a union where the value read (int_value) is different
// than the one most recently written to (float_value).
union
{
float float_value;
int int_value;
} data;
const float xhalf(0.5f*x);
data.float_value = x;
// This hides a good amount of math
data.int_value = 0x5f3759df - (data.int_value >> 1);
x = data.float_value;
x = x*(1.5f - xhalf*x*x); // Repeat for more accuracy
return x;
}
| float gmtl::Math::fastInvSqrt2 | ( | float | x | ) | [inline] |
Definition at line 375 of file Math.h.
{
GMTL_STATIC_ASSERT(sizeof(float) == sizeof(int),
Union_type_sizes_do_not_match);
// Use an approach to data type reinterpretation that is safe with GCC
// strict aliasing enabled. This is called type-punning, and it is valid
// when done with a union where the value read (int_value) is different
// than the one most recently written to (float_value).
union
{
float float_value;
int int_value;
} data;
const float xhalf(0.5f*x);
data.float_value = x;
// This hides a good amount of math
data.int_value = 0x5f3759df - (data.int_value >> 1);
x = data.float_value;
x = x*(1.5f - xhalf*x*x); // Repeat for more accuracy
x = x*(1.5f - xhalf*x*x);
return x;
}
| float gmtl::Math::fastInvSqrt3 | ( | float | x | ) | [inline] |
Definition at line 400 of file Math.h.
{
GMTL_STATIC_ASSERT(sizeof(float) == sizeof(int),
Union_type_sizes_do_not_match);
// Use an approach to data type reinterpretation that is safe with GCC
// strict aliasing enabled. This is called type-punning, and it is valid
// when done with a union where the value read (int_value) is different
// than the one most recently written to (float_value).
union
{
float float_value;
int int_value;
} data;
const float xhalf(0.5f*x);
data.float_value = x;
// This hides a good amount of math
data.int_value = 0x5f3759df - (data.int_value >> 1);
x = data.float_value;
x = x*(1.5f - xhalf*x*x); // Repeat for more accuracy
x = x*(1.5f - xhalf*x*x);
x = x*(1.5f - xhalf*x*x);
return x;
}
| T gmtl::Math::floor | ( | T | fValue | ) | [inline] |
| float gmtl::Math::floor | ( | float | fValue | ) | [inline] |
| double gmtl::Math::floor | ( | double | fValue | ) | [inline] |
| bool gmtl::Math::isEqual | ( | const T & | a, | |
| const T & | b, | |||
| const T & | tolerance | |||
| ) | [inline] |
Is almost equal? test for equality within some tolerance...
: tolerance must be >= 0
Definition at line 488 of file Math.h.
{
gmtlASSERT(tolerance >= static_cast<T>(0));
return gmtl::Math::abs( a - b ) <= tolerance;
}
| void gmtl::Math::lerp | ( | T & | result, | |
| const U & | lerp, | |||
| const T & | a, | |||
| const T & | b | |||
| ) | [inline] |
| double gmtl::Math::log | ( | double | fValue | ) | [inline] |
| float gmtl::Math::log | ( | float | fValue | ) | [inline] |
| T gmtl::Math::log | ( | T | fValue | ) | [inline] |
| T gmtl::Math::Max | ( | const T & | w, | |
| const T & | x, | |||
| const T & | y, | |||
| const T & | z | |||
| ) | [inline] |
max returns the maximum of 4 values
Definition at line 542 of file Math.h.
{
return gmtl::Math::Max( gmtl::Math::Max( w, x ), gmtl::Math::Max( y, z ) );
}
| T gmtl::Math::Max | ( | const T & | x, | |
| const T & | y, | |||
| const T & | z | |||
| ) | [inline] |
max returns the maximum of 3 values
Definition at line 536 of file Math.h.
{
return Max( gmtl::Math::Max( x, y ), z );
}
| T gmtl::Math::Max | ( | const T & | x, | |
| const T & | y | |||
| ) | [inline] |
| T gmtl::Math::Min | ( | const T & | x, | |
| const T & | y, | |||
| const T & | z | |||
| ) | [inline] |
min returns the minimum of 3 values
Definition at line 517 of file Math.h.
{
return Min( gmtl::Math::Min( x, y ), z );
}
| T gmtl::Math::Min | ( | const T & | w, | |
| const T & | x, | |||
| const T & | y, | |||
| const T & | z | |||
| ) | [inline] |
min returns the minimum of 4 values
Definition at line 523 of file Math.h.
{
return gmtl::Math::Min( gmtl::Math::Min( w, x ), gmtl::Math::Min( y, z ) );
}
| T gmtl::Math::Min | ( | const T & | x, | |
| const T & | y | |||
| ) | [inline] |
| double gmtl::Math::pow | ( | double | fBase, | |
| double | fExponent | |||
| ) | [inline] |
| float gmtl::Math::pow | ( | float | fBase, | |
| float | fExponent | |||
| ) | [inline] |
| bool gmtl::Math::quadraticFormula | ( | T & | r1, | |
| T & | r2, | |||
| const T & | a, | |||
| const T & | b, | |||
| const T & | c | |||
| ) | [inline] |
Uses the quadratic formula to compute the 2 roots of the given 2nd degree polynomial in the form of Ax^2 + Bx + C.
| r1 | set to the first root | |
| r2 | set to the second root | |
| a | the coefficient to x^2 | |
| b | the coefficient to x^1 | |
| c | the coefficient to x^0 |
Definition at line 607 of file Math.h.
{
const T q = b * b - static_cast<T>(4) * a * c;
// the result has real roots
if (q >= 0)
{
const T sq = gmtl::Math::sqrt(q);
const T d = static_cast<T>(1) / (static_cast<T>(2) * a);
r1 = (-b + sq) * d;
r2 = (-b - sq) * d;
return true;
}
// the result has complex roots
else
{
return false;
}
}
| float gmtl::Math::rad2Deg | ( | float | fVal | ) | [inline] |
Definition at line 473 of file Math.h.
{
return static_cast<float>(fVal * static_cast<float>(180.0 / gmtl::Math::PI));
}
| double gmtl::Math::rad2Deg | ( | double | fVal | ) | [inline] |
Definition at line 477 of file Math.h.
{
return static_cast<float>(fVal * static_cast<double>(180.0 / gmtl::Math::PI));
}
| float gmtl::Math::rangeRandom | ( | float | x1, | |
| float | x2 | |||
| ) | [inline] |
return a random number between x1 and x2 RETURNS: random number between x1 and x2
Definition at line 449 of file Math.h.
{
float r = gmtl::Math::unitRandom();
float size = x2 - x1;
return static_cast<float>(r * size + x1);
}
| T gmtl::Math::round | ( | T | p | ) | [inline] |
round to nearest integer
Definition at line 504 of file Math.h.
{
return static_cast<T>(gmtl::Math::floor(p + static_cast<T>(0.5)));
}
| void gmtl::Math::seedRandom | ( | unsigned int | seed | ) | [inline] |
| int gmtl::Math::sign | ( | T | iValue | ) | [inline] |
| float gmtl::Math::sin | ( | float | fValue | ) | [inline] |
| double gmtl::Math::sin | ( | double | fValue | ) | [inline] |
| T gmtl::Math::sin | ( | T | fValue | ) | [inline] |
| T gmtl::Math::sqr | ( | T | fValue | ) | [inline] |
| T gmtl::Math::sqrt | ( | T | fValue | ) | [inline] |
| double gmtl::Math::sqrt | ( | double | fValue | ) | [inline] |
| float gmtl::Math::tan | ( | float | fValue | ) | [inline] |
| T gmtl::Math::tan | ( | T | fValue | ) | [inline] |
| double gmtl::Math::tan | ( | double | fValue | ) | [inline] |
| T gmtl::Math::trunc | ( | T | val | ) | [inline] |
cut off the digits after the decimal place
Definition at line 496 of file Math.h.
{
return static_cast<T>((val < static_cast<T>(0)) ?
gmtl::Math::ceil(val) :
gmtl::Math::floor(val));
}
| float gmtl::Math::unitRandom | ( | ) | [inline] |
| T gmtl::Math::zeroClamp | ( | T | value, | |
| T | eps = static_cast<T>(0) | |||
| ) | [inline] |
Clamps the given value down to zero if it is within epsilon of zero.
| value | the value to clamp | |
| eps | the epsilon tolerance or zero by default |
Definition at line 128 of file Math.h.
{
return ( (gmtl::Math::abs(value) <= eps) ? static_cast<T>(0) : value );
}
| const float gmtl::Math::PI = 3.14159265358979323846f |
| const float gmtl::Math::PI_OVER_2 = 1.57079632679489661923f |
| const float gmtl::Math::PI_OVER_4 = 0.78539816339744830962f |
| const float gmtl::Math::TWO_PI = 6.28318530717958647692f |
1.7.1