SubWithOverflow returns a-b. If ok is false, a-b overflowed.
(a, b int64)
| 59 | |
| 60 | // SubWithOverflow returns a-b. If ok is false, a-b overflowed. |
| 61 | func SubWithOverflow(a, b int64) (r int64, ok bool) { |
| 62 | if b < 0 && a > math.MaxInt64+b { |
| 63 | return 0, false |
| 64 | } |
| 65 | if b > 0 && a < math.MinInt64+b { |
| 66 | return 0, false |
| 67 | } |
| 68 | return a - b, true |
| 69 | } |
| 70 | |
| 71 | // Sub32to64WithOverflow returns a-b. If ok is false, b was outside the |
| 72 | // int32 range or a-b overflowed. |
no outgoing calls
no test coverage detected