Created
July 17, 2014 04:23
-
-
Save ksomemo/cf3036f4ae2d151453ad to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"math/cmplx" | |
) | |
func Cbrt(x complex128) complex128 { | |
z := complex128(1.0) | |
for i := 0; i < 10000; i++ { | |
z = z - (z*z*z-x)/(3*z*z) | |
} | |
return z | |
} | |
func main() { | |
fmt.Println(Cbrt(2)) | |
fmt.Println(cmplx.Pow(2, 1./3.)) | |
} |
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
(1.2599210498948732+0i) | |
(1.259921049894873+0i) | |
Program exited. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment