#include #include struct valores{ float termo; // i-esimo termo double invsqrt; // valor calculado via InvSqrt double mathsqrt; // valor calculado via 1/Math.sqrt(x) double delta; // abs(invsqrt - mathsqrt), erro entre a aproximacao e o valor real } typedef Valores; const int QUANTIDADETESTADA = 100000; union casting { int i; float f; }; float InvSqrt (float x) { union casting cast; float xhalf = 0.5f*x; cast.f = x; // int i = *(int*)&x; cast.i = 0x5f3759df - ((cast.i)>>1); // x = *(float*)&i; return cast.f*(1.5f - xhalf*cast.f*cast.f); // x = x*(1.5f - xhalf*x*x); } int main(void){ Valores vars[QUANTIDADETESTADA]; float termos = 0.f; for(int i=0; i