Tag: 牛顿法

这个C成语是什么意思?

可能重复: John Carmack不寻常的快速反向平方根(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; } 做int i = *(int*)&x;的原因是什么int i = *(int*)&x; ? 做int i = (int) x; 相反,给出了完全不同的结果。

Newton Raphson迭代陷入无限循环

我是这个主题的初学者,并且找不到原因:有时程序有效,有时候没有(在提出问题之后,它根本不想接受我的答案,而不是我可以写作我想要它,它没有回应,只列出数字,我插入) #include float abszolut (float szam) { float abszoluterteke; if (szam >=0) abszoluterteke = szam; else abszoluterteke = -szam; return abszoluterteke; } float negyzetgyok (float szam) { float pontossag = 0.000001; float tipp = 1; if (szam = pontossag) tipp = (szam/tipp + tipp)/2; return tipp; } } int main (void) { float alap, eredmeny; […]