Created
December 23, 2012 04:33
-
-
Save alq666/4361984 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
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