相关疑难解决方法(0)

这个C成语是什么意思?

可能重复:
约翰卡马克不寻常的快速反向平方根(Quake III)

我最近在博客上看到了这段代码 - 它来自Quake3引擎.它意味着使用Newton-Rhapson方法快速计算平方根.

float InvSqrt (float x){
    float xhalf = 0.5f*x;
    int i = *(int*)&x;
    i = 0x5f3759df - (i>>1);
    x = *(float*)&i;
    x = x*(1.5f - xhalf*x*x);
    return x;
}
Run Code Online (Sandbox Code Playgroud)

这样做的原因是什么int i = *(int*)&x;?这样做int i = (int) x;,而不是给出一个完全不同的结果.

c math floating-point newtons-method

-1
推荐指数
2
解决办法
604
查看次数

标签 统计

c ×1

floating-point ×1

math ×1

newtons-method ×1