Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Last active August 29, 2015 13:56
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 guilleiguaran/8995532 to your computer and use it in GitHub Desktop.
Save guilleiguaran/8995532 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func abs(x float64) float64 {
if x > 0 {
return x
} else {
return -x
}
}
func Sqrt(x float64) float64 {
z := 1.0
for abs(x - z*z) > 0.000001 {
z = z-(z*z-x)/(2*z)
}
return z
}
func main() {
fmt.Println(Sqrt(9.0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment