mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-09-07 18:58:19 +00:00
Merge pull request #10 from Valmar33/revert-8-revert-7-master
Revert "Revert "Added HMM_FastInverseSquareRoot function""
This commit is contained in:
@@ -223,6 +223,7 @@ HMMDEF float HMM_ToRadians(float Degrees);
|
|||||||
HMMDEF float HMM_Inner(hmm_vec3 A, hmm_vec3 B);
|
HMMDEF float HMM_Inner(hmm_vec3 A, hmm_vec3 B);
|
||||||
HMMDEF float HMM_SquareRoot(float Float);
|
HMMDEF float HMM_SquareRoot(float Float);
|
||||||
HMMDEF float HMM_LengthSquareRoot(hmm_vec3 A);
|
HMMDEF float HMM_LengthSquareRoot(hmm_vec3 A);
|
||||||
|
HMMDEF float HMM_FastInverseSquareRoot(float Number);
|
||||||
HMMDEF float HMM_Length(hmm_vec3 A);
|
HMMDEF float HMM_Length(hmm_vec3 A);
|
||||||
HMMDEF float HMM_Power(float Base, int Exponent);
|
HMMDEF float HMM_Power(float Base, int Exponent);
|
||||||
HMMDEF float HMM_Clamp(float Min, float Value, float Max);
|
HMMDEF float HMM_Clamp(float Min, float Value, float Max);
|
||||||
@@ -351,6 +352,24 @@ HMM_LengthSquareRoot(hmm_vec3 A)
|
|||||||
return (Result);
|
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
|
HINLINE float
|
||||||
HMM_Length(hmm_vec3 A)
|
HMM_Length(hmm_vec3 A)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user