mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-09-07 02:38:15 +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
|
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)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user