Skip to content

Instantly share code, notes, and snippets.

@tmtk75
Created July 9, 2013 22:00
Show Gist options
  • Select an option

  • Save tmtk75/5961680 to your computer and use it in GitHub Desktop.

Select an option

Save tmtk75/5961680 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
z := complex(1, 0)
for i := 0; i < 10; 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