本帖最后由 liang7143 于 2012-7-14 15:55 编辑
呵呵,给LZ看一看一个更晕的函数
求平方根的倒数,等同于1/sqrt(x)
float InvSqrt(float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x; // get bits for floating value
i = 0x5f3759df - (i>>1); // gives initial guess
x = *(float*)&i; // convert bits back to float
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
return x;
}
详细资料可以看附件 |