Skip to content

Instantly share code, notes, and snippets.

@jabrena
Last active August 30, 2015 14:28
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 jabrena/b1c0a6fd33bfc3959907 to your computer and use it in GitHub Desktop.
Save jabrena/b1c0a6fd33bfc3959907 to your computer and use it in GitHub Desktop.
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")
}
}
}
@jabrena
Copy link
Author

jabrena commented Aug 30, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment