Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

gmtl::Math Namespace Reference


C Math Abstraction

template<typename T> T abs (T 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=T(0))
 Clamps the given value down to zero if it is within epsilon of zero. More...

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)
void seedRandom (unsigned int seed)
 Seeds the pseudorandom number generator with the given seed. More...

float unitRandom ()
 get a random number between 0 and 1. More...

float rangeRandom (float x1, float x2)
 return a random number between x1 and x2 RETURNS: random number between x1 and x2. More...

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... More...

template<class T> T trunc (T val)
 cut off the digits after the decimal place. More...

template<class T> T round (T p)
 round to nearest integer. More...

template<class T> T Min (const T &x, const T &y)
 min returns the minimum of 2 values. More...

template<class T> T Min (const T &x, const T &y, const T &z)
 min returns the minimum of 3 values. More...

template<class T> T Min (const T &w, const T &x, const T &y, const T &z)
 min returns the minimum of 4 values. More...

template<class T> T Max (const T &x, const T &y)
 max returns the maximum of 2 values. More...

template<class T> T Max (const T &x, const T &y, const T &z)
 max returns the maximum of 3 values. More...

template<class T> T Max (const T &w, const T &x, const T &y, const T &z)
 max returns the maximum of 4 values. More...

template<class T> T factorial (T rhs)
 Compute the factorial. More...


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]. More...


Mathematical constants

const float PI = 3.14159265358979323846f
const float PI_OVER_2 = 1.57079632679489661923f
const float PI_OVER_4 = 0.78539816339744830962f

Functions

template<class T> T clamp (T number, T lo, T hi)
 clamp "number" to a range between lo and hi. More...

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. More...


Function Documentation

template<class T>
T clamp   number,
  lo,
  hi
[inline]
 

clamp "number" to a range between lo and hi.

Definition at line 507 of file Math.h.

00508 {
00509    if (number > hi) number = hi;
00510    else if (number < lo) number = lo;
00511    return number;
00512 }

template<class T>
bool 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.

Parameters:
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
Returns:
true if both r1 and r2 are real; false otherwise

Definition at line 543 of file Math.h.

00544 {
00545    const T q = b*b - T(4)*a*c;
00546 
00547    // the result has real roots
00548    if (q >= 0)
00549    {
00550       const T sq = gmtl::Math::sqrt(q);
00551       const T d = T(1) / (T(2) * a);
00552       r1 = (-b + sq) * d;
00553       r2 = (-b - sq) * d;
00554       return true;
00555    }
00556    // the result has complex roots
00557    else
00558    {
00559       return false;
00560    }
00561 }


Generated on Mon Apr 7 15:29:35 2003 for GenericMathTemplateLibrary by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002