Skip to content

Instantly share code, notes, and snippets.

@zgiber
zgiber / cbrt.go
Last active December 10, 2015 16:48
A Tour of Go. Advanced Exercise: Complex cube roots.
package main
import (
"fmt"
"math"
)
func Cbrt(x complex128) complex128 {
next := func(z complex128) (complex128, float64) { //takes the result of the last iteration, and returns new result and difference
newz := z - (((z * z * z) - x) / (3 * (z * z)))