Skip to content

Instantly share code, notes, and snippets.

@twr14152
Created September 22, 2019 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twr14152/9732600d19ad6c49b062d018f6732f70 to your computer and use it in GitHub Desktop.
Save twr14152/9732600d19ad6c49b062d018f6732f70 to your computer and use it in GitHub Desktop.
Tour_go_exercises
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
for i := 0; i < 10; i++ {
z -= (z * z-x) / (2 * z)
}
return z
}
func main() {
z := float64(16)
// check the math
fmt.Println(Sqrt(z), Sqrt(z) == math.Sqrt(z))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment