From feb3465accc7cf9a3a2f316d4f0fc64b50847e0f Mon Sep 17 00:00:00 2001 From: gelosie Date: Thu, 20 Sep 2012 14:59:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A01.2=E8=8A=82=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.2.md | 2 ++ src/1.2/main.go | 13 +++++++++++++ src/1.2/sqrt.go | 11 +++++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/1.2/main.go create mode 100644 src/1.2/sqrt.go diff --git a/1.2.md b/1.2.md index a9558458..3b16849f 100644 --- a/1.2.md +++ b/1.2.md @@ -2,6 +2,8 @@ ## GOPATH设置 go 命令依赖一个重要的环境变量:$GOPATH1 + + *(注:这个不是Go安装目录。下面以笔者的工作目录为说明,请替换自己机器上的工作目录。)* 在类似 Unix 环境大概这样设置: diff --git a/src/1.2/main.go b/src/1.2/main.go new file mode 100644 index 00000000..328acd54 --- /dev/null +++ b/src/1.2/main.go @@ -0,0 +1,13 @@ +// 章节 1.2 +// $GOPATH/src/mathapp/main.go + +package main + +import ( + "fmt" + "mymath" +) + +func main() { + fmt.Printf("Hello, world. Sqrt(2) = %v\n", mymath.Sqrt(2)) +} diff --git a/src/1.2/sqrt.go b/src/1.2/sqrt.go new file mode 100644 index 00000000..2fb5d8fc --- /dev/null +++ b/src/1.2/sqrt.go @@ -0,0 +1,11 @@ +// 章节 1.2 +// $GOPATH/src/mymath/sqrt.go +package mymath + +func Sqrt(x float64) float64 { + z := 0.0 + for i := 0; i < 1000; i++ { + z -= (z*z - x) / (2 * x) + } + return z +}