46 #define momax(a,b) ((a)>(b)?(a):(b))
49 #define momin(a,b) ((a)<(b)?(a):(b))
81 inline static Real
ACos (Real fValue)
83 if (-(Real)1.0 < fValue)
85 if (fValue < (Real)1.0)
87 return (Real)acos((
double)fValue);
105 inline static Real
ASin (Real fValue)
107 if (-(Real)1.0 < fValue)
109 if (fValue < (Real)1.0)
111 return (Real)asin((
double)fValue);
129 inline static Real
ATan (Real fValue)
131 return (Real)atan((
double)fValue);
140 inline static Real
ATan2 (Real fY, Real fX)
142 return (Real)atan2((
double)fY,(
double)fX);
150 inline static Real
Ceil (Real fValue)
152 return (Real)ceil((
double)fValue);
160 inline static Real
Cos (Real fValue)
162 return (Real)cos((
double)fValue);
170 inline static Real
Exp (Real fValue)
172 return (Real)exp((
double)fValue);
180 inline static Real
FAbs (Real fValue)
182 return (Real)fabs((
double)fValue);
190 inline static Real
Floor (Real fValue)
192 return (Real)floor((
double)fValue);
200 inline static Real
FMod (Real fX, Real fY)
202 return (Real)fmod((
double)fX,(
double)fY);
212 return (Real)(1.0/sqrt((
double)fValue));
220 inline static Real
Log (Real fValue)
222 return (Real)log((
double)fValue);
230 inline static Real
Log2 (Real fValue)
240 inline static Real
Log10 (Real fValue)
250 inline static Real
Pow (Real fBase, Real fExponent)
252 return (Real)pow((
double)fBase,(
double)fExponent);
260 inline static Real
Sin (Real fValue)
262 return (Real)sin((
double)fValue);
270 inline static Real
Sqr (Real fValue) {
271 return fValue*fValue;
279 inline static Real
Sqrt (Real fValue) {
280 return (Real)sqrt((
double)fValue);
288 inline static Real
Tan (Real fValue) {
289 return (Real)tan((
double)fValue);
298 return (iValue > 0) && ((iValue & (iValue - 1)) == 0);
307 unsigned int uiLog2 = (uiPowerOfTwo & 0xAAAAAAAA) != 0;
308 uiLog2 |= ((uiPowerOfTwo & 0xFFFF0000) != 0) << 4;
309 uiLog2 |= ((uiPowerOfTwo & 0xFF00FF00) != 0) << 3;
310 uiLog2 |= ((uiPowerOfTwo & 0xF0F0F0F0) != 0) << 2;
311 uiLog2 |= ((uiPowerOfTwo & 0xCCCCCCCC) != 0) << 1;
326 iShift = 150 - iLog - ((*(
int*)(&fFloat) >> 23) & 0xFF);
329 iInt = ((*(
int*)(&fFloat) & 0x007FFFFF) | 0x00800000) >> iShift;
330 if ( iInt == (1 << iLog) ) iInt--;
341 inline static char Sign (
int iValue) {
360 inline static Real
Sign (Real fValue) {
361 if (fValue > (Real)0.0)
366 if (fValue < (Real)0.0)
386 double dRatio = ((double)rand())/((
double)(RAND_MAX));
402 double dRatio = ((double)rand())/((
double)(RAND_MAX));
403 return (Real)(2.0*dRatio - 1.0);
415 unsigned int uiSeed = 0) {
421 double dRatio = ((double)rand())/((
double)(RAND_MAX));
422 return fMin+(fMax-fMin)*((Real)dRatio);
432 return UnitRandom ((
unsigned int)rSeed);
441 return SymmetricRandom ((
unsigned int)rSeed);
452 return IntervalRandom (fMin, fMax, (
unsigned int)rSeed);
461 Real fASqr = fAngle*fAngle;
462 Real fResult = (Real)7.61e-03;
464 fResult -= (Real)1.6605e-01;
466 fResult += (Real)1.0;
477 Real fASqr = fAngle*fAngle;
478 Real fResult = -(Real)2.39e-08;
480 fResult += (Real)2.7526e-06;
482 fResult -= (Real)1.98409e-04;
484 fResult += (Real)8.3333315e-03;
486 fResult -= (Real)1.666666664e-01;
488 fResult += (Real)1.0;
499 Real fASqr = fAngle*fAngle;
500 Real fResult = (Real)3.705e-02;
502 fResult -= (Real)4.967e-01;
504 fResult += (Real)1.0;
514 Real fASqr = fAngle*fAngle;
515 Real fResult = -(Real)2.605e-07;
517 fResult += (Real)2.47609e-05;
519 fResult -= (Real)1.3888397e-03;
521 fResult += (Real)4.16666418e-02;
523 fResult -= (Real)4.999999963e-01;
525 fResult += (Real)1.0;
535 Real fASqr = fAngle*fAngle;
536 Real fResult = (Real)2.033e-01;
538 fResult += (Real)3.1755e-01;
540 fResult += (Real)1.0;
551 Real fASqr = fAngle*fAngle;
552 Real fResult = (Real)9.5168091e-03;
554 fResult += (Real)2.900525e-03;
556 fResult += (Real)2.45650893e-02;
558 fResult += (Real)5.33740603e-02;
560 fResult += (Real)1.333923995e-01;
562 fResult += (Real)3.333314036e-01;
564 fResult += (Real)1.0;
576 Real fResult = -(Real)0.0187293;
578 fResult += (Real)0.0742610;
580 fResult -= (Real)0.2121144;
582 fResult += (Real)1.5707288;
583 fResult = HALF_PI - fRoot*fResult;
594 Real fResult = -(Real)0.0012624911;
596 fResult += (Real)0.0066700901;
598 fResult -= (Real)0.0170881256;
600 fResult += (Real)0.0308918810;
602 fResult -= (Real)0.0501743046;
604 fResult += (Real)0.0889789874;
606 fResult -= (Real)0.2145988016;
608 fResult += (Real)1.5707963050;
609 fResult = HALF_PI - fRoot*fResult;
620 Real fResult = -(Real)0.0187293;
622 fResult += (Real)0.0742610;
624 fResult -= (Real)0.2121144;
626 fResult += (Real)1.5707288;
638 Real fResult = -(Real)0.0012624911;
640 fResult += (Real)0.0066700901;
642 fResult -= (Real)0.0170881256;
644 fResult += (Real)0.0308918810;
646 fResult -= (Real)0.0501743046;
648 fResult += (Real)0.0889789874;
650 fResult -= (Real)0.2145988016;
652 fResult += (Real)1.5707963050;
663 Real fVSqr = fValue*fValue;
664 Real fResult = (Real)0.0208351;
666 fResult -= (Real)0.085133;
668 fResult += (Real)0.180141;
670 fResult -= (Real)0.3302995;
672 fResult += (Real)0.999866;
683 Real fVSqr = fValue*fValue;
684 Real fResult = (Real)0.0028662257;
686 fResult -= (Real)0.0161657367;
688 fResult += (Real)0.0429096138;
690 fResult -= (Real)0.0752896400;
692 fResult += (Real)0.1065626393;
694 fResult -= (Real)0.1420889944;
696 fResult += (Real)0.1999355085;
698 fResult -= (Real)0.3333314528;
700 fResult += (Real)1.0;
710 static Real FastInvSqrt (Real fValue);
718 Real fResult = (Real)0.0038278;
720 fResult += (Real)0.0292732;
722 fResult += (Real)0.2507213;
724 fResult += (Real)1.0;
727 fResult = ((Real)1.0)/fResult;
737 Real fResult = (Real)0.00026695;
739 fResult += (Real)0.00227723;
741 fResult += (Real)0.03158565;
743 fResult += (Real)0.24991035;
745 fResult += (Real)1.0;
748 fResult = ((Real)1.0)/fResult;
758 Real fResult = (Real)0.000014876;
760 fResult += (Real)0.000127992;
762 fResult += (Real)0.002673255;
764 fResult += (Real)0.031198056;
766 fResult += (Real)0.250010936;
768 fResult += (Real)1.0;
771 fResult = ((Real)1.0)/fResult;
781 Real fResult = (Real)0.0000006906;
783 fResult += (Real)0.0000054302;
785 fResult += (Real)0.0001715620;
787 fResult += (Real)0.0025913712;
789 fResult += (Real)0.0312575832;
791 fResult += (Real)0.2499986842;
793 fResult += (Real)1.0;
796 fResult = ((Real)1.0)/fResult;
807 return DEG_TO_RAD * iDeg;
817 return RAD_TO_DEG * iRad;
826 static const Real
PI;
910 int i = *(
int*)&fValue;
911 i = 0x5f3759df - (i >> 1);
913 fValue = fValue*(1.5f - fHalf*fValue*fValue);
922 #if defined(WM4_USING_VC70) || defined(WM4_USING_VC6)
923 i = 0x5fe6ec85e7de30da - (i >> 1);
925 i = 0x5fe6ec85e7de30daLL - (i >> 1);
928 dValue = dValue*(1.5 - dHalf*dValue*dValue);
static Real FastInvTan1(Real fValue)
static const Real HALF_PI
static Real Log2(Real fValue)
static Real FastCos1(Real fAngle)
static Real FastTan1(Real fAngle)
static Real FastTan0(Real fAngle)
static Real FastInvSin1(Real fValue)
static Real FastNegExp2(Real fValue)
static Real ACos(Real fValue)
static Real ATan2(Real fY, Real fX)
static Real IntervalRandom(Real fMin, Real fMax, Real rSeed)
static Real SymmetricRandom(Real rSeed)
static const Real RAD_TO_DEG
static const Real INV_TWO_PI
static Real FastInvCos1(Real fValue)
static Real Sin(Real fValue)
static Real Tan(Real fValue)
static Real Log(Real fValue)
static Real Sqr(Real fValue)
static Real FastNegExp0(Real fValue)
static const Real ZERO_TOLERANCE
static Real SymmetricRandom(unsigned int uiSeed=0)
static Real Floor(Real fValue)
static const Real EPSILON
static Real ATan(Real fValue)
static Real Log10(Real fValue)
static Real DegToRad(Real iDeg)
static const Real MAX_REAL
static Real InvSqrt(Real fValue)
static Real FastNegExp3(Real fValue)
static Real Sqrt(Real fValue)
static Real ASin(Real fValue)
static char Sign(int iValue)
static Real FastCos0(Real fAngle)
static const Real INV_LN_10
static Real FastSin0(Real fAngle)
static Real FastInvTan0(Real fValue)
static Real UnitRandom(Real rSeed)
static Real RadToDeg(Real iRad)
static Real Cos(Real fValue)
static Real FastInvSqrt(Real fValue)
static Real FMod(Real fX, Real fY)
bool IsPowerOfTwo(int iValue)
static Real FastInvSin0(Real fValue)
static Real FastInvCos0(Real fValue)
static int ScaledFloatToInt(float fFloat, int iLog)
static const Real INV_LN_2
static Real Pow(Real fBase, Real fExponent)
static Real FastNegExp1(Real fValue)
static Real IntervalRandom(Real fMin, Real fMax, unsigned int uiSeed=0)
static const Real DEG_TO_RAD
static Real FAbs(Real fValue)
static Real Sign(Real fValue)
static Real UnitRandom(unsigned int uiSeed=0)
static Real FastSin1(Real fAngle)
static Real Exp(Real fValue)
static Real Ceil(Real fValue)
unsigned int Log2OfPowerOfTwo(unsigned int uiPowerOfTwo)