计算机算平方根用牛顿迭代。。。或者。。。下面这个fuck的方法
float InvSqrt(float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x; // get bits for floating VALUE
i = 0x5f375a86- (i>>1); // gives initial guess y0
x = *(float*)&i; // convert bits BACK to float
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
return x;
}
参考:一个sqrt函数引发的血案
XXXXXXXXXXXXXXXXXXXXXX/pkuoliver/archive/2010/10/06/XXXXXXXXXXXXXXXXXXXml
InvSqrt.pdf
147.71KB
PDF
65次下载
预览