golang在两个uint值上使用math.max的正确方法是什么?

golang在两个uint值上使用math.max的正确方法是什么?

问题描述:

This is what I do, it is extremely ugly.

What is the right way to use math.Max for 2 uint s?

vs.curView.Viewnum =uint(math.Max(float64(args.Viewnum+1), float64(vs.curView.Viewnum)))

这是我所做的,非常丑陋。 p>

什么是 正确的方法将 math.Max code>用于2个uint? p>

  vs.curView.Viewnum = uint(math.Max(float64(args。  Viewnum + 1),float64(vs.curView.Viewnum)))
  code>  pre> 
  div>

The main reason math.Max exists is to ensure some of the special cases of IEEE floating point are handled correctly (positive and negative infinity, NaN and signed zeroes).

These issues are not relevant for simple integers, so you may as well just use the obvious implementation. Something like:

if args.Viewnum+1 > vs.curView.Viewnum {
    vs.curView.Viewnum = args.Viewnum+1
}