//计算指数为非负数的次方
public double powerWithExponet(double base, int exponent){
if(exponent == 0)
return 1.0;
if(exponent == 1)
return base;
//使用左移运算符,将exponent除以2
double result = powerWithExponet(base, exponent >> 1);
result *= result;
if((exponent & 1) == 1){ //判断是否为奇数
result *= base;
}
return result;
}
https://blog.csdn.net/weixin_37672169/article/details/80150005