Last active
October 10, 2017 12:59
-
-
Save phigasui/4157832b747195ee232bd146d29cd5d3 to your computer and use it in GitHub Desktop.
A Tour of Go: https://go-tour-jp.appspot.com/flowcontrol/8
This file contains 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" | |
) | |
func Sqrt(x float64) (i float64, z float64, loop_count int, err float64) { | |
z = x | |
i = x | |
loop_count = 0 | |
var diff float64; | |
for { | |
diff = (z * z - x) / (2.0 * z) | |
if diff <= 1 / (20 ^ 9) { | |
err = math.Sqrt(x) - z | |
return | |
} | |
z -= diff | |
loop_count++ | |
} | |
} | |
func main() { | |
for i:=10;i<13;i++ { | |
fmt.Println(Sqrt(float64(i))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment