Skip to content

Instantly share code, notes, and snippets.

@shaneharter

shaneharter/sqrt.go

Created May 13, 2013
Embed
What would you like to do?
Gotour: Newtonian square roots in Go
package main
import (
"fmt"
"math"
)
const min_delta = 0.000000000001
func Sqrt(x float64) float64 {
z := 0.0
for value := 1.0; math.Abs(value-z) > min_delta; {
z = value
value = z - (z*z-x)/(2*z)
}
return z
}
func main() {
fmt.Println(Sqrt(34500000))
fmt.Println("---")
fmt.Println(math.Sqrt(34500000))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.