Skip to content

Instantly share code, notes, and snippets.

@kaipakartik
Created December 25, 2013 01:18
Show Gist options
  • Save kaipakartik/8119359 to your computer and use it in GitHub Desktop.
Save kaipakartik/8119359 to your computer and use it in GitHub Desktop.
Advanced Exercise: Complex cube roots http://tour.golang.org/#48
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
z := complex128(1)
for i := 0; i < 10; i++ {
z = z - (z*z*z - x)/(3 * z *z)
}
return z
}
func main() {
fmt.Println(Cbrt(2 + 3i), cmplx.Pow(2.0 + 3i, 1.0/3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment