Skip to content

Instantly share code, notes, and snippets.

@siisee11
Last active December 11, 2019 11:12
Show Gist options
  • Save siisee11/8ee92a778906747dd7559e0f22ed34eb to your computer and use it in GitHub Desktop.
Save siisee11/8ee92a778906747dd7559e0f22ed34eb to your computer and use it in GitHub Desktop.
Complex cube roots
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
var z complex128 = 1
for i := 0 ; i < 50 ; i++ {
z = z - (z * z * z - x) / (3 * z * z)
}
return z
}
func main() {
fmt.Println(Cbrt(2))
fmt.Println(cmplx.Pow(Cbrt(2), 3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment