Skip to content

Instantly share code, notes, and snippets.

@eckorog2005
Created May 6, 2013 01:11
Show Gist options
  • Select an option

  • Save eckorog2005/5522817 to your computer and use it in GitHub Desktop.

Select an option

Save eckorog2005/5522817 to your computer and use it in GitHub Desktop.
sample exerise
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(1);
old := float64(3);
delta := float64(.00000001);
for math.Abs(old - z) > delta {
old = z;
z = z - ((z*z - x)/(2*z));
}
return z;
}
func main() {
fmt.Println(Sqrt(1))
fmt.Println(Sqrt(2))
fmt.Println(Sqrt(3))
fmt.Println(Sqrt(4))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment