The maximum value for an int type in Go

How does one specify the maximum value representable for an unsigned integer type?

I would like to know how to initialize min in the loop below that iteratively computes min and max lengths from some structs.

var minLen uint = ???
var maxLen uint = 0
for _, thing := range sliceOfThings {
  if minLen > thing.n { minLen = thing.n }
  if maxLen < thing.n { maxLen = thing.n }
}
if minLen > maxLen {
  // If there are no values, clamp min at 0 so that min <= max.
  minLen = 0
}

so that the first time through the comparison, minLen >= n.

13 Answers
13

Leave a Comment