Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(850)

Side by Side Diff: gotour/solutions/loops.go

Issue 6589070: code review 6589070: go-tour: add copyright notices (Closed)
Patch Set: diff -r bb8e3b14b929 https://code.google.com/p/go-tour Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gotour/solutions/image.go ('k') | gotour/solutions/maps.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
1 package main 5 package main
2 6
3 import ( 7 import (
4 "fmt" 8 "fmt"
5 "math" 9 "math"
6 ) 10 )
7 11
8 const delta = 1e-10 12 const delta = 1e-10
9 13
10 func Sqrt(x float64) float64 { 14 func Sqrt(x float64) float64 {
11 z := x 15 z := x
12 for { 16 for {
13 n := z - (z*z-x)/(2*z) 17 n := z - (z*z-x)/(2*z)
14 if math.Abs(n-z) < delta { 18 if math.Abs(n-z) < delta {
15 break 19 break
16 } 20 }
17 z = n 21 z = n
18 } 22 }
19 return z 23 return z
20 } 24 }
21 25
22 func main() { 26 func main() {
23 const x = 2 27 const x = 2
24 mine, theirs := Sqrt(x), math.Sqrt(x) 28 mine, theirs := Sqrt(x), math.Sqrt(x)
25 fmt.Println(mine, theirs, mine-theirs) 29 fmt.Println(mine, theirs, mine-theirs)
26 } 30 }
OLDNEW
« no previous file with comments | « gotour/solutions/image.go ('k') | gotour/solutions/maps.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b