Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BIG_NUMBER (3.4e+38f)
- struct Math
- {
- static float Abs(float F)
- {
- return F > 0.0f ? F : -F;
- }
- static float Sqrt(float F)
- {
- int NUM_REAPEAT = 16;
- int k;
- float t;
- float buf = F;
- for (k = 0, t = buf; k < NUM_REAPEAT; k++)
- {
- if (t < 1.f)
- break;
- t = (t * t + buf) / (2.f * t);
- }
- return t;
- }
- static float InvSqrt(float F)
- {
- float FHalf = 0.5f * F;
- int i = *(int*)&F;
- i = 0x5f3759df - (i >> 1);
- F = *(float*)&i;
- F = F * (1.5f - (FHalf * F * F));
- return F;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement