Skip to content

Instantly share code, notes, and snippets.

@kakkun61
Last active December 19, 2015 15:09
Show Gist options
  • Save kakkun61/5974679 to your computer and use it in GitHub Desktop.
Save kakkun61/5974679 to your computer and use it in GitHub Desktop.
My incomplete answer for http://go-tour-jp.appspot.com/#47
// ! incomplete
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
var z complex128 = 1
for i := 0; i < 10; i++ {
z = z - (cmplx.Pow(z, 3) - x)/(3 * cmplx.Pow(z, 2))
}
return z
}
func main() {
fmt.Println(Cbrt(2))
fmt.Println(cmplx.Pow(2, 1/3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment