控制工程学习吧 关注:4贴子:70
  • 0回复贴,共1

平方根倒数速算法--算法神奇。值得一看

只看楼主收藏回复

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 y0 (神奇的数字!)
x = *(float*)&i; // convert bits back to float
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
return x;
}


IP属地:山东1楼2016-08-11 20:43回复