精简的 1/sqrt()函数:
float InvSqrt(float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x; // get bits for floating VALUE i = 0x5f375a86- (i>>1); // gives initial gue y0
x = *(float*)&i; // convert bits BACK to float x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
} return x;
《牛逼函数算法.doc》
将本文的Word文档下载到电脑,方便编辑。
推荐度:
点击下载文档