Last active
August 30, 2015 14:28
-
-
Save jabrena/b1c0a6fd33bfc3959907 to your computer and use it in GitHub Desktop.
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) float64 { | |
z := 1.0 | |
for i := 0; i < 10; i++ { | |
z -= (math.Pow(z, 2) - x) / (2 * z) | |
} | |
return z | |
} | |
func main() { | |
for i := 0.0; i < 10; i++ { | |
if v := Sqrt(i) - math.Sqrt(i); v < 0.001{ | |
fmt.Println("Lo gozo") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testing Go with Newton method to calculate the Square root:
https://en.wikipedia.org/wiki/Methods_of_computing_square_roots
for the problem:
https://tour.golang.org/flowcontrol/8