double PowerWithUnsignedExponent(double base, int exponent)
{
if (exponent == 0)
return 1;
if (exponent == 1)
return base;
double result = PowerWithUnsignedExponent(base, exponent >> 1);
result = result*result;
if (exponent & 0x1 == 1)
result = result * base;//若为奇数次方,最后一次递归经过这里
return result;
}
数值的整数次方
最新推荐文章于 2022-05-02 21:16:53 发布