Skip to content

Instantly share code, notes, and snippets.

@timbogit
Created May 7, 2013 15:13
Show Gist options
  • Save timbogit/5533392 to your computer and use it in GitHub Desktop.
Save timbogit/5533392 to your computer and use it in GitHub Desktop.
Cubic Root exercise for Go lang tour
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
z := complex128(1)
for i := 0; i < 100; i++ {
z = z - ((cmplx.Pow(z, 3) - x) / (3 * z * z))
}
return z
}
func main() {
fmt.Println(Cbrt(8))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment