Created
May 8, 2014 10:32
-
-
Save laprasdrum/de5109a293cd52a4dd31 to your computer and use it in GitHub Desktop.
ʕ◔ϖ◔ʔ
From http://go-tour-jp.appspot.com/#48
This file contains 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 { | |
var z complex128 = 1.0 | |
for { | |
z = z - ((cmplx.Pow(z, 3.0)-x)/(3.0*cmplx.Pow(z, 2.0))) | |
fmt.Println(z, cmplx.Pow(z, 3.0)) | |
if cmplx.Abs(x - cmplx.Pow(z, 3.0)) < 0.000000000001 { | |
break | |
} | |
} | |
return z | |
} | |
func main() { | |
fmt.Println(Cbrt(64)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment