Skip to content

Instantly share code, notes, and snippets.

@laprasdrum
Created May 8, 2014 10:32
Show Gist options
  • Save laprasdrum/de5109a293cd52a4dd31 to your computer and use it in GitHub Desktop.
Save laprasdrum/de5109a293cd52a4dd31 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
var z complex128 = 1.0
for {
z = z - ((cmplx.Pow(z, 3.0)-x)/(3.0*cmplx.Pow(z, 2.0)))
fmt.Println(z, cmplx.Pow(z, 3.0))
if cmplx.Abs(x - cmplx.Pow(z, 3.0)) < 0.000000000001 {
break
}
}
return z
}
func main() {
fmt.Println(Cbrt(64))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment