((*(const unsigned long *)&x) & 0x007fffff) != 0x00000000 )
#define IEEE_FLT_MANTISSA_BITS 23
#define IEEE_FLT_EXPONENT_BITS 8
#define IEEE_FLT_EXPONENT_BIAS 127
#define IEEE_FLT_SIGN_BIT 31
#define IEEE_DBL_MANTISSA_BITS 52
#define IEEE_DBL_EXPONENT_BITS 11
#define IEEE_DBL_EXPONENT_BIAS 1023
#define IEEE_DBL_SIGN_BIT 63
#define IEEE_DBLE_MANTISSA_BITS 63
#define IEEE_DBLE_EXPONENT_BITS 15
#define IEEE_DBLE_EXPONENT_BIAS 0
#define IEEE_DBLE_SIGN_BIT 79
template<class T> ID_INLINE T Max( T x, T y ) { return ( x > y ) ? x : y; }
template<class T> ID_INLINE T Min( T x, T y ) { return ( x < y ) ? x : y; }
template<class T> ID_INLINE int MaxIndex( T x, T y ) { return ( x > y ) ? 0 : 1; }
template<class T> ID_INLINE int MinIndex( T x, T y ) { return ( x < y ) ? 0 : 1; }
template<class T> ID_INLINE T Max3( T x, T y, T z ) { return ( x > y ) ? ( ( x > z ) ? x : z ) : ( ( y > z ) ? y : z ); }
template<class T> ID_INLINE T Min3( T x, T y, T z ) { return ( x < y ) ? ( ( x < z ) ? x : z ) : ( ( y < z ) ? y : z ); }
template<class T> ID_INLINE int Max3Index( T x, T y, T z ) { return ( x > y ) ? ( ( x > z ) ? 0 : 2 ) : ( ( y > z ) ? 1 : 2 ); }
template<class T> ID_INLINE int Min3Index( T x, T y, T z ) { return ( x < y ) ? ( ( x < z ) ? 0 : 2 ) : ( ( y < z ) ? 1 : 2 ); }
template<class T> ID_INLINE T Sign( T f ) { return ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 0 ); }
// RAVEN BEGIN
// abahr: I know its not correct but return 1 if zero
template<class T> ID_INLINE T SignZero( T f ) { return ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 1 ); }
// RAVEN END
template<class T> ID_INLINE T Square( T x ) { return x * x; }
template<class T> ID_INLINE T Cube( T x ) { return x * x * x; }
class idMath {
public:
static void Init( void );
static float RSqrt( float x ); // reciprocal square root, returns huge number when x == 0.0
#ifdef _FAST_MATH
static float InvSqrt( float x ); // inverse square root with 32 bits precision, returns huge number when x == 0.0
static float InvSqrt16( float x ); // inverse square root with 16 bits precision, returns huge number when x == 0.0
static double InvSqrt64( float x ); // inverse square root with 64 bits precision, returns huge number when x == 0.0
static float Sqrt( float x ); // square root with 32 bits precision
static float Sqrt16( float x ); // square root with 16 bits precision
static double Sqrt64( float x ); // square root with 64 bits precision
static float Sin( float a ); // sine with 32 bits precision
static float Sin16( float a ); // sine with 16 bits precision, maximum absolute error is 2.3082e-09
static double Sin64( float a ); // sine with 64 bits precision
static float Cos( float a ); // cosine with 32 bits precision
static float Cos16( float a ); // cosine with 16 bits precision, maximum absolute error is 2.3082e-09
static double Cos64( float a ); // cosine with 64 bits precision
static float Tan( float a ); // tangent with 32 bits precision
static float Tan16( float a ); // tangent with 16 bits precision, maximum absolute error is 1.8897e-08
static double Tan64( float a ); // tangent with 64 bits precision
static float ATan( float a ); // arc tangent with 32 bits precision
static float ATan16( float a ); // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
static double ATan64( float a ); // arc tangent with 64 bits precision
static float ATan( float y, float x ); // arc tangent with 32 bits precision
static float ATan16( float y, float x ); // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
static double ATan64( float y, float x ); // arc tangent with 64 bits precision
#else
static float InvSqrt( float x ) { assert( x > 0.0f ); return( 1.0f / sqrtf( x ) ); } // inverse square root with 32 bits precision, returns huge number when x == 0.0
static float InvSqrt16( float x ) { assert( x > 0.0f ); return( 1.0f / sqrt( x ) ); } // inverse square root with 16 bits precision, returns huge number when x == 0.0
static double InvSqrt64( float x ) { assert( x > 0.0f ); return( 1.0f / sqrt( x ) ); } // inverse square root with 64 bits precision, returns huge number when x == 0.0
static float Sqrt( float x ) { assert( x >= 0.0f ); return( sqrtf( x ) ); } // square root with 32 bits precision
static float Sqrt16( float x ) { assert( x >= 0.0f ); return( sqrtf( x ) ); } // square root with 16 bits precision
static double Sqrt64( float x ) { assert( x >= 0.0f ); return( sqrt( x ) ); } // square root with 64 bits precision
static float Sin( float a ) { return( sinf( a ) ); } // sine with 32 bits precision
static float Sin16( float a ) { return( sinf( a ) ); } // sine with 16 bits precision, maximum absolute error is 2.3082e-09
static double Sin64( float a ) { return( sin( a ) ); } // sine with 64 bits precision
static float Cos( float a ) { return( cosf( a ) ); } // cosine with 32 bits precision
static float Cos16( float a ) { return( cosf( a ) ); } // cosine with 16 bits precision, maximum absolute error is 2.3082e-09
static double Cos64( float a ) { return( cos( a ) ); } // cosine with 64 bits precision
static float Tan( float a ) { return( tanf( a ) ); } // tangent with 32 bits precision
static float Tan16( float a ) { return( tanf( a ) ); } // tangent with 16 bits precision, maximum absolute error is 1.8897e-08
static double Tan64( float a ) { return( tan( a ) ); } // tangent with 64 bits precision
static float ATan( float a ) { return( atanf( a ) ); } // arc tangent with 32 bits precision
static float ATan16( float a ) { return( atanf( a ) ); } // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
static double ATan64( float a ) { return( atan( a ) ); } // arc tangent with 64 bits precision
static float ATan( float y, float x ) { return( atan2f( y, x ) ); } // arc tangent with 32 bits precision
static float ATan16( float y, float x ) { return( atan2f( y, x ) ); } // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
static double ATan64( float y, float x ) { return( atan2( y, x ) ); } // arc tangent with 64 bits precision
#endif
static void SinCos( float a, float &s, float &c ); // sine and cosine with 32 bits precision
static void SinCos16( float a, float &s, float &c ); // sine and cosine with 16 bits precision
static void SinCos64( float a, double &s, double &c ); // sine and cosine with 64 bits precision
static float ASin( float a ); // arc sine with 32 bits precision, input is clamped to [-1, 1] to avoid a silent NaN
static float ASin16( float a ); // arc sine with 16 bits precision, maximum absolute error is 6.7626e-05
static double ASin64( float a ); // arc sine with 64 bits precision
static float ACos( float a ); // arc cosine with 32 bits precision, input is clamped to [-1, 1] to avoid a silent NaN
static float ACos16( float a ); // arc cosine with 16 bits precision, maximum absolute error is 6.7626e-05
static double ACos64( float a ); // arc cosine with 64 bits precision
static float Pow( float x, float y ); // x raised to the power y with 32 bits precision
static float Pow16( float x, float y ); // x raised to the power y with 16 bits precision
static double Pow64( float x, float y ); // x raised to the power y with 64 bits precision
static float Exp( float f ); // e raised to the power f with 32 bits precision
static float Exp16( float f ); // e raised to the power f with 16 bits precision
static double Exp64( float f ); // e raised to the power f with 64 bits precision
static float Log( float f ); // natural logarithm with 32 bits precision
static float Log16( float f ); // natural logarithm with 16 bits precision
static double Log64( float f ); // natural logarithm with 64 bits precision
static int IPow( int x, int y ); // integral x raised to the power y
static int ILog2( float f ); // integral base-2 logarithm of the floating point value
static int ILog2( int i ); // integral base-2 logarithm of the integer value
static int BitsForFloat( float f ); // minumum number of bits required to represent ceil( f )
static int BitsForInteger( int i ); // minumum number of bits required to represent i
static int MaskForFloatSign( float f );// returns 0x00000000 if x >= 0.0f and returns 0xFFFFFFFF if x <= -0.0f
static int MaskForIntegerSign( int i );// returns 0x00000000 if x >= 0 and returns 0xFFFFFFFF if x < 0
static int FloorPowerOfTwo( int x ); // round x down to the nearest power of 2
static int CeilPowerOfTwo( int x ); // round x up to the nearest power of 2
static bool IsPowerOfTwo( int x ); // returns true if x is a power of 2
static int BitCount( int x ); // returns the number of 1 bits in x
static int BitReverse( int x ); // returns the bit reverse of x
static int Abs( int x ); // returns the absolute value of the integer value (for reference only)
static float Fabs( float f ); // returns the absolute value of the floating point value
static float Floor( float f ); // returns the largest integer that is less than or equal to the given value
static float Ceil( float f ); // returns the smallest integer that is greater than or equal to the given value
static float Rint( float f ); // returns the nearest integer
static int Ftoi( float f ); // float to int conversion
static int FtoiFast( float f ); // fast float to int conversion but uses current FPU round mode (default round nearest)
static byte Ftob( float f ); // float to byte conversion, the result is clamped to the range [0-255]
static signed char ClampChar( int i );
// RAVEN BEGIN
static byte ClampByte( int i );
// RAVEN END
static signed short ClampShort( int i );
static int ClampInt( int min, int max, int value );
static float ClampFloat( float min, float max, float value );