ryochack
1/9/2012 - 4:12 AM

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

/*
 * http://tour.golang.org/#48
 * OR
 * http://http://go-tour-jp.appspot.com/#47
 */

package main

import (
	"fmt"
	//"cmath"
)

func Cbrt(x complex128) complex128 {
	var z complex128 = 1.
	const cnt = 10

	for i:=0; i<cnt; i++ {
		z = z - ((z*z*z) - x) / (3*z*z)
	}

	return z
	//return cmath.Pow(x, 1/3.)
}

func main() {
	fmt.Println(Cbrt(2))
}