/**
* 数值的整数次方
* @param base
* @param exponent
* @return
*/
public static double Power(double base, int exponent) {
double res = 1, curr = base;
if (exponent == 0) {
if (base == 0)
throw new RuntimeException("分母不能为0");
else return 1;
}
int e = exponent > 0 ? exponent : -exponent;
while (e != 0) {
res = (e & 1) != 0 ? res * base : res;
base *= base;//这一步特别重要不要忘了,一定要翻倍的
e = e >> 1;
}
return exponent > 0 ? res : 1 / res;
}