https://groups.google.com/group/golang-nuts/msg/71c307e4d73024ce?pli=1

The germane part:

Since integer types use two's complement arithmetic, you can infer the min/max constant values for int and uint. For example,

const MaxUint = ^uint(0) 
const MinUint = 0 
const MaxInt = int(MaxUint >> 1) 
const MinInt = -MaxInt - 1

As per @CarelZA's comment:

uint8  : 0 to 255 
uint16 : 0 to 65535 
uint32 : 0 to 4294967295 
uint64 : 0 to 18446744073709551615 
int8   : -128 to 127 
int16  : -32768 to 32767 
int32  : -2147483648 to 2147483647 
int64  : -9223372036854775808 to 9223372036854775807
Answer from nmichaels on Stack Overflow
🌐
Go
go.dev › play › p › qeElniC-Nin
Go Playground - The Go Programming Language
Common problems companies solve with Go · Stories about how and why companies use Go
Discussions

Using minimum and maximum int64 limits leads to error
Problem statement A tool I am using is generating the following schema, which sets minimum and maximum limits for a parameter of type integer: "schema": { "maximum": 92233720368... More on github.com
🌐 github.com
8
April 11, 2022
go - Get maximum int64 value using 2's complement arithmetic golang - Stack Overflow
How to get maximum int64 value using 2's complement arithmetic in golang More on stackoverflow.com
🌐 stackoverflow.com
max int64 and uint64 handling
Problem statement Max int64 and uint64 seems to be wrong even if correct in the json schema definition go test -race ./... # github.com/opencontainers/image-spec/specsgo specsgo/int64_validator.go:... More on github.com
🌐 github.com
4
June 29, 2016
Writing a function that returns the max value of a type [~float64 | ~uint | ~int T]
Today I was trying to write a generic function to return the maximum value for floats, ints and uints. It seems… More on reddit.com
🌐 r/golang
11
23
March 17, 2024
🌐
Reddit
reddit.com › r/golang › writing a function that returns the max value of a type [~float64 | ~uint | ~int t]
r/golang on Reddit: Writing a function that returns the max value of a type [~float64 | ~uint | ~int T]
March 17, 2024 - r/golang · • 2y ago · rschio · Today I was trying to write a generic function to return the maximum value for floats, ints and uints. It seems straightforward, right? It's not! The function signature: type Types interface { ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uint | ~int | ~int64 | ~int32 | ~int16 | ~int8 | ~float64 | ~float32 } func infFor[T Types]() T ·
🌐
Leapcell
leapcell.io › blog › understanding-maximum-integer-values-in-go
Understanding Maximum Integer Values in Go | Leapcell
July 25, 2025 - In this example, incrementing the maximum int8 value (127) results in -128 due to overflow. Choose Appropriate Integer Types: Use integer types that suit the range of values you expect. For example, use int32 or int64 if you anticipate large numbers.
🌐
gosamples
gosamples.dev › tutorials › the maximum and minimum value of the int types in go
🍰 The maximum and minimum value of the int types in Go
April 14, 2022 - To get the maximum and minimum value of various integer types in Go, use the math package constants. For example, to get the minimum value of the int64 type, which is -9223372036854775808, use the math.MinInt64 constant. To get the maximum value of the int64 type, which is 9223372036854775807, ...
🌐
Rotational
rotational.io › blog › ranges-of-integer-data-types
Rotational Labs | Ranges of Integer Data Types
// Constants defined in the math package const ( MaxInt8 int8 = 1<<7 - 1 MinInt8 int8 = -1 << 7 MaxInt16 int16 = 1<<15 - 1 MinInt16 int16 = -1 << 15 MaxInt32 int32 = 1<<31 - 1 MinInt32 int32 = -1 << 31 MaxInt64 int64 = 1<<63 - 1 MinInt64 int64 ...
🌐
GitHub
github.com › go-swagger › go-swagger › issues › 2755
Using minimum and maximum int64 limits leads to error · Issue #2755 · go-swagger/go-swagger
April 11, 2022 - if err := validate.MinimumInt("limit", ...api_logs_parameters.go:95:60: cannot use -9.223372036854776e+18 (untyped float constant -9.22337e+18) as int64 value in argument to validate.MinimumInt (truncated) go/server/restapi/operati...
Author   avdv
🌐
YourBasic
yourbasic.org › golang › max-min-int-uint
Maximum value of an int · YourBasic Go
This code computes the limit values as untyped constants. const UintSize = 32 << (^uint(0) >> 32 & 1) // 32 or 64 const ( MaxInt = 1&lt;<(UintSize-1) - 1 // 1<<31 - 1 or 1<<63 - 1 MinInt = -MaxInt - 1 // -1 << 31 or -1 << 63 MaxUint = 1<<UintSize - 1 // 1<<32 - 1 or 1<<64 - 1 ) The UintSize constant is also available in package math/bits. ... Go blueprints: code for com­mon tasks is a collection of handy code examples. Pick the right one: int vs. int64
Find elsewhere
🌐
Educative
educative.io › answers › what-is-type-int64-in-golang
What is type int64 in Golang?
However, just incrementing it by 1 pushed it out of the allowed range, which resulted in the stored value being interpreted as -9223372036854775808 when printed again. When this happens, we call it an overflow.
🌐
IncludeHelp
includehelp.com › golang › math-maxuint64-constant-with-examples.aspx
Golang math.MaxUint64 Constant with Examples
The return type of math.MaxUint64 constant is int, it returns the highest (maximum) value that can be represented by a uint64. // Golang program to demonstrate the // example of math.MaxUint64 Constant package main import ( "fmt" "math" ) func main() { fmt.Printf("Type of math.MaxUint64 is ...
🌐
Google Groups
groups.google.com › g › golang-nuts › c › a9PitPAHSSU › m › ziQw1-QHw3EJ
[go-nuts] MAX/MIN NUMBER of each integer type
On Apr 16, 12:26 pm, peterGo <go.peter...@gmail.com> wrote: > Daniel > > On Apr 16, 12:12 pm, Ostsol <ost...@gmail.com> wrote: > > > int64, for > > example, has a maximum of 2^32 - 1. > > MaxInt64 = 1<<63 - 1 = 2^64 - 1 > > Peter ... Either email addresses are anonymous for this group or you ...
🌐
ZetCode
zetcode.com › golang › builtins-int64-type
Understanding the int64 Type in Golang
package main import "fmt" func main() { var a int64 = 9223372036854775807 // Maximum int64 value var b int64 = -9223372036854775808 // Minimum int64 value c := int64(42) // Type conversion from untyped constant fmt.Println("a:", a) fmt.Println("b:", b) fmt.Println("c:", c) }
🌐
YourBasic
yourbasic.org › golang › int-vs-int64
Pick the right one: int vs. int64 · YourBasic Go
func Max(a []int64) int64 { max := a[0] for i := 1; i < len(a); i++ { if max < a[i] { max = a[i] } } return max }
🌐
YourBasic
yourbasic.org › golang › max-min-function
Compute max of two ints/floats · YourBasic Go
yourbasic.org/golang · There is no built-in max or min function for integers, but it’s simple to write your own. // Max returns the larger of x or y. func Max(x, y int64) int64 { if x < y { return y } return x } // Min returns the smaller ...
🌐
Go Packages
pkg.go.dev › builtin
builtin - Go Packages - Golang
If T is a floating-point type and any of the arguments are NaNs, max will return NaN. ... The min built-in function returns the smallest value of a fixed number of arguments of cmp.Ordered types. There must be at least one argument.
🌐
Gophersnippets
gophersnippets.com › what-is-the-maximum-value-of-numeric-types
What is the maximum value of numeric types - GopherSnippets.com
package main import ( "fmt" "math" ... fmt.Println("Max float32:", math.MaxFloat32) fmt.Println("Max float64:", math.MaxFloat64) // Output: // Max int8: 127 // Max int16: 32767 // Max int32: 2147483647 // Max int64: 9223372036854775807 // Max uint8: 255 // Max uint16: 65535 ...
🌐
Stack Overflow
stackoverflow.com › questions › 77281192 › get-maximum-int64-value-using-2s-complement-arithmetic-golang
go - Get maximum int64 value using 2's complement arithmetic golang - Stack Overflow
... Recommended read: <go.dev/blog/constants>. It deals with a more interesting case and also explains how to work with bit shifts when dealing with constants. ... Found: const MaxInt64 := int64(^uint64(0) >> 1) or const MaxInt64 = 1<<63 - 1, also ...
🌐
GitHub
gist.github.com › petergloor › 1eacd3ebcfc3e09ed578dd0d4f80cabe
MaxInt, MinInt, MaxUint and MinUint in Go (golang) · GitHub
April 11, 2022 - package main import "fmt" import "math" const maxUint = uint(math.MaxUint) func main() { fmt.Println("Integer range on your system") // .Println("MaxUint:", math.MaxUint) ERROR constant 18446744073709551615 overflows int fmt.Println("MaxUint:", maxUint) fmt.Println("MinInt:", math.MinInt) fmt.Println("MaxInt:", math.MaxInt) }
🌐
GitHub
github.com › go-swagger › go-swagger › issues › 581
max int64 and uint64 handling · Issue #581 · go-swagger/go-swagger
June 29, 2016 - "int64": { 20 "type": "integer", 21 "minimum": -9223372036854775808, 22 "maximum": 9223372036854775807 23 },
Author   runcom