Skip to content

Instantly share code, notes, and snippets.

@tae0y
Created May 11, 2019 13:20
Show Gist options
  • Save tae0y/39874454c6b9f2817ecf2efb07d19c8f to your computer and use it in GitHub Desktop.
Save tae0y/39874454c6b9f2817ecf2efb07d19c8f to your computer and use it in GitHub Desktop.
gotour complex pow
package main
import(
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
t := x
for idx:=0; idx<1000; idx++ {
x = x - (x*x*x-t)/(3*x*x)
}
return x
}
func main() {
input := complex(8, 0)
fmt.Println(Cbrt(input))
fmt.Println(cmplx.Pow(Cbrt(input),complex(3,0)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment