Skip to content

Instantly share code, notes, and snippets.

@MokkeMeguru
Created May 18, 2020 12:36
Show Gist options
  • Save MokkeMeguru/a939e839bfada2d444c210026d9e31ee to your computer and use it in GitHub Desktop.
Save MokkeMeguru/a939e839bfada2d444c210026d9e31ee to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
var z = 1.0
for {
if math.Abs(z*z-x) < 1e-8 {
break
}
z = (z*z - x) / (2 * z)
}
return z
}
func main() {
fmt.Println(Sqrt(2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment