Implement pow(x, n).
double myPow(double x, int n) {
int flag=false;
if(n == 0){
return 1;
}
else if(n < 0){
n = 0- n;
flag=true;
}
double result = 1;
while(n>0){
if(n&1){
result *= x;
}
n>>=1;
x *= x;
}
if(flag)
return 1/result;
return result;
}
原文地址:http://searchcoding.blog.51cto.com/1335412/1695028