Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #define BIG_NUMBER (3.4e+38f)
  2.  
  3. struct Math
  4. {
  5. static float Abs(float F)
  6. {
  7. return F > 0.0f ? F : -F;
  8. }
  9.  
  10. static float Sqrt(float F)
  11. {
  12. int NUM_REAPEAT = 16;
  13. int k;
  14. float t;
  15. float buf = F;
  16.  
  17. for (k = 0, t = buf; k < NUM_REAPEAT; k++)
  18. {
  19. if (t < 1.f)
  20. break;
  21. t = (t * t + buf) / (2.f * t);
  22. }
  23.  
  24. return t;
  25. }
  26.  
  27. static float InvSqrt(float F)
  28. {
  29. float FHalf = 0.5f * F;
  30. int i = *(int*)&F;
  31. i = 0x5f3759df - (i >> 1);
  32. F = *(float*)&i;
  33. F = F * (1.5f - (FHalf * F * F));
  34.  
  35. return F;
  36. }
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement