mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-09-07 10:48:17 +00:00
Added HMM_FastInverseSquareRoot function
With it's original comments. :) I won't mess too much with the coding style, because I don't fully understand it. It works, though.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user