SirGod Posted August 20, 2015 Report Posted August 20, 2015 Ceva "magie" pentru pasionatii hack-urilor de genul. Daca vreti sa aflati ce face si cum functioneaza urmatoarea functie:float InvSqrt(float x) { float xhalf = 0.5 f * x; int i = * (int * ) & x; // get bits for floating value i = 0x5f3759df - (i >> 1); // gives initial guess y0 x = * (float * ) & i; // convert bits back to float x = x * (1.5 f - xhalf * x * x); // Newton step, repeating increases accuracy return x;}Puteti citi: http://www.lomont.org/Math/Papers/2003/InvSqrt.pdfhttps://en.wikipedia.org/wiki/Fast_inverse_square_root 1 Quote
Skalpel Posted August 21, 2015 Report Posted August 21, 2015 (edited) [REDACTED] Edited March 27, 2017 by Skalpel Quote
Active Members MrGrj Posted August 21, 2015 Active Members Report Posted August 21, 2015 (edited) float InvSqrt(float x) { float xhalf = 0.5 f * x; int i = * (int * ) & x; // get bits for floating value i = 0x5f3759df - (i >> 1); // gives initial guess y0 x = * (float * ) & i; // convert bits back to float x = x * (1.5 f - xhalf * x * x); // Newton step, repeating increases accuracy return x;}float xhalf =[COLOR="#FF0000"] 0.5 f[/COLOR] * x;Nu stiu de ce, dar am impresia ca nu compileaza in forma astaprogram.c:6:23: error: expected ‘,’ or ‘;’ before ‘f’ float xhalf = 0.5 f * x; ^program.c:10:18: error: expected ‘)’ before ‘f’ x = x * (1.5 f - xhalf * x * x); // Newton step, repeating increases accuracyPentru cei care sunt la inceput, ar trebui sa fie: 0.5f //fara spatiu Edited August 21, 2015 by MrGrj Quote