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 HINLINE float
HMM_Power(float Base, int Exponent) HMM_Power(float Base, int Exponent)
{ {
float Result = 1; float Result = 1.0f;
float Mul = Exponent < 0 ? 1.f / Base : Base;
if(Exponent > 0) unsigned int X = Exponent < 0 ? -Exponent : Exponent;
while (X)
{ {
int i; if (X & 1)
for(i = 0; i < Exponent; ++i)
{ {
Result *= Base; Result *= Mul;
} }
Mul *= Mul;
X >>= 1;
} }
else
{
int i;
for(i = 0; i > Exponent; --i)
{
Result /= Base;
}
}
return (Result); return (Result);
} }
HINLINE float HINLINE float
HMM_Lerp(float A, float Time, float B) HMM_Lerp(float A, float Time, float B)
{ {