Last active
August 29, 2015 13:58
-
-
Save parasj/10332914 to your computer and use it in GitHub Desktop.
Learning Go
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
http://tour.golang.org |
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" | |
) | |
func Sqrt(x float64) float64 { | |
z := 1.0 | |
delta := 1.0 | |
const delta_lim float64 = .000001 | |
for delta > delta_lim || delta < -1*delta_lim { | |
delta = z | |
z = z - (z*z-x)/(2*z) | |
delta = z - delta | |
} | |
return z | |
} | |
func main() { | |
fmt.Println(Sqrt(2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment