osada-chan

Rails メインでサーバーサイドエンジニアしつつ現場監督やってます

A Tour of Go 16

16ページ目

package main

import "fmt"

const (
  Big   = 1 << 100
  Small = Big >> 99
)

func needInt(x int) int { return x * 10 + 1 }
func needFloat(x float64) float64 {
  return x * 0.1
}

func main() {
  fmt.Println("Aboud Samll")
  fmt.Println(needInt(Small))
  fmt.Println(needFloat(Small))

  fmt.Println("Aboud Big")
  // fmt.Println(needInt(Big))
  fmt.Println(needFloat(Big))
}


数値定数は高精度な値らしい。よく分からん。

例で needInt(Big) を出力してみてください。

はい。

実行結果

go run tour16.go
# command-line-arguments
.\tour16.go:21: constant 1267650600228229401496703205376 overflows int

オーバーフローしました。さて。