- れんしゅうで作った
- 精度は、ほぼない
プログラム
オンラインコンパイラ
#include <iostream>
using namespace std;
int q_rsqrt(int number) {
long long i;
long long x2, y;
long long threehalfs;
x2 = number * 1000000 / 2;
y = number * 1000000;
threehalfs = 15 * 1000000 / 10;
printf("x2 = %lld\n",x2);
printf("y = %lld\n",y);
printf("threehalfs = %lld\n",threehalfs);
y = 304049 - (( 7812 * x2 )/1000000);
printf("y = %lld\n",y);
i = y * y / 1000000;
i = x2 * i / 1000000;
i = threehalfs - i;
y = y * i / 1000000;
printf("y = %lld\n",y);
//y = y * ( threehalfs - ( x2 * y * y ) );
return y;
}
int main(void){
// Your code here!
int in = 20;
int f;
f = q_rsqrt(in);
f = in * f;
printf("%d.%d",f / 1000000,f % 1000000 );
}
x2 = 10000000
y = 20000000
threehalfs = 1500000
y = 225929
y = 223572
4.471440