Issue
I have always used INT_MAX
in C++
and I’m trying to find an easy way to do it in Golang
.
I did try INT_MAX
and uint32
but they didn’t work, and math.MaxInt
is lengthy as I’ll have to import math
library.
Solution
All such numeric constants are defined in the math package. Use math.MaxInt
https://pkg.go.dev/math@go1.18#pkg-constants
Importing a package is not the same as importing a library. You are only importing the names in that package. No function in math library will be included in the final binary unless you use them.
Answered By – Burak Serdar
Answer Checked By – Terry (GoLangFix Volunteer)