Sub32WithOverflow returns a-b. If ok is false, a-b overflowed.
(a, b int32)
| 79 | |
| 80 | // Sub32WithOverflow returns a-b. If ok is false, a-b overflowed. |
| 81 | func Sub32WithOverflow(a, b int32) (r int32, ok bool) { |
| 82 | if b < 0 && a > math.MaxInt32+b { |
| 83 | return 0, false |
| 84 | } |
| 85 | if b > 0 && a < math.MinInt32+b { |
| 86 | return 0, false |
| 87 | } |
| 88 | return a - b, true |
| 89 | } |
| 90 | |
| 91 | // MulHalfPositiveWithOverflow returns a*b. b must be positive. If ok |
| 92 | // is false, a*b overflowed. |
no outgoing calls
no test coverage detected