include<iostream> #include<cmath> using namespace std; 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 i/=2; i = 1597463174- i; x = *(float*)&i; // convert bits BACK to float x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy return 1/x; }
开方
猜你喜欢
转载自blog.csdn.net/d710055071/article/details/47053513
今日推荐
周排行