Skip to content

Instantly share code, notes, and snippets.

@suisho
Created April 29, 2013 05:13
Show Gist options
  • Save suisho/5479828 to your computer and use it in GitHub Desktop.
Save suisho/5479828 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func newton(x, z float64) float64{
return z - ((math.Pow(z , 2) - x)/ (2 * z))
}
func Sqrt(x float64) float64 {
var z = x
for i := 0; i < 10000000; i++ {
z = newton(x,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