In C, I am trying a few different things, but am not sure which is most efficient. I am trying to have a power function returns
Originally I had
long long rhs = num % (long long) pow(10, pos);
but this gave errors as the power became high.
I substituted powl
to return a long double
, which works flawlessly in returning powers up to the largest value of long long
long long rhs = num % (long long) powl(10, pos);
However, I am worried that this may not be the most efficient way to get powers of 10, which are reused in other parts of the programs.
For getting powers of ten to divide a long long up to its maximum value, should I continue using the powl cast to long long method or use a function that only returns long long like i did below. Which is more efficient?
long long pow10(int exp)
{
long long pow = 1;
for(exp = exp; exp > 0; exp--)
{
pow *= 10;
}
return pow;
}//pow10