The typical way to unroll this uses the bitwise representation of b. Compute a1, a2, a4, a8, etc. and at each step determine whether or not to multiply it into the total. This is shown here:
double result = 1;
double multiplier = a;
for (double multiplier = a; b != 0; multiplier *= multiplier, b /= 2) {
if (b % 2 == 1) {
result *= multiplier;
}
}
For example, to compute 35, we'd notice that 5 has binary representation 101, so we'd multiply in 31 and 34.
Hope this helps!