Skip to content

Instantly share code, notes, and snippets.

@ksomemo
Created July 17, 2014 04:23
Show Gist options
  • Save ksomemo/cf3036f4ae2d151453ad to your computer and use it in GitHub Desktop.
Save ksomemo/cf3036f4ae2d151453ad to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
z := complex128(1.0)
for i := 0; i < 10000; i++ {
z = z - (z*z*z-x)/(3*z*z)
}
return z
}
func main() {
fmt.Println(Cbrt(2))
fmt.Println(cmplx.Pow(2, 1./3.))
}
(1.2599210498948732+0i)
(1.259921049894873+0i)
Program exited.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment