Math Namespace
The Math namespace provides an assortment of common math functions and constants.
Constants
As you can see, these aren't actually declared const. Please don't modify their values.
float pi
3.141593
kVec3 vecZero
(0,0,0)
Basic Arithmetic
int Abs( int i )
float Fabs( float f )
absolute value
float Ceil( float f )
float Floor( float f )
ceiling (round up) and floor (round down)
float Min( float a, float b )
float Max( float a, float b )
returns the lesser or greater of the two parameters, respectively
float Sqrt( float f )
float InvSqrt( float f )
√f and 1⁄√f
1/Math::Sqrt(0) crashes the game, but Math::InvSqrt(0) returns a large number
float Pow( float base, float exp )
returns base raised to the power of exp
float Log( float f )
natural logarithm (base e)
float IncMax( float val, float inc, float max )
returns val+inc, capped to max
float Lerp( float a, float b, float pct )
linear interpolation
returns a value a fraction of the way from a to b:
a + pct*(b-a)
Trigonometry
float Sin( float radians )
float Cos( float radians )
float Tan( float radians )
sine, cosine, tangent
float ACos( float f )
arc (inverse) cosine (in radians)
float ATan2( float y, float x )
angle (in radians) between the positive x-axis and (x,y)
float Deg2Rad( float degrees )
float Rad2Deg( float radians )
convert between radians and degrees
float CosTween( float [unknown] )
float CosArc( float [unknown] )
Random Numbers
Floating point ranges are given in interval notation: parentheses denote exclusive endpoints, and square brackets denote inclusive endpoints.
Take any exclusive endpoints with a grain of salt – it's possible I just never rolled them while testing.
int Rand()
int SysRand()
0 to 32767
anecdotally, Rand() seems to have a hard time hitting 0 (faster but with less even distribution?)
uint8 RandByte()
0 to 255
int RandMax( int max )
0 to max-1
float RandFloat()
( 0.0, 1.0 )
float RandCFloat()
[ -1.0, 1.0 )
float RandRange( float min, float max )
( min, max ]
int RandRange( int min, int max )
[ min, max ]
