The maximum value for an int type in Go

前端 未结 10 1149
无人共我
无人共我 2021-01-29 19:09

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

10条回答
  •  野性不改
    2021-01-29 19:30

    One way to solve this problem is to get the starting points from the values themselves:

    var minLen, maxLen uint
    if len(sliceOfThings) > 0 {
      minLen = sliceOfThings[0].minLen
      maxLen = sliceOfThings[0].maxLen
      for _, thing := range sliceOfThings[1:] {
        if minLen > thing.minLen { minLen = thing.minLen }
        if maxLen < thing.maxLen { maxLen = thing.maxLen }
      }
    }
    

提交回复
热议问题