github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/emath/math_minmax.go (about) 1 package emath 2 3 // MinInt find and return the minimum item from the specified int 4 func MinInt(nums ...int) int { 5 var ret = nums[0] 6 for i, l := 1, len(nums); i < l; i++ { 7 if ret > nums[i] { 8 ret = nums[i] 9 } 10 } 11 return ret 12 } 13 14 // MaxInt find and return the maximum item from the specified int 15 func MaxInt(nums ...int) int { 16 var ret = nums[0] 17 for i, l := 1, len(nums); i < l; i++ { 18 if ret < nums[i] { 19 ret = nums[i] 20 } 21 } 22 return ret 23 } 24 25 // MinByte find and return the minimum item from the specified byte 26 func MinByte(nums ...byte) byte { 27 var ret = nums[0] 28 for i, l := 1, len(nums); i < l; i++ { 29 if ret > nums[i] { 30 ret = nums[i] 31 } 32 } 33 return ret 34 } 35 36 // MaxByte find and return the maximum item from the specified byte 37 func MaxByte(nums ...byte) byte { 38 var ret = nums[0] 39 for i, l := 1, len(nums); i < l; i++ { 40 if ret < nums[i] { 41 ret = nums[i] 42 } 43 } 44 return ret 45 } 46 47 // MinInt8 find and return the minimum item from the specified int8 48 func MinInt8(nums ...int8) int8 { 49 var ret = nums[0] 50 for i, l := 1, len(nums); i < l; i++ { 51 if ret > nums[i] { 52 ret = nums[i] 53 } 54 } 55 return ret 56 } 57 58 // MaxInt8 find and return the maximum item from the specified int8 59 func MaxInt8(nums ...int8) int8 { 60 var ret = nums[0] 61 for i, l := 1, len(nums); i < l; i++ { 62 if ret < nums[i] { 63 ret = nums[i] 64 } 65 } 66 return ret 67 } 68 69 // MinUint8 find and return the minimum item from the specified uint8 70 func MinUint8(nums ...uint8) uint8 { 71 var ret = nums[0] 72 for i, l := 1, len(nums); i < l; i++ { 73 if ret > nums[i] { 74 ret = nums[i] 75 } 76 } 77 return ret 78 } 79 80 // MaxUint8 find and return the maximum item from the specified uint8 81 func MaxUint8(nums ...uint8) uint8 { 82 var ret = nums[0] 83 for i, l := 1, len(nums); i < l; i++ { 84 if ret < nums[i] { 85 ret = nums[i] 86 } 87 } 88 return ret 89 } 90 91 // MinInt16 find and return the minimum item from the specified int16 92 func MinInt16(nums ...int16) int16 { 93 var ret = nums[0] 94 for i, l := 1, len(nums); i < l; i++ { 95 if ret > nums[i] { 96 ret = nums[i] 97 } 98 } 99 return ret 100 } 101 102 // MaxInt16 find and return the maximum item from the specified int16 103 func MaxInt16(nums ...int16) int16 { 104 var ret = nums[0] 105 for i, l := 1, len(nums); i < l; i++ { 106 if ret < nums[i] { 107 ret = nums[i] 108 } 109 } 110 return ret 111 } 112 113 // MinUint16 find and return the minimum item from the specified uint16 114 func MinUint16(nums ...uint16) uint16 { 115 var ret = nums[0] 116 for i, l := 1, len(nums); i < l; i++ { 117 if ret > nums[i] { 118 ret = nums[i] 119 } 120 } 121 return ret 122 } 123 124 // MaxUint16 find and return the maximum item from the specified uint16 125 func MaxUint16(nums ...uint16) uint16 { 126 var ret = nums[0] 127 for i, l := 1, len(nums); i < l; i++ { 128 if ret < nums[i] { 129 ret = nums[i] 130 } 131 } 132 return ret 133 } 134 135 // MinInt32 find and return the minimum item from the specified int32 136 func MinInt32(nums ...int32) int32 { 137 var ret = nums[0] 138 for i, l := 1, len(nums); i < l; i++ { 139 if ret > nums[i] { 140 ret = nums[i] 141 } 142 } 143 return ret 144 } 145 146 // MaxInt32 find and return the maximum item from the specified int32 147 func MaxInt32(nums ...int32) int32 { 148 var ret = nums[0] 149 for i, l := 1, len(nums); i < l; i++ { 150 if ret < nums[i] { 151 ret = nums[i] 152 } 153 } 154 return ret 155 } 156 157 // MinUint32 find and return the minimum item from the specified int32 158 func MinUint32(nums ...uint32) uint32 { 159 var ret = nums[0] 160 for i, l := 1, len(nums); i < l; i++ { 161 if ret > nums[i] { 162 ret = nums[i] 163 } 164 } 165 return ret 166 } 167 168 // MaxUint32 find and return the maximum item from the specified uint32 169 func MaxUint32(nums ...uint32) uint32 { 170 var ret = nums[0] 171 for i, l := 1, len(nums); i < l; i++ { 172 if ret < nums[i] { 173 ret = nums[i] 174 } 175 } 176 return ret 177 } 178 179 // MinInt64 find and return the minimum item from the specified uint32 180 func MinInt64(nums ...int64) int64 { 181 var ret = nums[0] 182 for i, l := 1, len(nums); i < l; i++ { 183 if ret > nums[i] { 184 ret = nums[i] 185 } 186 } 187 return ret 188 } 189 190 // MaxInt64 find and return the maximum item from the specified int64 191 func MaxInt64(nums ...int64) int64 { 192 var ret = nums[0] 193 for i, l := 1, len(nums); i < l; i++ { 194 if ret < nums[i] { 195 ret = nums[i] 196 } 197 } 198 return ret 199 } 200 201 // MinUint64 find and return the minimum item from the specified uint64 202 func MinUint64(nums ...uint64) uint64 { 203 var ret = nums[0] 204 for i, l := 1, len(nums); i < l; i++ { 205 if ret > nums[i] { 206 ret = nums[i] 207 } 208 } 209 return ret 210 } 211 212 // MaxUint64 find and return the maximum item from the specified uint64 213 func MaxUint64(nums ...uint64) uint64 { 214 var ret = nums[0] 215 for i, l := 1, len(nums); i < l; i++ { 216 if ret < nums[i] { 217 ret = nums[i] 218 } 219 } 220 return ret 221 } 222 223 // MinFloat32 find and return the minimum item from the specified float32 224 func MinFloat32(nums ...float32) float32 { 225 var ret = nums[0] 226 for i, l := 1, len(nums); i < l; i++ { 227 if ret > nums[i] { 228 ret = nums[i] 229 } 230 } 231 return ret 232 } 233 234 // MaxFloat32 find and return the maximum item from the specified float32 235 func MaxFloat32(nums ...float32) float32 { 236 var ret = nums[0] 237 for i, l := 1, len(nums); i < l; i++ { 238 if ret < nums[i] { 239 ret = nums[i] 240 } 241 } 242 return ret 243 } 244 245 // MinFloat64 find and return the minimum item from the specified float64 246 func MinFloat64(nums ...float64) float64 { 247 var ret = nums[0] 248 for i, l := 1, len(nums); i < l; i++ { 249 if ret > nums[i] { 250 ret = nums[i] 251 } 252 } 253 return ret 254 } 255 256 // MaxFloat64 find and return the maximum item from the specified float64 257 func MaxFloat64(nums ...float64) float64 { 258 var ret = nums[0] 259 for i, l := 1, len(nums); i < l; i++ { 260 if ret < nums[i] { 261 ret = nums[i] 262 } 263 } 264 return ret 265 }