ブックマーク / chopl.in (1)

  • A Tour of Goの解答 - still deeper

    Go Conference 2013 spring で A Tour of Go をやっているのでExcersiseの解答をメモ Goらしくかけているかは分からないのでコメント歓迎です #23 Loops and Functions package main import ( "fmt" "math" ) func Sqrt(x float64) float64 { z := 1.0 for diff := 1.0; math.Abs(diff) > 1e-10; { diff = ((math.Pow(z, 2) - x) / (2.0 * x)) z = z - diff } return z } func main() { fmt.Println(Sqrt(2)) fmt.Println(math.Sqrt(2)) } #35 Slices package main import "

    moutend
    moutend 2014/11/18
  • 1