Skip to content

Instantly share code, notes, and snippets.

@alq666
Created December 26, 2012 00:31
Show Gist options
  • Save alq666/4376775 to your computer and use it in GitHub Desktop.
Save alq666/4376775 to your computer and use it in GitHub Desktop.
package main
import "fmt"
import "math/cmplx"
const d float64 = 0.0001
func Cbrt(x complex128) complex128 {
z0, z := complex128(0), complex128(1)
for cmplx.Abs(z - z0) > d {
z0, z = z, z - (z*z*z - x)/(3*z*z)
}
return z
}
func main() {
fmt.Println(Cbrt(2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment