Skip to content

Instantly share code, notes, and snippets.

@oldergod
Created September 13, 2014 04:27
Show Gist options
  • Select an option

  • Save oldergod/cbf2d8cec608e86d905e to your computer and use it in GitHub Desktop.

Select an option

Save oldergod/cbf2d8cec608e86d905e to your computer and use it in GitHub Desktop.
Tour of Go Complex Cube Roots
package main
import "fmt"
import "math/cmplx"
func Cbrt(x complex128, z complex128) complex128 {
for i := 0; i < 10; i++ {
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2))
}
return z
}
func main() {
var r complex128 = Cbrt(2, 1)
fmt.Println(r)
fmt.Println(cmplx.Pow(r, 3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment