diff --git a/HandmadeMath.h b/HandmadeMath.h index 8db5f05..ba435b7 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -343,6 +343,24 @@ HMM_SquareRoot(float Float) return(Result); } +HINLINE float +HMM_FastInverseSquareRoot(float Number) +{ + long i; + float x2, y; + const float threehalfs = 1.5f; + + x2 = Number * 0.5f; + y = Number; + i = * ( long * ) &y; // evil floating point bit level hacking + i = 0x5f3759df - ( i >> 1 ); // what the fuck? + y = * ( float * ) &i; + + y = y * ( threehalfs - ( x2 * y * y ) ); + + return ( y ); +} + HINLINE float HMM_LengthSquareRoot(hmm_vec3 A) {