Last active
April 3, 2018 20:54
-
-
Save pinkmomo027/160ac2f05bff303977dab366fb4ea31c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Sqrt(x float64) float64 { | |
i := 1; | |
z := float64(1) | |
t := z - (z*z - x) / (2*z) | |
delta := 0.0000001 | |
for math.Abs(t-z) > delta { | |
z = t | |
t = z - (z*z - x) / (2*z) | |
fmt.Println(z) | |
i++; | |
} | |
fmt.Printf("%d times, answer is %f\n", i, t) | |
return t | |
} | |
func main() { | |
fmt.Println(Sqrt(2), Sqrt(2000000)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment