虽然写不出这么牛逼的函数,但是读过这么牛逼的函数,所以来小白的博客还是会有收获的。
下面就是函数代码,还没研究,先贴上来。
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
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
return 1/x;
}
下面是这位牛人的博客,敬仰ing
http://blog.redfox66.com/?tag=/算法