Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created November 7, 2013 11:55
Show Gist options
  • Save hitode909/7353436 to your computer and use it in GitHub Desktop.
Save hitode909/7353436 to your computer and use it in GitHub Desktop.
ニュートン法 http://tour.golang.org/#24
package main
import (
"fmt"
)
func Sqrt(x float64) float64 {
return _sqrt(x, 0, 10);
}
func _sqrt(x float64, z float64, i int) float64 {
if (i > 0) {
return _sqrt(x, z-(z*z-x)/(x*2), i-1)
} else {
return z
}
}
func main() {
fmt.Println(Sqrt(2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment