Advertisement
Guest User

Untitled

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