最快的求一个数根号的倒数的方法


代码演示

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;
 }

文章作者: Axieyun
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Axieyun !
评论
评论
  目录