Accelerate HMM_Power() with the squaring technique

Thanks to @mmozeiko for the algorithm
This commit is contained in:
Matt Mascarenhas
2016-08-29 21:58:14 +01:00
parent c58043db84
commit cad7efa639

View File

@@ -598,28 +598,22 @@ HMM_Length(hmm_vec3 A)
HINLINE float
HMM_Power(float Base, int Exponent)
{
float Result = 1;
if(Exponent > 0)
float Result = 1.0f;
float Mul = Exponent < 0 ? 1.f / Base : Base;
unsigned int X = Exponent < 0 ? -Exponent : Exponent;
while (X)
{
int i;
for(i = 0; i < Exponent; ++i)
if (X & 1)
{
Result *= Base;
Result *= Mul;
}
Mul *= Mul;
X >>= 1;
}
else
{
int i;
for(i = 0; i > Exponent; --i)
{
Result /= Base;
}
}
return (Result);
}
HINLINE float
HMM_Lerp(float A, float Time, float B)
{