
Implement pow(x, n).
Subscribe to see which companies asked this question
利用依次消去二进制位上的1,来进行计算
double myPow(double x, int n) {
double ans = ;
unsigned long long p;
if (n < ) {
p = -n;
x = / x;
}
else {
p = n;
}
while (p) {
if (p & )
ans *= x;
x *= x;
p >>= ;
}
return ans;
}