Yesterday, stormy weather, the temperature plummeted, all huddled in the warm thick clothes, no God staring at the monitor. I am no exception, trembling hands click on the mouse, while complaining about the weather, while blaming the computer. Suddenly, a piece of code came into view, looked intently, did not understand, the code is this:
floatQ_RSQRT (floatNumber ) { Longi; floatx2, y; Const floatThreehalfs =1.5F; X2= number *0.5F; Y=Number ; I= * (Long*) &y;//What's this TM?i =0X5F3759DF-(I >>1);//What is this TM?y = * (float*) &i;//What the hell is this TM ?y = y * (Threehalfs-(x2 * y * y));//this is .....//y = y * (Threehalfs-(x2 * y * y)); // ......... returny;}
This code from "Thor Hammer 3", seeking the reciprocal of the square root, the speed is claimed to be more radical than the usual, take the inverse of the calculation method four times times faster, I instant a leng, I do not know where the heat, wrapped my body, driving the cold, except the trembling, condensation in the heart of the only one idea: This TM is what.
Well, in fact, only one sentence is the key:
I 0x5f3759df1 ); // What is this TM?
The following will focus on the above sentence, but the article, to have the beginning of the end, good, when I did not say before, we start again:
A reciprocal algorithm for finding square root--salute to Carmack and others