Skip to content

Instantly share code, notes, and snippets.

@slawosz
Last active December 18, 2015 04:28
Show Gist options
  • Save slawosz/5725209 to your computer and use it in GitHub Desktop.
Save slawosz/5725209 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := x
delta := 0.00000000001
notDone := true
fmt.Println("foo")
for notDone {
res := z - ((z*z) - x)/(2*z)
fmt.Println(res)
if math.Abs(res - z) < delta {
notDone = false
}
z = res
}
return z
}
func main() {
fmt.Println(Sqrt(2))
fmt.Println("--",math.Sqrt(2))
}
// http://tour.golang.org/#26
package main
import "fmt"
type Vertex struct {
X int
Y int
}
func main() {
p := Vertex{1, 2}
// struct is copied
q := p
q.X = 1e9
fmt.Println(p)
fmt.Println(q)
// q2 points to struct p
q2 := &p
q2.X = 1e9
fmt.Println(p)
}
@slawosz
Copy link
Author

slawosz commented Jun 6, 2013

@slawosz
Copy link
Author

slawosz commented Jun 7, 2013

http://tour.golang.org/#28 provides knowledge about pointers to structs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment