Maximum value of an int

yourbasic.org/golang

Go has two predeclared integer types with implementation-specific sizes:

This code computes the limit values as untyped constants.

const BitsPerWord = 32 << (^uint(0) >> 63) // either 32 or 64

const (
    MaxInt  = 1<<(BitsPerWord-1) - 1 // either 1<<31 - 1 or 1<<63 - 1
    MinInt  = -MaxInt - 1            // either -1 << 31 or -1 << 63
    MaxUint = 1<<BitsPerWord - 1     // either 1<<32 - 1 or 1<<64 - 1
)

More code examples

Go blueprints: code for com­mon tasks is a collection of handy code examples.

Share this page: