I have written a function that computes pow(a,b) in O(logb).
double pow(double a, int b){
double res=1;
while(b>0){
if (b%2==1){
res=res*a;
}
b=b>>1;
a=a*a;
}
return res;
}
I have stumbled upon the question if it would be possible to write a function pow(double a, double b) in O(1)
time. Yet I have not found an answer.