Skip to content

Instantly share code, notes, and snippets.

@kei-s
Created July 14, 2014 10:54
Show Gist options
  • Save kei-s/7991ec6e9e7af998c3d6 to your computer and use it in GitHub Desktop.
Save kei-s/7991ec6e9e7af998c3d6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
for {
zz := z - ((z*z - x)/(2*x))
if math.Abs(z - zz) < 0.0000001 {
return z
}
z = zz
}
return z
}
func main() {
const i = 2
fmt.Println(Sqrt(i))
fmt.Println(math.Sqrt(i))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment