A Tour of Goのコードにfmt.Printlnを追加したものなのですが、思っていた結果と違う結果になりました。なぜこのような結果になるのでしょうか?
go
1package main 2 3import ( 4 "fmt" 5 "math" 6) 7 8func pow(x, n, lim float64) float64 { 9 fmt.Printf("start\n") 10 if v := math.Pow(x, n); v < lim { 11 return v 12 } else { 13 fmt.Printf("%g >= %g\n", v, lim) 14 } 15 // can't use v here, though 16 return lim 17} 18 19func main() { 20 fmt.Println( 21 pow(3, 2, 10), 22 pow(3, 3, 20), 23 ) 24}
期待
shell
1start 29 3start 427 >= 20 520
結果
shell
1start 2start 327 >= 20 49 20
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/16 09:27
2016/12/16 09:29