// Essential Header file - math.h
// Log2 Function
double Log2(double in)
{
return log(in)/ log(double(2));
}
Let us use the above function for calculating nearest power of two easily, as given below.
int NearestPowerOfTwo(int in)
{
return pow(2, ceil(Log2(in)));
}
Couldn't you speed this up by just precomputing log(double(2)) might not seem like much but it certainly can be when computing millions/billions of times in a look in scientific computing and it's basically "free" :) . -D , texas, usa
ReplyDeleteI meant loop :) , -D, texas, usa
ReplyDelete