Skip to content

Instantly share code, notes, and snippets.

@alq666
Created December 23, 2012 04:33
Show Gist options
  • Save alq666/4361984 to your computer and use it in GitHub Desktop.
Save alq666/4361984 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
const delta = 0.001
func Sqrt(x float64) float64 {
z := float64(1)
z1 := float64(0)
for math.Abs(z1 - z) > delta {
z1 = z
z = z1 - (z1*z1 - x) / (2*x)
}
return z
}
func main() {
fmt.Println(Sqrt(4))
fmt.Println(math.Sqrt(4))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment