Delta Between Two Patch Sets: gotour/solutions/complexcube.go
Issue 6585074 :
code review 6585074: golang-tour: Solutions to the exercises. (Closed)
Left Patch Set:
Right Patch Set: diff -r 4914aa37f57f https://code.google.com/p/go-tour
Use n/p to move between diff chunks;
N/P to move between comments.
Please Sign in to add in-line comments.
Jump to:
gotour/solutions/README
gotour/solutions/binarytrees.go
gotour/solutions/complexcube.go
gotour/solutions/errors.go
gotour/solutions/fib.go
gotour/solutions/image.go
gotour/solutions/loops.go
gotour/solutions/maps.go
gotour/solutions/rot13.go
gotour/solutions/slices.go
gotour/solutions/webcrawler.go
LEFT RIGHT
(no file at all) 1 package main
2
3 import (
4 "fmt"
5 "math/cmplx"
6 )
7
8 const delta = 1e-10
9
10 func Cbrt(x complex128) complex128 {
11 z := x
12 for {
13 n := z - (z*z*z-x)/(3*z*z)
14 if cmplx.Abs(n-z) < delta {
15 break
16 }
17 z = n
18 }
19 return z
20 }
21
22 func main() {
23 const x = 2
24 mine, theirs := Cbrt(x), cmplx.Pow(x, 1./3.)
25 fmt.Println(mine, theirs, mine-theirs)
26 }
LEFT RIGHT