home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / idlib / math / Math.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  32KB  |  1,044 lines

  1.  
  2. #ifndef __MATH_MATH_H__
  3. #define __MATH_MATH_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.   Math
  9.  
  10. ===============================================================================
  11. */
  12.  
  13. #ifdef INFINITY
  14. #undef INFINITY
  15. #endif
  16.  
  17. // RAVEN BEGIN
  18. // jscott: renamed to prevent name clash
  19. #ifdef FLOAT_EPSILON
  20. #undef FLOAT_EPSILON
  21. #endif
  22. // ddynerman: name clash prevention
  23. #ifdef INT_MIN
  24. #undef INT_MIN
  25. #endif
  26.  
  27. #ifdef INT_MAX
  28. #undef INT_MAX
  29. #endif
  30.  
  31. // jscott: uncomment this to use id's sqrt and trig approximations
  32. #if defined( __linux__ ) || defined( MACOS_X )
  33.     // TTimo - enabling for OSes I'm covering
  34.     // (14:34:20) mrelusive: in the general case we don't use those functions
  35.     // (14:34:28) mrelusive: they are only for specific cases where they are faster
  36.     #define _FAST_MATH
  37. #endif
  38. // RAVEN END
  39.  
  40. #define DEG2RAD(a)                ( (a) * idMath::M_DEG2RAD )
  41. #define RAD2DEG(a)                ( (a) * idMath::M_RAD2DEG )
  42.  
  43. #define SEC2MS(t)                ( idMath::FtoiFast( (t) * idMath::M_SEC2MS ) )
  44. #define MS2SEC(t)                ( (t) * idMath::M_MS2SEC )
  45.  
  46. #define    ANGLE2SHORT(x)            ( idMath::FtoiFast( (x) * 65536.0f / 360.0f ) & 65535 )
  47. #define    SHORT2ANGLE(x)            ( (x) * ( 360.0f / 65536.0f ) )
  48.  
  49. #define    ANGLE2BYTE(x)            ( idMath::FtoiFast( (x) * 256.0f / 360.0f ) & 255 )
  50. #define    BYTE2ANGLE(x)            ( (x) * ( 360.0f / 256.0f ) )
  51.  
  52. #define FLOATSIGNBITSET(f)        ((*(const unsigned long *)&(f)) >> 31)
  53. #define FLOATSIGNBITNOTSET(f)    ((~(*(const unsigned long *)&(f))) >> 31)
  54. #define FLOATNOTZERO(f)            ((*(const unsigned long *)&(f)) & ~(1<<31) )
  55. #define INTSIGNBITSET(i)        (((const unsigned long)(i)) >> 31)
  56. #define INTSIGNBITNOTSET(i)        ((~((const unsigned long)(i))) >> 31)
  57.  
  58. #define    FLOAT_IS_NAN(x)            (((*(const unsigned long *)&x) & 0x7f800000) == 0x7f800000)
  59. #define FLOAT_IS_INF(x)            (((*(const unsigned long *)&x) & 0x7fffffff) == 0x7f800000)
  60. #define FLOAT_IS_IND(x)            ((*(const unsigned long *)&x) == 0xffc00000)
  61. #define    FLOAT_IS_DENORMAL(x)    (((*(const unsigned long *)&x) & 0x7f800000) == 0x00000000 && \
  62.                                  ((*(const unsigned long *)&x) & 0x007fffff) != 0x00000000 )
  63.  
  64. #define IEEE_FLT_MANTISSA_BITS    23
  65. #define IEEE_FLT_EXPONENT_BITS    8
  66. #define IEEE_FLT_EXPONENT_BIAS    127
  67. #define IEEE_FLT_SIGN_BIT        31
  68.  
  69. #define IEEE_DBL_MANTISSA_BITS    52
  70. #define IEEE_DBL_EXPONENT_BITS    11
  71. #define IEEE_DBL_EXPONENT_BIAS    1023
  72. #define IEEE_DBL_SIGN_BIT        63
  73.  
  74. #define IEEE_DBLE_MANTISSA_BITS    63
  75. #define IEEE_DBLE_EXPONENT_BITS    15
  76. #define IEEE_DBLE_EXPONENT_BIAS    0
  77. #define IEEE_DBLE_SIGN_BIT        79
  78.  
  79. template<class T> ID_INLINE T    Max( T x, T y ) { return ( x > y ) ? x : y; }
  80. template<class T> ID_INLINE T    Min( T x, T y ) { return ( x < y ) ? x : y; }
  81. template<class T> ID_INLINE int    MaxIndex( T x, T y ) { return  ( x > y ) ? 0 : 1; }
  82. template<class T> ID_INLINE int    MinIndex( T x, T y ) { return ( x < y ) ? 0 : 1; }
  83.  
  84. template<class T> ID_INLINE T    Max3( T x, T y, T z ) { return ( x > y ) ? ( ( x > z ) ? x : z ) : ( ( y > z ) ? y : z ); }
  85. template<class T> ID_INLINE T    Min3( T x, T y, T z ) { return ( x < y ) ? ( ( x < z ) ? x : z ) : ( ( y < z ) ? y : z ); }
  86. template<class T> ID_INLINE int    Max3Index( T x, T y, T z ) { return ( x > y ) ? ( ( x > z ) ? 0 : 2 ) : ( ( y > z ) ? 1 : 2 ); }
  87. template<class T> ID_INLINE int    Min3Index( T x, T y, T z ) { return ( x < y ) ? ( ( x < z ) ? 0 : 2 ) : ( ( y < z ) ? 1 : 2 ); }
  88. template<class T> ID_INLINE T    Sign( T f ) { return ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 0 ); }
  89. // RAVEN BEGIN
  90. // abahr: I know its not correct but return 1 if zero
  91. template<class T> ID_INLINE T    SignZero( T f ) { return ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 1 ); }
  92. // RAVEN END
  93. template<class T> ID_INLINE T    Square( T x ) { return x * x; }
  94. template<class T> ID_INLINE T    Cube( T x ) { return x * x * x; }
  95.  
  96. class idMath {
  97. public:
  98.  
  99.     static void                    Init( void );
  100.  
  101.     static float                RSqrt( float x );            // reciprocal square root, returns huge number when x == 0.0
  102.  
  103. #ifdef _FAST_MATH
  104.     static float                InvSqrt( float x );            // inverse square root with 32 bits precision, returns huge number when x == 0.0
  105.     static float                InvSqrt16( float x );        // inverse square root with 16 bits precision, returns huge number when x == 0.0
  106.     static double                InvSqrt64( float x );        // inverse square root with 64 bits precision, returns huge number when x == 0.0
  107.  
  108.     static float                Sqrt( float x );            // square root with 32 bits precision
  109.     static float                Sqrt16( float x );            // square root with 16 bits precision
  110.     static double                Sqrt64( float x );            // square root with 64 bits precision
  111.  
  112.     static float                Sin( float a );                // sine with 32 bits precision
  113.     static float                Sin16( float a );            // sine with 16 bits precision, maximum absolute error is 2.3082e-09
  114.     static double                Sin64( float a );            // sine with 64 bits precision
  115.  
  116.     static float                Cos( float a );                // cosine with 32 bits precision
  117.     static float                Cos16( float a );            // cosine with 16 bits precision, maximum absolute error is 2.3082e-09
  118.     static double                Cos64( float a );            // cosine with 64 bits precision
  119.  
  120.     static float                Tan( float a );                // tangent with 32 bits precision
  121.     static float                Tan16( float a );            // tangent with 16 bits precision, maximum absolute error is 1.8897e-08
  122.     static double                Tan64( float a );            // tangent with 64 bits precision
  123.  
  124.     static float                ATan( float a );            // arc tangent with 32 bits precision
  125.     static float                ATan16( float a );            // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
  126.     static double                ATan64( float a );            // arc tangent with 64 bits precision
  127.  
  128.     static float                ATan( float y, float x );    // arc tangent with 32 bits precision
  129.     static float                ATan16( float y, float x );    // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
  130.     static double                ATan64( float y, float x );    // arc tangent with 64 bits precision
  131. #else
  132.     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
  133.     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
  134.     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
  135.  
  136.     static float                Sqrt( float x ) { assert( x >= 0.0f ); return( sqrtf( x ) ); }        // square root with 32 bits precision
  137.     static float                Sqrt16( float x ) { assert( x >= 0.0f ); return( sqrtf( x ) ); }    // square root with 16 bits precision
  138.     static double                Sqrt64( float x ) { assert( x >= 0.0f ); return( sqrt( x ) ); }        // square root with 64 bits precision
  139.  
  140.     static float                Sin( float a ) { return( sinf( a ) ); }                                // sine with 32 bits precision
  141.     static float                Sin16( float a ) { return( sinf( a ) ); }                            // sine with 16 bits precision, maximum absolute error is 2.3082e-09
  142.     static double                Sin64( float a ) { return( sin( a ) ); }                            // sine with 64 bits precision
  143.  
  144.     static float                Cos( float a ) { return( cosf( a ) ); }                                // cosine with 32 bits precision
  145.     static float                Cos16( float a ) { return( cosf( a ) ); }                            // cosine with 16 bits precision, maximum absolute error is 2.3082e-09
  146.     static double                Cos64( float a ) { return( cos( a ) ); }                            // cosine with 64 bits precision
  147.  
  148.     static float                Tan( float a ) { return( tanf( a ) ); }                                // tangent with 32 bits precision
  149.     static float                Tan16( float a ) { return( tanf( a ) ); }                            // tangent with 16 bits precision, maximum absolute error is 1.8897e-08
  150.     static double                Tan64( float a ) { return( tan( a ) ); }                            // tangent with 64 bits precision
  151.  
  152.     static float                ATan( float a ) { return( atanf( a ) ); }                            // arc tangent with 32 bits precision
  153.     static float                ATan16( float a ) { return( atanf( a ) ); }                            // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
  154.     static double                ATan64( float a ) { return( atan( a ) ); }                            // arc tangent with 64 bits precision
  155.  
  156.     static float                ATan( float y, float x ) { return( atan2f( y, x ) ); }                // arc tangent with 32 bits precision
  157.     static float                ATan16( float y, float x ) { return( atan2f( y, x ) ); }            // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
  158.     static double                ATan64( float y, float x ) { return( atan2( y, x ) ); }                // arc tangent with 64 bits precision
  159. #endif
  160.  
  161.     static void                    SinCos( float a, float &s, float &c );        // sine and cosine with 32 bits precision
  162.     static void                    SinCos16( float a, float &s, float &c );    // sine and cosine with 16 bits precision
  163.     static void                    SinCos64( float a, double &s, double &c );    // sine and cosine with 64 bits precision
  164.  
  165.     static float                ASin( float a );            // arc sine with 32 bits precision, input is clamped to [-1, 1] to avoid a silent NaN
  166.     static float                ASin16( float a );            // arc sine with 16 bits precision, maximum absolute error is 6.7626e-05
  167.     static double                ASin64( float a );            // arc sine with 64 bits precision
  168.  
  169.     static float                ACos( float a );            // arc cosine with 32 bits precision, input is clamped to [-1, 1] to avoid a silent NaN
  170.     static float                ACos16( float a );            // arc cosine with 16 bits precision, maximum absolute error is 6.7626e-05
  171.     static double                ACos64( float a );            // arc cosine with 64 bits precision
  172.  
  173.     static float                Pow( float x, float y );    // x raised to the power y with 32 bits precision
  174.     static float                Pow16( float x, float y );    // x raised to the power y with 16 bits precision
  175.     static double                Pow64( float x, float y );    // x raised to the power y with 64 bits precision
  176.  
  177.     static float                Exp( float f );                // e raised to the power f with 32 bits precision
  178.     static float                Exp16( float f );            // e raised to the power f with 16 bits precision
  179.     static double                Exp64( float f );            // e raised to the power f with 64 bits precision
  180.  
  181.     static float                Log( float f );                // natural logarithm with 32 bits precision
  182.     static float                Log16( float f );            // natural logarithm with 16 bits precision
  183.     static double                Log64( float f );            // natural logarithm with 64 bits precision
  184.  
  185.     static int                    IPow( int x, int y );        // integral x raised to the power y
  186.     static int                    ILog2( float f );            // integral base-2 logarithm of the floating point value
  187.     static int                    ILog2( int i );                // integral base-2 logarithm of the integer value
  188.  
  189.     static int                    BitsForFloat( float f );    // minumum number of bits required to represent ceil( f )
  190.     static int                    BitsForInteger( int i );    // minumum number of bits required to represent i
  191.     static int                    MaskForFloatSign( float f );// returns 0x00000000 if x >= 0.0f and returns 0xFFFFFFFF if x <= -0.0f
  192.     static int                    MaskForIntegerSign( int i );// returns 0x00000000 if x >= 0 and returns 0xFFFFFFFF if x < 0
  193.     static int                    FloorPowerOfTwo( int x );    // round x down to the nearest power of 2
  194.     static int                    CeilPowerOfTwo( int x );    // round x up to the nearest power of 2
  195.     static bool                    IsPowerOfTwo( int x );        // returns true if x is a power of 2
  196.     static int                    BitCount( int x );            // returns the number of 1 bits in x
  197.     static int                    BitReverse( int x );        // returns the bit reverse of x
  198.  
  199.     static int                    Abs( int x );                // returns the absolute value of the integer value (for reference only)
  200.     static float                Fabs( float f );            // returns the absolute value of the floating point value
  201.     static float                Floor( float f );            // returns the largest integer that is less than or equal to the given value
  202.     static float                Ceil( float f );            // returns the smallest integer that is greater than or equal to the given value
  203.     static float                Rint( float f );            // returns the nearest integer
  204.     static int                    Ftoi( float f );            // float to int conversion
  205.     static int                    FtoiFast( float f );        // fast float to int conversion but uses current FPU round mode (default round nearest)
  206.     static byte                    Ftob( float f );            // float to byte conversion, the result is clamped to the range [0-255]
  207.  
  208.     static signed char            ClampChar( int i );
  209. // RAVEN BEGIN
  210.     static byte                    ClampByte( int i );
  211. // RAVEN END
  212.     static signed short            ClampShort( int i );
  213.     static int                    ClampInt( int min, int max, int value );
  214.     static float                ClampFloat( float min, float max, float value );
  215.  
  216.     static float                AngleNormalize360( float angle );
  217.     static float                AngleNormalize180( float angle );
  218.     static float                AngleDelta( float angle1, float angle2 );
  219.  
  220.     static int                    FloatToBits( float f, int exponentBits, int mantissaBits );
  221.     static float                BitsToFloat( int i, int exponentBits, int mantissaBits );
  222.  
  223.     static int                    FloatHash( const float *array, const int numFloats );
  224.  
  225.     static const float            PI;                            // pi
  226.     static const float            TWO_PI;                        // pi * 2
  227.     static const float            HALF_PI;                    // pi / 2
  228.     static const float            ONEFOURTH_PI;                // pi / 4
  229.     static const float            E;                            // e
  230.     static const float            SQRT_TWO;                    // sqrt( 2 )
  231.     static const float            SQRT_THREE;                    // sqrt( 3 )
  232. // RAVEN BEGIN
  233.     static const float            THREEFOURTHS_PI;            // 3 * pi / 4
  234. // RAVEN END
  235.     static const float            SQRT_1OVER2;                // sqrt( 1 / 2 )
  236.     static const float            SQRT_1OVER3;                // sqrt( 1 / 3 )
  237.     static const float            M_DEG2RAD;                    // degrees to radians multiplier
  238.     static const float            M_RAD2DEG;                    // radians to degrees multiplier
  239.     static const float            M_SEC2MS;                    // seconds to milliseconds multiplier
  240.     static const float            M_MS2SEC;                    // milliseconds to seconds multiplier
  241.     static const float            INFINITY;                    // huge number which should be larger than any valid number used
  242. // RAVEN BEGIN
  243. // jscott: renamed to prevent name clash
  244.     static const float            FLOAT_EPSILON;                // smallest positive number such that 1.0+FLT_EPSILON != 1.0
  245. // ddynerman: added from limits.h
  246.     static const int            INT_MIN;
  247.     static const int            INT_MAX;
  248.  
  249. // bdube: moved here from modview
  250.     static void                    ArtesianFromPolar( idVec3 &result, idVec3 view );
  251.     static void                    PolarFromArtesian( idVec3 &view, idVec3 artesian );
  252. // jscott: for material type collision
  253.     static float                BarycentricTriangleArea( const idVec3 &normal, const idVec3 &a, const idVec3 &b, const idVec3 &c );
  254.     static void                    BarycentricEvaluate( idVec2 &result, const idVec3 &point, const idVec3 &normal, const float area, const idVec3 t[3], const idVec2 tc[3] );
  255. // abahr
  256.     static float                Lerp( const idVec2& range, float frac );
  257.     static float                Lerp( float start, float end, float frac );
  258.     static float                MidPointLerp( float start, float mid, float end, float frac );
  259. // jscott: for sound system
  260.     static float                dBToScale( float db );
  261.     static float                ScaleToDb( float scale );
  262. // RAVEN END
  263.  
  264.  
  265. private:
  266.     enum {
  267.         LOOKUP_BITS                = 8,                            
  268.         EXP_POS                    = 23,                            
  269.         EXP_BIAS                = 127,                            
  270.         LOOKUP_POS                = (EXP_POS-LOOKUP_BITS),
  271.         SEED_POS                = (EXP_POS-8),
  272.         SQRT_TABLE_SIZE            = (2<<LOOKUP_BITS),
  273.         LOOKUP_MASK                = (SQRT_TABLE_SIZE-1)
  274.     };
  275.  
  276.     union _flint {
  277.         dword                    i;
  278.         float                    f;
  279.     };
  280.  
  281.     static dword                iSqrt[SQRT_TABLE_SIZE];
  282.     static bool                    initialized;
  283.  
  284. #ifdef ID_WIN_X86_SSE
  285.     static const float            SSE_FLOAT_ZERO;
  286.     static const float            SSE_FLOAT_255;
  287. #endif
  288. };
  289.  
  290. ID_INLINE float idMath::RSqrt( float x ) {
  291.     long i;
  292.     float y, r;
  293.  
  294.     y = x * 0.5f;
  295.     i = *reinterpret_cast<long *>( &x );
  296.     i = 0x5f3759df - ( i >> 1 );
  297.     r = *reinterpret_cast<float *>( &i );
  298.     r = r * ( 1.5f - r * r * y );
  299.     return r;
  300. }
  301.  
  302. #ifdef _FAST_MATH
  303. ID_INLINE float idMath::InvSqrt16( float x ) {
  304.     dword a = ((union _flint*)(&x))->i;
  305.     union _flint seed;
  306.  
  307.     assert( initialized );
  308.  
  309.     double y = x * 0.5f;
  310.     seed.i = (( ( (3*EXP_BIAS-1) - ( (a >> EXP_POS) & 0xFF) ) >> 1)<<EXP_POS) | iSqrt[(a >> (EXP_POS-LOOKUP_BITS)) & LOOKUP_MASK];
  311.     double r = seed.f;
  312.     r = r * ( 1.5f - r * r * y );
  313.     return (float) r;
  314. }
  315.  
  316. ID_INLINE float idMath::InvSqrt( float x ) {
  317.     dword a = ((union _flint*)(&x))->i;
  318.     union _flint seed;
  319.  
  320.     assert( initialized );
  321.  
  322.     double y = x * 0.5f;
  323.     seed.i = (( ( (3*EXP_BIAS-1) - ( (a >> EXP_POS) & 0xFF) ) >> 1)<<EXP_POS) | iSqrt[(a >> (EXP_POS-LOOKUP_BITS)) & LOOKUP_MASK];
  324.     double r = seed.f;
  325.     r = r * ( 1.5f - r * r * y );
  326.     r = r * ( 1.5f - r * r * y );
  327.     return (float) r;
  328. }
  329.  
  330. ID_INLINE double idMath::InvSqrt64( float x ) {
  331.     dword a = ((union _flint*)(&x))->i;
  332.     union _flint seed;
  333.  
  334.     assert( initialized );
  335.  
  336.     double y = x * 0.5f;
  337.     seed.i = (( ( (3*EXP_BIAS-1) - ( (a >> EXP_POS) & 0xFF) ) >> 1)<<EXP_POS) | iSqrt[(a >> (EXP_POS-LOOKUP_BITS)) & LOOKUP_MASK];
  338.     double r = seed.f;
  339.     r = r * ( 1.5f - r * r * y );
  340.     r = r * ( 1.5f - r * r * y );
  341.     r = r * ( 1.5f - r * r * y );
  342.     return r;
  343. }
  344.  
  345. ID_INLINE float idMath::Sqrt16( float x ) {
  346.     return x * InvSqrt16( x );
  347. }
  348.  
  349. ID_INLINE float idMath::Sqrt( float x ) {
  350.     return x * InvSqrt( x );
  351. }
  352.  
  353. ID_INLINE double idMath::Sqrt64( float x ) {
  354.     return x * InvSqrt64( x );
  355. }
  356.  
  357. ID_INLINE float idMath::Sin( float a ) {
  358.     return sinf( a );
  359. }
  360.  
  361. ID_INLINE float idMath::Sin16( float a ) {
  362.     float s;
  363.  
  364.     if ( ( a < 0.0f ) || ( a >= TWO_PI ) ) {
  365.         a -= floorf( a / TWO_PI ) * TWO_PI;
  366.     }
  367. #if 1
  368.     if ( a < PI ) {
  369.         if ( a > HALF_PI ) {
  370.             a = PI - a;
  371.         }
  372.     } else {
  373.         if ( a > PI + HALF_PI ) {
  374.             a = a - TWO_PI;
  375.         } else {
  376.             a = PI - a;
  377.         }
  378.     }
  379. #else
  380.     a = PI - a;
  381.     if ( fabs( a ) >= HALF_PI ) {
  382.         a = ( ( a < 0.0f ) ? -PI : PI ) - a;
  383.     }
  384. #endif
  385.     s = a * a;
  386.     return a * ( ( ( ( ( -2.39e-08f * s + 2.7526e-06f ) * s - 1.98409e-04f ) * s + 8.3333315e-03f ) * s - 1.666666664e-01f ) * s + 1.0f );
  387. }
  388.  
  389. ID_INLINE double idMath::Sin64( float a ) {
  390.     return sin( a );
  391. }
  392.  
  393. ID_INLINE float idMath::Cos( float a ) {
  394.     return cosf( a );
  395. }
  396.  
  397. ID_INLINE float idMath::Cos16( float a ) {
  398.     float s, d;
  399.  
  400.     if ( ( a < 0.0f ) || ( a >= TWO_PI ) ) {
  401.         a -= floorf( a / TWO_PI ) * TWO_PI;
  402.     }
  403. #if 1
  404.     if ( a < PI ) {
  405.         if ( a > HALF_PI ) {
  406.             a = PI - a;
  407.             d = -1.0f;
  408.         } else {
  409.             d = 1.0f;
  410.         }
  411.     } else {
  412.         if ( a > PI + HALF_PI ) {
  413.             a = a - TWO_PI;
  414.             d = 1.0f;
  415.         } else {
  416.             a = PI - a;
  417.             d = -1.0f;
  418.         }
  419.     }
  420. #else
  421.     a = PI - a;
  422.     if ( fabs( a ) >= HALF_PI ) {
  423.         a = ( ( a < 0.0f ) ? -PI : PI ) - a;
  424.         d = 1.0f;
  425.     } else {
  426.         d = -1.0f;
  427.     }
  428. #endif
  429.     s = a * a;
  430.     return d * ( ( ( ( ( -2.605e-07f * s + 2.47609e-05f ) * s - 1.3888397e-03f ) * s + 4.16666418e-02f ) * s - 4.999999963e-01f ) * s + 1.0f );
  431. }
  432.  
  433. ID_INLINE double idMath::Cos64( float a ) {
  434.     return cos( a );
  435. }
  436. #endif
  437.  
  438. ID_INLINE void idMath::SinCos( float a, float &s, float &c ) {
  439. #ifdef ID_WIN_X86_ASM
  440.     _asm {
  441.         fld        a
  442.         fsincos
  443.         mov        ecx, c
  444.         mov        edx, s
  445.         fstp    dword ptr [ecx]
  446.         fstp    dword ptr [edx]
  447.     }
  448. #else
  449.     s = sinf( a );
  450.     c = cosf( a );
  451. #endif
  452. }
  453.  
  454. ID_INLINE void idMath::SinCos16( float a, float &s, float &c ) {
  455.     float t, d;
  456.  
  457.     if ( ( a < 0.0f ) || ( a >= idMath::TWO_PI ) ) {
  458.         a -= floorf( a / idMath::TWO_PI ) * idMath::TWO_PI;
  459.     }
  460. #if 1
  461.     if ( a < PI ) {
  462.         if ( a > HALF_PI ) {
  463.             a = PI - a;
  464.             d = -1.0f;
  465.         } else {
  466.             d = 1.0f;
  467.         }
  468.     } else {
  469.         if ( a > PI + HALF_PI ) {
  470.             a = a - TWO_PI;
  471.             d = 1.0f;
  472.         } else {
  473.             a = PI - a;
  474.             d = -1.0f;
  475.         }
  476.     }
  477. #else
  478.     a = PI - a;
  479.     if ( fabs( a ) >= HALF_PI ) {
  480.         a = ( ( a < 0.0f ) ? -PI : PI ) - a;
  481.         d = 1.0f;
  482.     } else {
  483.         d = -1.0f;
  484.     }
  485. #endif
  486.     t = a * a;
  487.     s = a * ( ( ( ( ( -2.39e-08f * t + 2.7526e-06f ) * t - 1.98409e-04f ) * t + 8.3333315e-03f ) * t - 1.666666664e-01f ) * t + 1.0f );
  488.     c = d * ( ( ( ( ( -2.605e-07f * t + 2.47609e-05f ) * t - 1.3888397e-03f ) * t + 4.16666418e-02f ) * t - 4.999999963e-01f ) * t + 1.0f );
  489. }
  490.  
  491. ID_INLINE void idMath::SinCos64( float a, double &s, double &c ) {
  492. #ifdef ID_WIN_X86_ASM
  493.     _asm {
  494.         fld        a
  495.         fsincos
  496.         mov        ecx, c
  497.         mov        edx, s
  498.         fstp    qword ptr [ecx]
  499.         fstp    qword ptr [edx]
  500.     }
  501. #else
  502.     s = sin( a );
  503.     c = cos( a );
  504. #endif
  505. }
  506.  
  507. #ifdef _FAST_MATH
  508. ID_INLINE float idMath::Tan( float a ) {
  509.     return tanf( a );
  510. }
  511.  
  512. ID_INLINE float idMath::Tan16( float a ) {
  513.     float s;
  514.     bool reciprocal;
  515.  
  516.     if ( ( a < 0.0f ) || ( a >= PI ) ) {
  517.         a -= floorf( a / PI ) * PI;
  518.     }
  519. #if 1
  520.     if ( a < HALF_PI ) {
  521.         if ( a > ONEFOURTH_PI ) {
  522.             a = HALF_PI - a;
  523.             reciprocal = true;
  524.         } else {
  525.             reciprocal = false;
  526.         }
  527.     } else {
  528.         if ( a > HALF_PI + ONEFOURTH_PI ) {
  529.             a = a - PI;
  530.             reciprocal = false;
  531.         } else {
  532.             a = HALF_PI - a;
  533.             reciprocal = true;
  534.         }
  535.     }
  536. #else
  537.     a = HALF_PI - a;
  538.     if ( fabs( a ) >= ONEFOURTH_PI ) {
  539.         a = ( ( a < 0.0f ) ? -HALF_PI : HALF_PI ) - a;
  540.         reciprocal = false;
  541.     } else {
  542.         reciprocal = true;
  543.     }
  544. #endif
  545.     s = a * a;
  546.     s = a * ( ( ( ( ( ( 9.5168091e-03f * s + 2.900525e-03f ) * s + 2.45650893e-02f ) * s + 5.33740603e-02f ) * s + 1.333923995e-01f ) * s + 3.333314036e-01f ) * s + 1.0f );
  547.     if ( reciprocal ) {
  548.         return 1.0f / s;
  549.     } else {
  550.         return s;
  551.     }
  552. }
  553.  
  554. ID_INLINE double idMath::Tan64( float a ) {
  555.     return tan( a );
  556. }
  557. #endif
  558.  
  559. ID_INLINE float idMath::ASin( float a ) {
  560.     if ( a <= -1.0f ) {
  561.         return -HALF_PI;
  562.     }
  563.     if ( a >= 1.0f ) {
  564.         return HALF_PI;
  565.     }
  566.     return asinf( a );
  567. }
  568.  
  569. ID_INLINE float idMath::ASin16( float a ) {
  570.     if ( FLOATSIGNBITSET( a ) ) {
  571.         if ( a <= -1.0f ) {
  572.             return -HALF_PI;
  573.         }
  574.         a = fabs( a );
  575.         return ( ( ( -0.0187293f * a + 0.0742610f ) * a - 0.2121144f ) * a + 1.5707288f ) * sqrt( 1.0f - a ) - HALF_PI;
  576.     } else {
  577.         if ( a >= 1.0f ) {
  578.             return HALF_PI;
  579.         }
  580.         return HALF_PI - ( ( ( -0.0187293f * a + 0.0742610f ) * a - 0.2121144f ) * a + 1.5707288f ) * sqrt( 1.0f - a );
  581.     }
  582. }
  583.  
  584. ID_INLINE double idMath::ASin64( float a ) {
  585.     if ( a <= -1.0f ) {
  586.         return -HALF_PI;
  587.     }
  588.     if ( a >= 1.0f ) {
  589.         return HALF_PI;
  590.     }
  591.     return asin( a );
  592. }
  593.  
  594. ID_INLINE float idMath::ACos( float a ) {
  595.     if ( a <= -1.0f ) {
  596.         return PI;
  597.     }
  598.     if ( a >= 1.0f ) {
  599.         return 0.0f;
  600.     }
  601.     return acosf( a );
  602. }
  603.  
  604. ID_INLINE float idMath::ACos16( float a ) {
  605.     if ( FLOATSIGNBITSET( a ) ) {
  606.         if ( a <= -1.0f ) {
  607.             return PI;
  608.         }
  609.         a = fabs( a );
  610.         return PI - ( ( ( -0.0187293f * a + 0.0742610f ) * a - 0.2121144f ) * a + 1.5707288f ) * sqrt( 1.0f - a );
  611.     } else {
  612.         if ( a >= 1.0f ) {
  613.             return 0.0f;
  614.         }
  615.         return ( ( ( -0.0187293f * a + 0.0742610f ) * a - 0.2121144f ) * a + 1.5707288f ) * sqrt( 1.0f - a );
  616.     }
  617. }
  618.  
  619. ID_INLINE double idMath::ACos64( float a ) {
  620.     if ( a <= -1.0f ) {
  621.         return PI;
  622.     }
  623.     if ( a >= 1.0f ) {
  624.         return 0.0f;
  625.     }
  626.     return acos( a );
  627. }
  628.  
  629. #ifdef _FAST_MATH
  630. ID_INLINE float idMath::ATan( float a ) {
  631.     return atanf( a );
  632. }
  633.  
  634. ID_INLINE float idMath::ATan16( float a ) {
  635.     float s;
  636.  
  637.     if ( fabs( a ) > 1.0f ) {
  638.         a = 1.0f / a;
  639.         s = a * a;
  640.         s = - ( ( ( ( ( ( ( ( ( 0.0028662257f * s - 0.0161657367f ) * s + 0.0429096138f ) * s - 0.0752896400f )
  641.                 * s + 0.1065626393f ) * s - 0.1420889944f ) * s + 0.1999355085f ) * s - 0.3333314528f ) * s ) + 1.0f ) * a;
  642.         if ( FLOATSIGNBITSET( a ) ) {
  643.             return s - HALF_PI;
  644.         } else {
  645.             return s + HALF_PI;
  646.         }
  647.     } else {
  648.         s = a * a;
  649.         return ( ( ( ( ( ( ( ( ( 0.0028662257f * s - 0.0161657367f ) * s + 0.0429096138f ) * s - 0.0752896400f )
  650.             * s + 0.1065626393f ) * s - 0.1420889944f ) * s + 0.1999355085f ) * s - 0.3333314528f ) * s ) + 1.0f ) * a;
  651.     }
  652. }
  653.  
  654. ID_INLINE double idMath::ATan64( float a ) {
  655.     return atan( a );
  656. }
  657.  
  658. ID_INLINE float idMath::ATan( float y, float x ) {
  659.     return atan2f( y, x );
  660. }
  661.  
  662. ID_INLINE float idMath::ATan16( float y, float x ) {
  663.     float a, s;
  664.  
  665.     if ( fabs( y ) > fabs( x ) ) {
  666.         a = x / y;
  667.         s = a * a;
  668.         s = - ( ( ( ( ( ( ( ( ( 0.0028662257f * s - 0.0161657367f ) * s + 0.0429096138f ) * s - 0.0752896400f )
  669.                 * s + 0.1065626393f ) * s - 0.1420889944f ) * s + 0.1999355085f ) * s - 0.3333314528f ) * s ) + 1.0f ) * a;
  670.         if ( FLOATSIGNBITSET( a ) ) {
  671.             return s - HALF_PI;
  672.         } else {
  673.             return s + HALF_PI;
  674.         }
  675.     } else {
  676.         a = y / x;
  677.         s = a * a;
  678.         return ( ( ( ( ( ( ( ( ( 0.0028662257f * s - 0.0161657367f ) * s + 0.0429096138f ) * s - 0.0752896400f )
  679.             * s + 0.1065626393f ) * s - 0.1420889944f ) * s + 0.1999355085f ) * s - 0.3333314528f ) * s ) + 1.0f ) * a;
  680.     }
  681. }
  682.  
  683. ID_INLINE double idMath::ATan64( float y, float x ) {
  684.     return atan2( y, x );
  685. }
  686. #endif
  687.  
  688. ID_INLINE float idMath::Pow( float x, float y ) {
  689.     return powf( x, y );
  690. }
  691.  
  692. ID_INLINE float idMath::Pow16( float x, float y ) {
  693.     return Exp16( y * Log16( x ) );
  694. }
  695.  
  696. ID_INLINE double idMath::Pow64( float x, float y ) {
  697.     return pow( x, y );
  698. }
  699.  
  700. ID_INLINE float idMath::Exp( float f ) {
  701.     return expf( f );
  702. }
  703.  
  704. ID_INLINE float idMath::Exp16( float f ) {
  705.     int i, s, e, m, exponent;
  706.     float x, x2, y, p, q;
  707.  
  708.     x = f * 1.44269504088896340f;        // multiply with ( 1 / log( 2 ) )
  709. #if 1
  710.     i = *reinterpret_cast<int *>( &x );
  711.     s = ( i >> IEEE_FLT_SIGN_BIT );
  712.     e = ( ( i >> IEEE_FLT_MANTISSA_BITS ) & ( ( 1 << IEEE_FLT_EXPONENT_BITS ) - 1 ) ) - IEEE_FLT_EXPONENT_BIAS;
  713.     m = ( i & ( ( 1 << IEEE_FLT_MANTISSA_BITS ) - 1 ) ) | ( 1 << IEEE_FLT_MANTISSA_BITS );
  714.     i = ( ( m >> ( IEEE_FLT_MANTISSA_BITS - e ) ) & ~( e >> 31 ) ) ^ s;
  715. #else
  716.     i = (int) x;
  717.     if ( x < 0.0f ) {
  718.         i--;
  719.     }
  720. #endif
  721.     exponent = ( i + IEEE_FLT_EXPONENT_BIAS ) << IEEE_FLT_MANTISSA_BITS;
  722.     y = *reinterpret_cast<float *>( &exponent );
  723.     x -= (float) i;
  724.     if ( x >= 0.5f ) {
  725.         x -= 0.5f;
  726.         y *= 1.4142135623730950488f;    // multiply with sqrt( 2 )
  727.     }
  728.     x2 = x * x;
  729.     p = x * ( 7.2152891511493f + x2 * 0.0576900723731f );
  730.     q = 20.8189237930062f + x2;
  731.     x = y * ( q + p ) / ( q - p );
  732.     return x;
  733. }
  734.  
  735. ID_INLINE double idMath::Exp64( float f ) {
  736.     return exp( f );
  737. }
  738.  
  739. ID_INLINE float idMath::Log( float f ) {
  740.     return logf( f );
  741. }
  742.  
  743. ID_INLINE float idMath::Log16( float f ) {
  744.     int i, exponent;
  745.     float y, y2;
  746.  
  747.     i = *reinterpret_cast<int *>( &f );
  748.     exponent = ( ( i >> IEEE_FLT_MANTISSA_BITS ) & ( ( 1 << IEEE_FLT_EXPONENT_BITS ) - 1 ) ) - IEEE_FLT_EXPONENT_BIAS;
  749.     i -= ( exponent + 1 ) << IEEE_FLT_MANTISSA_BITS;    // get value in the range [.5, 1>
  750.     y = *reinterpret_cast<float *>( &i );
  751.     y *= 1.4142135623730950488f;                        // multiply with sqrt( 2 )
  752.     y = ( y - 1.0f ) / ( y + 1.0f );
  753.     y2 = y * y;
  754.     y = y * ( 2.000000000046727f + y2 * ( 0.666666635059382f + y2 * ( 0.4000059794795f + y2 * ( 0.28525381498f + y2 * 0.2376245609f ) ) ) );
  755.     y += 0.693147180559945f * ( (float)exponent + 0.5f );
  756.     return y;
  757. }
  758.  
  759. ID_INLINE double idMath::Log64( float f ) {
  760.     return log( f );
  761. }
  762.  
  763. ID_INLINE int idMath::IPow( int x, int y ) {
  764.     int r; for( r = x; y > 1; y-- ) { r *= x; } return r;
  765. }
  766.  
  767. ID_INLINE int idMath::ILog2( float f ) {
  768.     return ( ( ( *reinterpret_cast<int *>( &f ) ) >> IEEE_FLT_MANTISSA_BITS ) & ( ( 1 << IEEE_FLT_EXPONENT_BITS ) - 1 ) ) - IEEE_FLT_EXPONENT_BIAS;
  769. }
  770.  
  771. ID_INLINE int idMath::ILog2( int i ) {
  772.     return ILog2( (float)i );
  773. }
  774.  
  775. ID_INLINE int idMath::BitsForFloat( float f ) {
  776.     return ILog2( f ) + 1;
  777. }
  778.  
  779. ID_INLINE int idMath::BitsForInteger( int i ) {
  780.     return ILog2( (float)i ) + 1;
  781. }
  782.  
  783. ID_INLINE int idMath::MaskForFloatSign( float f ) {
  784.     return ( ( *reinterpret_cast<int *>( &f ) ) >> 31 );
  785. }
  786.  
  787. ID_INLINE int idMath::MaskForIntegerSign( int i ) {
  788.     return ( i >> 31 );
  789. }
  790.  
  791. ID_INLINE int idMath::FloorPowerOfTwo( int x ) {
  792.     return CeilPowerOfTwo( x ) >> 1;
  793. }
  794.  
  795. ID_INLINE int idMath::CeilPowerOfTwo( int x ) {
  796.     x--;
  797.     x |= x >> 1;
  798.     x |= x >> 2;
  799.     x |= x >> 4;
  800.     x |= x >> 8;
  801.     x |= x >> 16;
  802.     x++;
  803.     return x;
  804. }
  805.  
  806. ID_INLINE bool idMath::IsPowerOfTwo( int x ) {
  807.     return ( x & ( x - 1 ) ) == 0 && x > 0;
  808. }
  809.  
  810. ID_INLINE int idMath::BitCount( int x ) {
  811.     x -= ( ( x >> 1 ) & 0x55555555 );
  812.     x = ( ( ( x >> 2 ) & 0x33333333 ) + ( x & 0x33333333 ) );
  813.     x = ( ( ( x >> 4 ) + x ) & 0x0f0f0f0f );
  814.     x += ( x >> 8 );
  815.     return ( ( x + ( x >> 16 ) ) & 0x0000003f );
  816. }
  817.  
  818. ID_INLINE int idMath::BitReverse( int x ) {
  819.     x = ( ( ( x >> 1 ) & 0x55555555 ) | ( ( x & 0x55555555 ) << 1 ) );
  820.     x = ( ( ( x >> 2 ) & 0x33333333 ) | ( ( x & 0x33333333 ) << 2 ) );
  821.     x = ( ( ( x >> 4 ) & 0x0f0f0f0f ) | ( ( x & 0x0f0f0f0f ) << 4 ) );
  822.     x = ( ( ( x >> 8 ) & 0x00ff00ff ) | ( ( x & 0x00ff00ff ) << 8 ) );
  823.     return ( ( x >> 16 ) | ( x << 16 ) );
  824. }
  825.  
  826. ID_INLINE int idMath::Abs( int x ) {
  827.    int y = x >> 31;
  828.    return ( ( x ^ y ) - y );
  829. }
  830.  
  831. ID_INLINE float idMath::Fabs( float f ) {
  832.     int tmp = *reinterpret_cast<int *>( &f );
  833.     tmp &= 0x7FFFFFFF;
  834.     return *reinterpret_cast<float *>( &tmp );
  835. }
  836.  
  837. ID_INLINE float idMath::Floor( float f ) {
  838.     return floorf( f );
  839. }
  840.  
  841. ID_INLINE float idMath::Ceil( float f ) {
  842.     return ceilf( f );
  843. }
  844.  
  845. ID_INLINE float idMath::Rint( float f ) {
  846.     return floorf( f + 0.5f );
  847. }
  848.  
  849. ID_INLINE int idMath::Ftoi( float f ) {
  850. #ifdef ID_WIN_X86_SSE
  851.     // If a converted result is larger than the maximum signed doubleword integer,
  852.     // the floating-point invalid exception is raised, and if this exception is masked,
  853.     // the indefinite integer value (80000000H) is returned.
  854.     int i;
  855.     __asm cvttss2si    eax, f
  856.     __asm mov        i, eax
  857.     return i;
  858. #else
  859.     // If a converted result is larger than the maximum signed doubleword integer the result is undefined.
  860.     return (int) f;
  861. #endif
  862. }
  863.  
  864. ID_INLINE int idMath::FtoiFast( float f ) {
  865. #ifdef ID_WIN_X86_ASM
  866.     int i;
  867.     __asm fld        f
  868.     __asm fistp        i        // use default rouding mode (round nearest)
  869.     return i;
  870. #elif 0                        // round chop (C/C++ standard)
  871.     int i, s, e, m, shift;
  872.     i = *reinterpret_cast<int *>( &f );
  873.     s = i >> IEEE_FLT_SIGN_BIT;
  874.     e = ( ( i >> IEEE_FLT_MANTISSA_BITS ) & ( ( 1 << IEEE_FLT_EXPONENT_BITS ) - 1 ) ) - IEEE_FLT_EXPONENT_BIAS;
  875.     m = ( i & ( ( 1 << IEEE_FLT_MANTISSA_BITS ) - 1 ) ) | ( 1 << IEEE_FLT_MANTISSA_BITS );
  876.     shift = e - IEEE_FLT_MANTISSA_BITS;
  877.     return ( ( ( ( m >> -shift ) | ( m << shift ) ) & ~( e >> 31 ) ) ^ s ) - s;
  878. #elif defined( __linux__ )
  879.     #ifdef __i386__
  880.         int i;
  881.         __asm__ __volatile__ (
  882.                           "flds        %1\n\t"
  883.                           "fistpl    %0\n\t"
  884.                           : "=m"(i) : "m"(f));
  885.         return i;
  886.     #else
  887.         // lrintf is equivalent but only inlines at -O3
  888.         // although that should be more portable
  889.         return lrintf( f );
  890.     #endif
  891. #elif defined( MACOS_X )
  892.     return lrintf( f );
  893. #else
  894.     return (int) f;
  895. #endif
  896. }
  897.  
  898. ID_INLINE byte idMath::Ftob( float f ) {
  899. #ifdef ID_WIN_X86_SSE
  900.     // If a converted result is negative the value (0) is returned and if the
  901.     // converted result is larger than the maximum byte the value (255) is returned.
  902.     byte b;
  903.     __asm movss        xmm0, f
  904.     __asm maxss        xmm0, SSE_FLOAT_ZERO
  905.     __asm minss        xmm0, SSE_FLOAT_255
  906.     __asm cvttss2si    eax, xmm0
  907.     __asm mov        b, al
  908.     return b;
  909. #else
  910.     // If a converted result is clamped to the range [0-255].
  911.     int i;
  912.     i = (int) f;
  913.     if ( i < 0 ) {
  914.         return 0;
  915.     } else if ( i > 255 ) {
  916.         return 255;
  917.     }
  918.     return i;
  919. #endif
  920. }
  921.  
  922. ID_INLINE signed char idMath::ClampChar( int i ) {
  923.     if ( i < -128 ) {
  924.         return -128;
  925.     }
  926.     if ( i > 127 ) {
  927.         return 127;
  928.     }
  929.     return i;
  930. }
  931.  
  932. // RAVEN BEGIN
  933. ID_INLINE byte idMath::ClampByte( int i ) 
  934. {
  935.     if( i < 0 ) 
  936.     {
  937.         return( 0 );
  938.     }
  939.     if( i > 255 ) 
  940.     {
  941.         return( 255 );
  942.     }
  943.     return( i );
  944. }
  945. // RAVEN END
  946.  
  947. ID_INLINE signed short idMath::ClampShort( int i ) {
  948.     if ( i < -32768 ) {
  949.         return -32768;
  950.     }
  951.     if ( i > 32767 ) {
  952.         return 32767;
  953.     }
  954.     return i;
  955. }
  956.  
  957. ID_INLINE int idMath::ClampInt( int min, int max, int value ) {
  958.     if ( value < min ) {
  959.         return min;
  960.     }
  961.     if ( value > max ) {
  962.         return max;
  963.     }
  964.     return value;
  965. }
  966.  
  967. ID_INLINE float idMath::ClampFloat( float min, float max, float value ) {
  968.     if ( value < min ) {
  969.         return min;
  970.     }
  971.     if ( value > max ) {
  972.         return max;
  973.     }
  974.     return value;
  975. }
  976.  
  977. ID_INLINE float idMath::AngleNormalize360( float angle ) {
  978.     if ( ( angle >= 360.0f ) || ( angle < 0.0f ) ) {
  979.         angle -= floor( angle / 360.0f ) * 360.0f;
  980.     }
  981.     return angle;
  982. }
  983.  
  984. ID_INLINE float idMath::AngleNormalize180( float angle ) {
  985.     angle = AngleNormalize360( angle );
  986.     if ( angle > 180.0f ) {
  987.         angle -= 360.0f;
  988.     }
  989.     return angle;
  990. }
  991.  
  992. ID_INLINE float idMath::AngleDelta( float angle1, float angle2 ) {
  993.     return AngleNormalize180( angle1 - angle2 );
  994. }
  995.  
  996. ID_INLINE int idMath::FloatHash( const float *array, const int numFloats ) {
  997.     int i, hash = 0;
  998.     const int *ptr;
  999.  
  1000.     ptr = reinterpret_cast<const int *>( array );
  1001.     for ( i = 0; i < numFloats; i++ ) {
  1002.         hash ^= ptr[i];
  1003.     }
  1004.     return hash;
  1005. }
  1006.  
  1007. // RAVEN BEGIN
  1008. // jscott: fast and reliable random routines
  1009.  
  1010. // This is the VC libc version of rand() without multiple seeds per thread or 12 levels
  1011. // of subroutine calls.
  1012. // Both calls have been designed to minimise the inherent number of float <--> int 
  1013. // conversions and the additional math required to get the desired value.
  1014. // eg the typical tint = (rand() * 255) / 32768
  1015. // becomes tint = rvRandom::irand( 0, 255 )
  1016.  
  1017. class rvRandom {
  1018. private:
  1019.     static    unsigned long    mSeed;
  1020. public:
  1021.                             rvRandom( void ) { mSeed = 0x89abcdef; }
  1022.  
  1023.     // for a non seed based init
  1024.     static    int                Init( void );
  1025.  
  1026.     // Init the seed to a unique number
  1027.     static    void            Init( unsigned long seed ) { mSeed = seed; }
  1028.  
  1029.     // Returns a float min <= x < max (exclusive; will get max - 0.00001; but never max)
  1030.     static    float            flrand( float min, float max );
  1031.  
  1032.     // Returns a float min <= 0 < 1.0
  1033.     static    float            flrand();
  1034.  
  1035.     static    float            flrand( const idVec2& v );
  1036.  
  1037.     // Returns an integer min <= x <= max (ie inclusive)
  1038.     static    int                irand( int min, int max );
  1039. };
  1040.  
  1041. // RAVEN END
  1042.  
  1043. #endif /* !__MATH_MATH_H__ */
  1044.