Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

golang what is the right way to use math.max on two uint values?

Tags:

go

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)))
like image 583
BufBills Avatar asked Jan 29 '15 04:01

BufBills


1 Answers

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
}
like image 55
James Henstridge Avatar answered Nov 09 '22 02:11

James Henstridge