Skip to content

Instantly share code, notes, and snippets.

@ryochack
Created January 9, 2012 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryochack/1581026 to your computer and use it in GitHub Desktop.
Save ryochack/1581026 to your computer and use it in GitHub Desktop.
/*
* 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))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment