Last active
December 19, 2015 15:09
-
-
Save kakkun61/5974679 to your computer and use it in GitHub Desktop.
My incomplete answer for http://go-tour-jp.appspot.com/#47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ! incomplete | |
package main | |
import ( | |
"fmt" | |
"math/cmplx" | |
) | |
func Cbrt(x complex128) complex128 { | |
var z complex128 = 1 | |
for i := 0; i < 10; i++ { | |
z = z - (cmplx.Pow(z, 3) - x)/(3 * cmplx.Pow(z, 2)) | |
} | |
return z | |
} | |
func main() { | |
fmt.Println(Cbrt(2)) | |
fmt.Println(cmplx.Pow(2, 1/3)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment