wwmath.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWMath *
  23. * *
  24. * $Archive:: /Commando/Code/wwmath/wwmath.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 8/26/01 2:22p $*
  29. * *
  30. * $Revision:: 64 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef WWMATH_H
  39. #define WWMATH_H
  40. #include "always.h"
  41. #include <math.h>
  42. #include <float.h>
  43. #include <assert.h>
  44. #include <float.h>
  45. /*
  46. ** Some global constants.
  47. */
  48. #define WWMATH_EPSILON 0.0001f
  49. #define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON
  50. #define WWMATH_PI 3.141592654f
  51. #define WWMATH_FLOAT_MAX (FLT_MAX)
  52. #define WWMATH_FLOAT_MIN (FLT_MIN)
  53. #define WWMATH_SQRT2 1.414213562f
  54. #define WWMATH_SQRT3 1.732050808f
  55. #define WWMATH_OOSQRT2 0.707106781f
  56. #define WWMATH_OOSQRT3 0.577350269f
  57. // (DRM 05/07/01) Temporarily eliminated _fastcall
  58. // on non-Microsoft compatible compilers. Jani
  59. // should be replacing this soon.
  60. #ifndef _MSC_VER
  61. #define __fastcall
  62. #endif // _MSC_VER
  63. /*
  64. ** Macros to convert between degrees and radians
  65. */
  66. #ifndef RAD_TO_DEG
  67. #define RAD_TO_DEG(x) (((double)x)*180.0/WWMATH_PI)
  68. #endif
  69. #ifndef DEG_TO_RAD
  70. #define DEG_TO_RAD(x) (((double)x)*WWMATH_PI/180.0)
  71. #endif
  72. #ifndef RAD_TO_DEGF
  73. #define RAD_TO_DEGF(x) (((float)x)*180.0f/WWMATH_PI)
  74. #endif
  75. #ifndef DEG_TO_RADF
  76. #define DEG_TO_RADF(x) (((float)x)*WWMATH_PI/180.0f)
  77. #endif
  78. const int ARC_TABLE_SIZE=1024;
  79. const int SIN_TABLE_SIZE=1024;
  80. extern float _FastAcosTable[ARC_TABLE_SIZE];
  81. extern float _FastAsinTable[ARC_TABLE_SIZE];
  82. extern float _FastSinTable[SIN_TABLE_SIZE];
  83. extern float _FastInvSinTable[SIN_TABLE_SIZE];
  84. /*
  85. ** Some simple math functions which work on the built-in types.
  86. ** Include the various other header files in the WWMATH library
  87. ** in order to get matrices, quaternions, etc.
  88. */
  89. class WWMath
  90. {
  91. public:
  92. // Initialization and Shutdown. Other math sub-systems which require initialization and
  93. // shutdown processing will be handled in these functions
  94. static void Init(void);
  95. static void Shutdown(void);
  96. // These are meant to be a collection of small math utility functions to be optimized at some point.
  97. static WWINLINE float Fabs(float val)
  98. {
  99. int value=*(int*)&val;
  100. value&=0x7fffffff;
  101. return *(float*)&value;
  102. }
  103. static WWINLINE int Float_To_Int_Chop(const float& f);
  104. static WWINLINE int Float_To_Int_Floor(const float& f);
  105. #if defined(_MSC_VER) && defined(_M_IX86)
  106. static WWINLINE float Cos(float val);
  107. static WWINLINE float Sin(float val);
  108. static WWINLINE float Sqrt(float val);
  109. static float __fastcall Inv_Sqrt(float a); // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library
  110. static WWINLINE long Float_To_Long(float f);
  111. #else
  112. static float Cos(float val);
  113. static float Sin(float val);
  114. static float Sqrt(float val);
  115. static float Inv_Sqrt(float a);
  116. static long Float_To_Long(float f);
  117. #endif
  118. static WWINLINE float Fast_Sin(float val);
  119. static WWINLINE float Fast_Inv_Sin(float val);
  120. static WWINLINE float Fast_Cos(float val);
  121. static WWINLINE float Fast_Inv_Cos(float val);
  122. static WWINLINE float Fast_Acos(float val);
  123. static WWINLINE float Acos(float val);
  124. static WWINLINE float Fast_Asin(float val);
  125. static WWINLINE float Asin(float val);
  126. static float Atan(float x) { return static_cast<float>(atan(x)); }
  127. static float Atan2(float y,float x) { return static_cast<float>(atan2(y,x)); }
  128. static float Sign(float val);
  129. static float Ceil(float val) { return ceilf(val); }
  130. static float Floor(float val) { return floorf(val); }
  131. static bool Fast_Is_Float_Positive(const float & val);
  132. static float Random_Float(void);
  133. static float Random_Float(float min,float max);
  134. static float Clamp(float val, float min = 0.0f, float max = 1.0f);
  135. static double Clamp(double val, double min = 0.0f, double max = 1.0f);
  136. static float Wrap(float val, float min = 0.0f, float max = 1.0f);
  137. static double Wrap(double val, double min = 0.0f, double max = 1.0f);
  138. static float Min(float a, float b);
  139. static float Max(float a, float b);
  140. static float Lerp(float a, float b, float lerp );
  141. static double Lerp(double a, double b, float lerp );
  142. static long Float_To_Long(double f);
  143. static unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f*255.0f); }
  144. static float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; }
  145. static bool Is_Valid_Float(float x);
  146. static bool Is_Valid_Double(double x);
  147. };
  148. WWINLINE float WWMath::Sign(float val)
  149. {
  150. if (val > 0.0f) {
  151. return +1.0f;
  152. }
  153. if (val < 0.0f) {
  154. return -1.0f;
  155. }
  156. return 0.0f;
  157. }
  158. WWINLINE bool WWMath::Fast_Is_Float_Positive(const float & val)
  159. {
  160. return !((*(int *)(&val)) & 0x80000000);
  161. }
  162. WWINLINE float WWMath::Random_Float(float min,float max)
  163. {
  164. return Random_Float() * (max-min) + min;
  165. }
  166. WWINLINE float WWMath::Clamp(float val, float min /*= 0.0f*/, float max /*= 1.0f*/)
  167. {
  168. if(val < min) return min;
  169. if(val > max) return max;
  170. return val;
  171. }
  172. WWINLINE double WWMath::Clamp(double val, double min /*= 0.0f*/, double max /*= 1.0f*/)
  173. {
  174. if(val < min) return min;
  175. if(val > max) return max;
  176. return val;
  177. }
  178. WWINLINE float WWMath::Wrap(float val, float min /*= 0.0f*/, float max /*= 1.0f*/)
  179. {
  180. // Implemented as an if rather than a while, to long loops
  181. if ( val >= max ) val -= (max-min);
  182. if ( val < min ) val += (max-min);
  183. if ( val < min ) {
  184. val = min;
  185. }
  186. if ( val > max ) {
  187. val = max;
  188. }
  189. return val;
  190. }
  191. WWINLINE double WWMath::Wrap(double val, double min /*= 0.0f*/, double max /*= 1.0f*/)
  192. {
  193. // Implemented as an if rather than a while, to long loops
  194. if ( val >= max ) val -= (max-min);
  195. if ( val < min ) val += (max-min);
  196. if ( val < min ) {
  197. val = min;
  198. }
  199. if ( val > max ) {
  200. val = max;
  201. }
  202. return val;
  203. }
  204. WWINLINE float WWMath::Min(float a, float b)
  205. {
  206. if (a<b) return a;
  207. return b;
  208. }
  209. WWINLINE float WWMath::Max(float a, float b)
  210. {
  211. if (a>b) return a;
  212. return b;
  213. }
  214. WWINLINE float WWMath::Lerp(float a, float b, float lerp )
  215. {
  216. return (a + (b - a)*lerp);
  217. }
  218. WWINLINE double WWMath::Lerp(double a, double b, float lerp )
  219. {
  220. return (a + (b - a)*lerp);
  221. }
  222. WWINLINE bool WWMath::Is_Valid_Float(float x)
  223. {
  224. unsigned long * plong = (unsigned long *)(&x);
  225. unsigned long exponent = ((*plong) & 0x7F800000) >> (32-9);
  226. // if exponent is 0xFF, this is a NAN
  227. if (exponent == 0xFF) {
  228. return false;
  229. }
  230. return true;
  231. }
  232. WWINLINE bool WWMath::Is_Valid_Double(double x)
  233. {
  234. unsigned long * plong = (unsigned long *)(&x) + 1;
  235. unsigned long exponent = ((*plong) & 0x7FF00000) >> (32-12);
  236. // if exponent is 0x7FF, this is a NAN
  237. if (exponent == 0x7FF) {
  238. return false;
  239. }
  240. return true;
  241. }
  242. // ----------------------------------------------------------------------------
  243. // Float to long
  244. // ----------------------------------------------------------------------------
  245. #if defined(_MSC_VER) && defined(_M_IX86)
  246. WWINLINE long WWMath::Float_To_Long(float f)
  247. {
  248. long i;
  249. __asm {
  250. fld [f]
  251. fistp [i]
  252. }
  253. return i;
  254. }
  255. #else
  256. WWINLINE long WWMath::Float_To_Long(float f)
  257. {
  258. return (long) f;
  259. }
  260. #endif
  261. WWINLINE long WWMath::Float_To_Long(double f)
  262. {
  263. #if defined(_MSC_VER) && defined(_M_IX86)
  264. long retval;
  265. __asm fld qword ptr [f]
  266. __asm fistp dword ptr [retval]
  267. return retval;
  268. #else
  269. return (long) f;
  270. #endif
  271. }
  272. // ----------------------------------------------------------------------------
  273. // Cos
  274. // ----------------------------------------------------------------------------
  275. #if defined(_MSC_VER) && defined(_M_IX86)
  276. WWINLINE float WWMath::Cos(float val)
  277. {
  278. float retval;
  279. __asm {
  280. fld [val]
  281. fcos
  282. fstp [retval]
  283. }
  284. return retval;
  285. }
  286. #else
  287. WWINLINE float WWMath::Cos(float val)
  288. {
  289. return cosf(val);
  290. }
  291. #endif
  292. // ----------------------------------------------------------------------------
  293. // Sin
  294. // ----------------------------------------------------------------------------
  295. #if defined(_MSC_VER) && defined(_M_IX86)
  296. WWINLINE float WWMath::Sin(float val)
  297. {
  298. float retval;
  299. __asm {
  300. fld [val]
  301. fsin
  302. fstp [retval]
  303. }
  304. return retval;
  305. }
  306. #else
  307. WWINLINE float WWMath::Sin(float val)
  308. {
  309. return sinf(val);
  310. }
  311. #endif
  312. // ----------------------------------------------------------------------------
  313. // Fast, table based sin
  314. // ----------------------------------------------------------------------------
  315. WWINLINE float WWMath::Fast_Sin(float val)
  316. {
  317. val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI);
  318. int idx0=Float_To_Int_Floor(val);
  319. int idx1=idx0+1;
  320. float frac=val-(float)idx0;
  321. idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1);
  322. idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1);
  323. return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1];
  324. }
  325. // ----------------------------------------------------------------------------
  326. // Fast, table based 1.0f/sin
  327. // ----------------------------------------------------------------------------
  328. WWINLINE float WWMath::Fast_Inv_Sin(float val)
  329. {
  330. #if 0 // TODO: more testing, not reliable!
  331. float index = val * float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI);
  332. int idx0=Float_To_Int_Floor(index);
  333. int idx1=idx0+1;
  334. float frac=val-(float)idx0;
  335. idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1);
  336. idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1);
  337. // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide.
  338. const int BUFFER = 16;
  339. if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE-BUFFER-1)) {
  340. return 1.0f / WWMath::Fast_Sin(val);
  341. } else {
  342. return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1];
  343. }
  344. #else
  345. return 1.0f / WWMath::Fast_Sin(val);
  346. #endif
  347. }
  348. // ----------------------------------------------------------------------------
  349. // Fast, table based cos
  350. // ----------------------------------------------------------------------------
  351. WWINLINE float WWMath::Fast_Cos(float val)
  352. {
  353. val+=(WWMATH_PI * 0.5f);
  354. val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI);
  355. int idx0=Float_To_Int_Floor(val);
  356. int idx1=idx0+1;
  357. float frac=val-(float)idx0;
  358. idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1);
  359. idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1);
  360. return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1];
  361. }
  362. // ----------------------------------------------------------------------------
  363. // Fast, table based 1.0f/cos
  364. // ----------------------------------------------------------------------------
  365. WWINLINE float WWMath::Fast_Inv_Cos(float val)
  366. {
  367. #if 0 // TODO: more testing, not reliable!
  368. float index = val + (WWMATH_PI * 0.5f);
  369. index *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI);
  370. int idx0=Float_To_Int_Chop(index);
  371. int idx1=idx0+1;
  372. float frac=val-(float)idx0;
  373. idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1);
  374. idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1);
  375. // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide.
  376. if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE-3)) {
  377. return 1.0f / WWMath::Fast_Cos(val);
  378. } else {
  379. return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1];
  380. }
  381. #else
  382. return 1.0f / WWMath::Fast_Cos(val);
  383. #endif
  384. }
  385. // ----------------------------------------------------------------------------
  386. // Fast, table based arc cos
  387. // ----------------------------------------------------------------------------
  388. WWINLINE float WWMath::Fast_Acos(float val)
  389. {
  390. // Near -1 and +1, the table becomes too inaccurate
  391. if (WWMath::Fabs(val) > 0.975f) {
  392. return WWMath::Acos(val);
  393. }
  394. val*=float(ARC_TABLE_SIZE/2);
  395. int idx0=Float_To_Int_Floor(val);
  396. int idx1=idx0+1;
  397. float frac=val-(float)idx0;
  398. idx0+=ARC_TABLE_SIZE/2;
  399. idx1+=ARC_TABLE_SIZE/2;
  400. // we dont even get close to the edge of the table...
  401. assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE));
  402. assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE));
  403. // compute and return the interpolated value
  404. return (1.0f - frac) * _FastAcosTable[idx0] + frac * _FastAcosTable[idx1];
  405. }
  406. // ----------------------------------------------------------------------------
  407. // Arc cos
  408. // ----------------------------------------------------------------------------
  409. WWINLINE float WWMath::Acos(float val)
  410. {
  411. return (float)acos(val);
  412. }
  413. // ----------------------------------------------------------------------------
  414. // Fast, table based arc sin
  415. // ----------------------------------------------------------------------------
  416. WWINLINE float WWMath::Fast_Asin(float val)
  417. {
  418. // Near -1 and +1, the table becomes too inaccurate
  419. if (WWMath::Fabs(val) > 0.975f) {
  420. return WWMath::Asin(val);
  421. }
  422. val*=float(ARC_TABLE_SIZE/2);
  423. int idx0=Float_To_Int_Floor(val);
  424. int idx1=idx0+1;
  425. float frac=val-(float)idx0;
  426. idx0+=ARC_TABLE_SIZE/2;
  427. idx1+=ARC_TABLE_SIZE/2;
  428. // we dont even get close to the edge of the table...
  429. assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE));
  430. assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE));
  431. // compute and return the interpolated value
  432. return (1.0f - frac) * _FastAsinTable[idx0] + frac * _FastAsinTable[idx1];
  433. }
  434. // ----------------------------------------------------------------------------
  435. // Arc sin
  436. // ----------------------------------------------------------------------------
  437. WWINLINE float WWMath::Asin(float val)
  438. {
  439. return (float)asin(val);
  440. }
  441. // ----------------------------------------------------------------------------
  442. // Sqrt
  443. // ----------------------------------------------------------------------------
  444. #if defined(_MSC_VER) && defined(_M_IX86)
  445. WWINLINE float WWMath::Sqrt(float val)
  446. {
  447. float retval;
  448. __asm {
  449. fld [val]
  450. fsqrt
  451. fstp [retval]
  452. }
  453. return retval;
  454. }
  455. #else
  456. WWINLINE float WWMath::Sqrt(float val)
  457. {
  458. return (float)sqrt(val);
  459. }
  460. #endif
  461. WWINLINE int WWMath::Float_To_Int_Chop(const float& f)
  462. {
  463. int a = *reinterpret_cast<const int*>(&f); // take bit pattern of float into a register
  464. int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive
  465. int mantissa = (a&((1<<23)-1))|(1<<23); // extract mantissa and add the hidden bit
  466. int exponent = ((a&0x7fffffff)>>23)-127; // extract the exponent
  467. int r = ((unsigned int)(mantissa)<<8)>>(31-exponent); // ((1<<exponent)*mantissa)>>24 -- (we know that mantissa > (1<<24))
  468. return ((r ^ (sign)) - sign ) &~ (exponent>>31); // add original sign. If exponent was negative, make return value 0.
  469. }
  470. WWINLINE int WWMath::Float_To_Int_Floor (const float& f)
  471. {
  472. int a = *reinterpret_cast<const int*>(&f); // take bit pattern of float into a register
  473. int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive
  474. a&=0x7fffffff; // we don't need the sign any more
  475. int exponent = (a>>23)-127; // extract the exponent
  476. int expsign = ~(exponent>>31); // 0xFFFFFFFF if exponent is positive, 0 otherwise
  477. int imask = ( (1<<(31-(exponent))))-1; // mask for true integer values
  478. int mantissa = (a&((1<<23)-1)); // extract mantissa (without the hidden bit)
  479. int r = ((unsigned int)(mantissa|(1<<23))<<8)>>(31-exponent); // ((1<<exponent)*(mantissa|hidden bit))>>24 -- (we know that mantissa > (1<<24))
  480. r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign); // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++;
  481. return r;
  482. }
  483. // ----------------------------------------------------------------------------
  484. // Inverse square root
  485. // ----------------------------------------------------------------------------
  486. #if defined(_MSC_VER) && defined(_M_IX86)
  487. WWINLINE __declspec(naked) float __fastcall WWMath::Inv_Sqrt(float a)
  488. {
  489. __asm {
  490. mov eax, 0be6eb508h
  491. mov DWORD PTR [esp-12],03fc00000h ; 1.5 on the stack
  492. sub eax, DWORD PTR [esp+4]; a
  493. sub DWORD PTR [esp+4], 800000h ; a/2 a=Y0
  494. shr eax, 1 ; firs approx in eax=R0
  495. mov DWORD PTR [esp-8], eax
  496. fld DWORD PTR [esp-8] ;r
  497. fmul st, st ;r*r
  498. fld DWORD PTR [esp-8] ;r
  499. fxch st(1)
  500. fmul DWORD PTR [esp+4];a ;r*r*y0
  501. fld DWORD PTR [esp-12];load 1.5
  502. fld st(0)
  503. fsub st,st(2) ;r1 = 1.5 - y1
  504. ;x1 = st(3)
  505. ;y1 = st(2)
  506. ;1.5 = st(1)
  507. ;r1 = st(0)
  508. fld st(1)
  509. fxch st(1)
  510. fmul st(3),st ; y2=y1*r1*...
  511. fmul st(3),st ; y2=y1*r1*r1
  512. fmulp st(4),st ; x2=x1*r1
  513. fsub st,st(2) ; r2=1.5-y2
  514. ;x2=st(3)
  515. ;y2=st(2)
  516. ;1.5=st(1)
  517. ;r2 = st(0)
  518. fmul st(2),st ;y3=y2*r2*...
  519. fmul st(3),st ;x3=x2*r2
  520. fmulp st(2),st ;y3=y2*r2*r2
  521. fxch st(1)
  522. fsubp st(1),st ;r3= 1.5 - y3
  523. ;x3 = st(1)
  524. ;r3 = st(0)
  525. fmulp st(1), st
  526. ret 4
  527. }
  528. }
  529. #else
  530. WWINLINE float WWMath::Inv_Sqrt(float val)
  531. {
  532. return 1.0f / (float)sqrt(val);
  533. }
  534. #endif
  535. #endif