A reciprocal algorithm for finding square root--salute to Carmack and others

Source: Internet
Author: User
Tags square root

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.