double POW( double x, int y)
{
if(x==0) return 0;//if x is zero
if(y==0) return 1;//if y is zero
if(y==1) return x;
if(y<0) return 1.0 / POW(x, -y);//if y is negtive
double temp = POW(x, y>>1);
double res = temp * temp;
return y % 2 == 0 ? res : res * x; //if y is even
}
C语言二分法实现浮点数的整数幂次
最新推荐文章于 2022-11-11 22:29:16 发布