Skip to content

Instantly share code, notes, and snippets.

@suzuken
Created January 8, 2014 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzuken/8315708 to your computer and use it in GitHub Desktop.
Save suzuken/8315708 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(1)
for i := 0; ; i++ {
z1 := z
z = z - (z * z - x) / 2 * z
if math.Abs(z - z1) <= 0.001 {
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