The way to implement SQRT in go language _golang

Source: Internet
Author: User

This article illustrates the way the go language implements sqrt. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:
Package MyMath
Import "Math"
Func invsqrt (x float32) float32 {
var xhalf float32 = 0.5*x//Get bits for floating VALUE
I: = Math. Float32bits (x)//gives initial guess y0
i = 0x5f375a86-(i>>1)//convert bits back to float
x = Math. Float32frombits (i)//Newton step, repeating increases accuracy
x = x* (1.5-xhalf*x*x)
x = x* (1.5-xhalf*x*x)
x = x* (1.5-xhalf*x*x)
Return 1/x
}

I hope this article will help you with your go language program.

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.