| 1 |
checked: overflow-checked integer arithmetic |
| 2 |
|
| 3 |
The functions add*, sub* and mul* perform wrapping integer arithmetic, with the |
| 4 |
same semantics as the +, -, and * operators. |
| 5 |
|
| 6 |
const (res, overflow) = math::addi32(types::I32_MAX, 1); |
| 7 |
assert(res == types::I32_MIN); |
| 8 |
assert(overflow); |
| 9 |
|
| 10 |
The functions sat_* perform saturating integer arithmetic, which clamp the |
| 11 |
result value to the range of the type. |
| 12 |
|
| 13 |
const res = math::sat_addi32(types::I32_MAX, 1); |
| 14 |
assert(res == types::I32_MAX); |