Efficient function implementation for solving the reciprocal of square root

Source: Internet
Author: User
Tags float number
/*** Float q_rsqrt (float number) */float q_rsqrt (float number) {long I; float X2, Y; const float threehalfs = 1.5f; x2 = Number * 0.5f; y = number; I = * (long *) & Y; // edevil floating point bit level hackingi = 0x5f3759df-(I> 1); // What the fuck? Y = * (float *) & I; y = y * (threehalfs-(X2 * y )); // 1st iteration // y = y * (threehalfs-(X2 * y); // 2nd iteration, this can be removed # ifdef _ Linux _ assert (! Isnan (y); // bk010122-FPE? # Endifreturn y ;}

 

Efficient function implementation for solving the reciprocal of square root

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.