What is Saturating arithmetic?
Arithmetic that clamps results exceeding the representable range to the maximum or minimum instead of wrapping around. Used in audio and image signal processing to avoid large errors.
Japanese name: 飽和演算
Arithmetic that clamps results exceeding the representable range to the maximum or minimum instead of wrapping around. Used in audio and image signal processing to avoid large errors.
Japanese name: 飽和演算
In ordinary integer arithmetic, a result beyond the range wraps around to the opposite end. An 8-bit signed integer can represent −128 to 127. Adding 100 and 100 really gives 200, but with wraparound the result is −56. With saturating arithmetic it stays at the upper limit, 127. For unsigned 8 bits (0 to 255), adding 100 to 200 gives 44 with wraparound and 255 with saturation. Subtracting 100 from 50 gives 206 with wraparound and 0 with saturation.
When an audio waveform slightly exceeds the maximum value and wraps around, the value jumps from near the positive maximum to near the negative maximum. This is heard as loud noise. With saturating arithmetic the top of the waveform is merely flattened and the error stays small. The same holds for images. When brightness is added and exceeds the upper limit, wraparound makes white areas suddenly dark, while saturation keeps them white.
Digital signal processors (DSPs) and SIMD instructions, which process several data items at once, have saturating add and subtract instructions. As a circuit, it only detects overflow and replaces the result with the maximum or minimum value. Ordinary integer arithmetic in C does not saturate, so the programmer writes range checks or uses dedicated functions. One caution is that the result depends on the order of operations. In 8-bit signed arithmetic, evaluating 100 + 100 − 100 from the left gives 127 − 100, which is 27. Evaluating the last two first gives 100 + 0, which is 100.
Answer: A. When a result exceeds the maximum, it is held at the maximum instead of wrapping around
Ordinary integer arithmetic wraps around on overflow; in 8-bit signed arithmetic, 127 + 1 becomes −128. In audio or images that causes large errors, such as the brightest pixel suddenly turning dark. Saturating arithmetic clamps results above the maximum to the maximum (127) and below the minimum to the minimum (−128), keeping errors small. DSP and SIMD instruction sets provide it. The bit width does not grow, and results are not reset to 0.
On many processors, yes. When saturation occurs a dedicated flag is set and stays set until software clears it.
A result beyond the representable range becomes infinity. It does not wrap around, so the sign-reversal errors of integer wraparound do not occur.
Saturating arithmetic appears in 3 practice questions across 3 topics, including Computer Arithmetic, Digital Signal Processing Basics, Control Engineering Basics.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.