Friday, July 16, 2010

Efficiently calculating integer powers of float


static float pow(float base, int exp) {
float result = 1;
if(exp<0) return 1.0f/pow(base,-exp);
while (exp!=0) {
if ((exp & 1)!=0) result *= base;
exp >>= 1;
base *= base;
}
return result;
}

No comments:

Post a Comment