github.com/FUSIONFoundation/efsn@v3.6.2-0.20200916075423-dbb5dd5d2cc7+incompatible/common/overflow/overflow_impl.go (about) 1 package overflow 2 3 // This is generated code, created by overflow_template.sh executed 4 // by "go generate" 5 6 7 8 9 // Add8 performs + operation on two int8 operands 10 // returning a result and status 11 func Add8(a, b int8) (int8, bool) { 12 c := a + b 13 if (c > a) == (b > 0) { 14 return c, true 15 } 16 return c, false 17 } 18 19 // Add8p is the unchecked panicing version of Add8 20 func Add8p(a, b int8) int8 { 21 r, ok := Add8(a, b) 22 if !ok { 23 panic("addition overflow") 24 } 25 return r 26 } 27 28 29 // Sub8 performs - operation on two int8 operands 30 // returning a result and status 31 func Sub8(a, b int8) (int8, bool) { 32 c := a - b 33 if (c < a) == (b > 0) { 34 return c, true 35 } 36 return c, false 37 } 38 39 // Sub8p is the unchecked panicing version of Sub8 40 func Sub8p(a, b int8) int8 { 41 r, ok := Sub8(a, b) 42 if !ok { 43 panic("subtraction overflow") 44 } 45 return r 46 } 47 48 49 // Mul8 performs * operation on two int8 operands 50 // returning a result and status 51 func Mul8(a, b int8) (int8, bool) { 52 if a == 0 || b == 0 { 53 return 0, true 54 } 55 c := a * b 56 if (c < 0) == ((a < 0) != (b < 0)) { 57 if c/b == a { 58 return c, true 59 } 60 } 61 return c, false 62 } 63 64 // Mul8p is the unchecked panicing version of Mul8 65 func Mul8p(a, b int8) int8 { 66 r, ok := Mul8(a, b) 67 if !ok { 68 panic("multiplication overflow") 69 } 70 return r 71 } 72 73 74 75 // Div8 performs / operation on two int8 operands 76 // returning a result and status 77 func Div8(a, b int8) (int8, bool) { 78 q, _, ok := Quotient8(a, b) 79 return q, ok 80 } 81 82 // Div8p is the unchecked panicing version of Div8 83 func Div8p(a, b int8) int8 { 84 r, ok := Div8(a, b) 85 if !ok { 86 panic("division failure") 87 } 88 return r 89 } 90 91 // Quotient8 performs + operation on two int8 operands 92 // returning a quotient, a remainder and status 93 func Quotient8(a, b int8) (int8, int8, bool) { 94 if b == 0 { 95 return 0, 0, false 96 } 97 c := a / b 98 status := (c < 0) == ((a < 0) != (b < 0)) 99 return c, a % b, status 100 } 101 102 103 104 // Add16 performs + operation on two int16 operands 105 // returning a result and status 106 func Add16(a, b int16) (int16, bool) { 107 c := a + b 108 if (c > a) == (b > 0) { 109 return c, true 110 } 111 return c, false 112 } 113 114 // Add16p is the unchecked panicing version of Add16 115 func Add16p(a, b int16) int16 { 116 r, ok := Add16(a, b) 117 if !ok { 118 panic("addition overflow") 119 } 120 return r 121 } 122 123 124 // Sub16 performs - operation on two int16 operands 125 // returning a result and status 126 func Sub16(a, b int16) (int16, bool) { 127 c := a - b 128 if (c < a) == (b > 0) { 129 return c, true 130 } 131 return c, false 132 } 133 134 // Sub16p is the unchecked panicing version of Sub16 135 func Sub16p(a, b int16) int16 { 136 r, ok := Sub16(a, b) 137 if !ok { 138 panic("subtraction overflow") 139 } 140 return r 141 } 142 143 144 // Mul16 performs * operation on two int16 operands 145 // returning a result and status 146 func Mul16(a, b int16) (int16, bool) { 147 if a == 0 || b == 0 { 148 return 0, true 149 } 150 c := a * b 151 if (c < 0) == ((a < 0) != (b < 0)) { 152 if c/b == a { 153 return c, true 154 } 155 } 156 return c, false 157 } 158 159 // Mul16p is the unchecked panicing version of Mul16 160 func Mul16p(a, b int16) int16 { 161 r, ok := Mul16(a, b) 162 if !ok { 163 panic("multiplication overflow") 164 } 165 return r 166 } 167 168 169 170 // Div16 performs / operation on two int16 operands 171 // returning a result and status 172 func Div16(a, b int16) (int16, bool) { 173 q, _, ok := Quotient16(a, b) 174 return q, ok 175 } 176 177 // Div16p is the unchecked panicing version of Div16 178 func Div16p(a, b int16) int16 { 179 r, ok := Div16(a, b) 180 if !ok { 181 panic("division failure") 182 } 183 return r 184 } 185 186 // Quotient16 performs + operation on two int16 operands 187 // returning a quotient, a remainder and status 188 func Quotient16(a, b int16) (int16, int16, bool) { 189 if b == 0 { 190 return 0, 0, false 191 } 192 c := a / b 193 status := (c < 0) == ((a < 0) != (b < 0)) 194 return c, a % b, status 195 } 196 197 198 199 // Add32 performs + operation on two int32 operands 200 // returning a result and status 201 func Add32(a, b int32) (int32, bool) { 202 c := a + b 203 if (c > a) == (b > 0) { 204 return c, true 205 } 206 return c, false 207 } 208 209 // Add32p is the unchecked panicing version of Add32 210 func Add32p(a, b int32) int32 { 211 r, ok := Add32(a, b) 212 if !ok { 213 panic("addition overflow") 214 } 215 return r 216 } 217 218 219 // Sub32 performs - operation on two int32 operands 220 // returning a result and status 221 func Sub32(a, b int32) (int32, bool) { 222 c := a - b 223 if (c < a) == (b > 0) { 224 return c, true 225 } 226 return c, false 227 } 228 229 // Sub32p is the unchecked panicing version of Sub32 230 func Sub32p(a, b int32) int32 { 231 r, ok := Sub32(a, b) 232 if !ok { 233 panic("subtraction overflow") 234 } 235 return r 236 } 237 238 239 // Mul32 performs * operation on two int32 operands 240 // returning a result and status 241 func Mul32(a, b int32) (int32, bool) { 242 if a == 0 || b == 0 { 243 return 0, true 244 } 245 c := a * b 246 if (c < 0) == ((a < 0) != (b < 0)) { 247 if c/b == a { 248 return c, true 249 } 250 } 251 return c, false 252 } 253 254 // Mul32p is the unchecked panicing version of Mul32 255 func Mul32p(a, b int32) int32 { 256 r, ok := Mul32(a, b) 257 if !ok { 258 panic("multiplication overflow") 259 } 260 return r 261 } 262 263 264 265 // Div32 performs / operation on two int32 operands 266 // returning a result and status 267 func Div32(a, b int32) (int32, bool) { 268 q, _, ok := Quotient32(a, b) 269 return q, ok 270 } 271 272 // Div32p is the unchecked panicing version of Div32 273 func Div32p(a, b int32) int32 { 274 r, ok := Div32(a, b) 275 if !ok { 276 panic("division failure") 277 } 278 return r 279 } 280 281 // Quotient32 performs + operation on two int32 operands 282 // returning a quotient, a remainder and status 283 func Quotient32(a, b int32) (int32, int32, bool) { 284 if b == 0 { 285 return 0, 0, false 286 } 287 c := a / b 288 status := (c < 0) == ((a < 0) != (b < 0)) 289 return c, a % b, status 290 } 291 292 293 294 // Add64 performs + operation on two int64 operands 295 // returning a result and status 296 func Add64(a, b int64) (int64, bool) { 297 c := a + b 298 if (c > a) == (b > 0) { 299 return c, true 300 } 301 return c, false 302 } 303 304 // Add64p is the unchecked panicing version of Add64 305 func Add64p(a, b int64) int64 { 306 r, ok := Add64(a, b) 307 if !ok { 308 panic("addition overflow") 309 } 310 return r 311 } 312 313 314 // Sub64 performs - operation on two int64 operands 315 // returning a result and status 316 func Sub64(a, b int64) (int64, bool) { 317 c := a - b 318 if (c < a) == (b > 0) { 319 return c, true 320 } 321 return c, false 322 } 323 324 // Sub64p is the unchecked panicing version of Sub64 325 func Sub64p(a, b int64) int64 { 326 r, ok := Sub64(a, b) 327 if !ok { 328 panic("subtraction overflow") 329 } 330 return r 331 } 332 333 334 // Mul64 performs * operation on two int64 operands 335 // returning a result and status 336 func Mul64(a, b int64) (int64, bool) { 337 if a == 0 || b == 0 { 338 return 0, true 339 } 340 c := a * b 341 if (c < 0) == ((a < 0) != (b < 0)) { 342 if c/b == a { 343 return c, true 344 } 345 } 346 return c, false 347 } 348 349 // Mul64p is the unchecked panicing version of Mul64 350 func Mul64p(a, b int64) int64 { 351 r, ok := Mul64(a, b) 352 if !ok { 353 panic("multiplication overflow") 354 } 355 return r 356 } 357 358 359 360 // Div64 performs / operation on two int64 operands 361 // returning a result and status 362 func Div64(a, b int64) (int64, bool) { 363 q, _, ok := Quotient64(a, b) 364 return q, ok 365 } 366 367 // Div64p is the unchecked panicing version of Div64 368 func Div64p(a, b int64) int64 { 369 r, ok := Div64(a, b) 370 if !ok { 371 panic("division failure") 372 } 373 return r 374 } 375 376 // Quotient64 performs + operation on two int64 operands 377 // returning a quotient, a remainder and status 378 func Quotient64(a, b int64) (int64, int64, bool) { 379 if b == 0 { 380 return 0, 0, false 381 } 382 c := a / b 383 status := (c < 0) == ((a < 0) != (b < 0)) 384 return c, a % b, status 385 } 386