ryochack
1/9/2012 - 4:07 AM

"A Tour of Go" http://tour.golang.org/#44

/*
 * http://tour.golang.org/#44
 * OR
 * http://http://go-tour-jp.appspot.com/#43
 */

package main

import (
	"fmt"
	"math"
)

func Sqrt(x float64) float64 {
	z := float64(0)
	const maxloopcnt = 50
	for i:=0; i<maxloopcnt; i++ { 
		z = z - ((z*z) - x)/(2*x)
	}
	return z
}

func main() {
	fmt.Println(Sqrt(2))
	fmt.Println(math.Sqrt(2))
}