mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-09-06 10:18:18 +00:00
Accelerate HMM_Power() with the squaring technique
Thanks to @mmozeiko for the algorithm
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user