IT lexicon › Programming › Saturating arithmetic

Saturating arithmetic

Programming På svenska → Updated: 2026-11-04

Arithmetic in which a result that doesn't fit sticks at the largest or smallest value instead of wrapping around to the other end of the range.

Ordinary two's-complement integer maths is modular: 127 + 1 in an int8_t is −128. For a counter that is often exactly what you want; for an audio sample or a control output it is a disaster. A sample that should have been slightly too loud jumps to full negative excursion and comes out as a click. With saturation it becomes 127 and the error sounds like ordinary clipping.

DSPs have had it in hardware since the 1980s. ARM added QADD and QSUB in ARMv5TE and SSAT/USAT in ARMv6; they are standard on Cortex-M4 and up, and CMSIS exposes them as intrinsics. C still has no standard operator, so portable code writes the comparisons by hand and hopes the compiler spots the pattern. Rust has saturating_add on every integer type.

← Back to the lexicon