超级求平方根的方法

 

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;
}

你可能感兴趣的:(方法)