Skip to content

Instantly share code, notes, and snippets.

@kei-s
Created September 25, 2014 10:48
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 kei-s/2d4f47f9c5ffee6a5e48 to your computer and use it in GitHub Desktop.
Save kei-s/2d4f47f9c5ffee6a5e48 to your computer and use it in GitHub Desktop.
package main
import "fmt"
import "math/cmplx"
func Cbrt(x complex128) complex128 {
z := 1 + 0i
for {
zz := z - ((z * z * z - x) / (3 * z * z))
if cmplx.Abs(z-zz) < 0.0000001 {
return z
}
z = zz
}
return z
}
func main() {
fmt.Println(Cbrt(2))
fmt.Println(cmplx.Pow(Cbrt(2), 3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment