github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xmath/compare.go (about) 1 package xmath 2 3 func CompareUint64(a, b uint64, max bool) uint64 { 4 if max { 5 if a > b { 6 return a 7 } 8 return b 9 } else { 10 if a > b { 11 return b 12 } 13 return a 14 } 15 } 16 17 func CompareUint32(a, b uint32, max bool) uint32 { 18 return uint32(CompareUint64(uint64(a), uint64(b), max)) 19 } 20 21 func CompareUint16(a, b uint16, max bool) uint16 { 22 return uint16(CompareUint64(uint64(a), uint64(b), max)) 23 } 24 25 func CompareUint8(a, b uint8, max bool) uint8 { 26 return uint8(CompareUint64(uint64(a), uint64(b), max)) 27 } 28 29 func CompareUint(a, b uint, max bool) uint { 30 return uint(CompareUint64(uint64(a), uint64(b), max)) 31 } 32 33 func CompareInt64(a, b int64, max bool) int64 { 34 if max { 35 if a > b { 36 return a 37 } 38 return b 39 } else { 40 if a > b { 41 return b 42 } 43 return a 44 } 45 } 46 47 func CompareInt32(a, b int32, max bool) int32 { 48 return int32(CompareInt64(int64(a), int64(b), max)) 49 } 50 51 func CompareInt16(a, b int16, max bool) int16 { 52 return int16(CompareInt64(int64(a), int64(b), max)) 53 } 54 55 func CompareInt8(a, b int8, max bool) int8 { 56 return int8(CompareInt64(int64(a), int64(b), max)) 57 } 58 59 func CompareInt(a, b int, max bool) int { 60 return int(CompareInt64(int64(a), int64(b), max)) 61 }