Skip to content

Instantly share code, notes, and snippets.

@SatoTakeshiX
Created February 13, 2018 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SatoTakeshiX/04b02d53d07c454a0e327e3916ad3524 to your computer and use it in GitHub Desktop.
Save SatoTakeshiX/04b02d53d07c454a0e327e3916ad3524 to your computer and use it in GitHub Desktop.
定義を上からしなくてもよい。Smallでしたの方に定義したBit定数を使える #read_go #CodePiece
package main
import "fmt"
const (
// Shift it right again 99 places, so we end up with 1<<1, or 2.
Small = Big >> 99
// Create a huge number by shifting a 1 bit left 100 places.
// In other words, the binary number that is 1 followed by 100 zeroes.
Big = 1 << 100
)
func needInt(x int) int { return x*10 + 1 }
func needFloat(x float64) float64 {
return x * 0.1
}
func main() {
fmt.Println(needInt(Small))
fmt.Println(needFloat(Small))
fmt.Println(needFloat(Big))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment