Sqrt In Go
package main
import "fmt"
func refineSqrt(x float64, sqrt float64) float64 {
return sqrt - (sqrt * sqrt - x) / (2 * sqrt)
}
func Sqrt(x float64) (sqrt float64) {
sqrt = x / 2
for {
if nextSqrt := refineSqrt(x, sqrt);
sqrt - nextSqrt < 0.0000000000001 {
return sqrt
} else {
sqrt = nextSqrt
}
}
}
func main() {
fmt.Println(Sqrt(2048.3 * 2048.3))
}