Skip to content

Instantly share code, notes, and snippets.

@bouzuya
Last active November 7, 2015 02:41
Show Gist options
  • Select an option

  • Save bouzuya/57af6fdc5b0caf80b0fe to your computer and use it in GitHub Desktop.

Select an option

Save bouzuya/57af6fdc5b0caf80b0fe to your computer and use it in GitHub Desktop.
package main
import "fmt"
import "math"
func Sqrt(x float64) float64 {
var z float64 = 1.0
for i := 0; i < 10; i++ {
z = z - (z*z-x)/(2*z)
}
return z
}
func main() {
for i := 1; i <= 10; i++ {
var x float64 = float64(i)
fmt.Println(x)
fmt.Println(" Sqrt:", Sqrt(x))
fmt.Println("math.Sqrt:", math.Sqrt(x))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment