超级求平方根的方法

 

float SquareRootFloat(float number)
{
 long i;
 float x, y;
 const float f = 1.5F;
 x = number * 0.5F;
 y = number;
 i = * (long *) &y;
 i = 0x5f3759df - (i >> 1);//0x5f375a86 is more better than 0x5f3759df
 y = * (float *)&i;
 y = y * (f - (x * y * y));
 y = y * (f - (x * y * y));
 return number * y;
}

int main(int argc, char* argv[])
{
 float f1;
 scanf("%f", &f1);
 float f2 = SquareRootFloat(f1);
 return 0;
}

posted on 2007-09-11 11:49  highmayor  阅读(516)  评论(0编辑  收藏  举报

导航