Correctness of configured bounded fixed-point operations #
Complete word conversions recover the stored code, and encoding preserves in-range words. Wrapping arithmetic decodes to centered modular arithmetic on signed coefficients. Checked addition and subtraction are exact whenever they succeed; the corresponding multiplication theorem assumes a positive destination width. At positive widths, saturating arithmetic decodes to the exact coefficient clamped to the signed destination range.
Unwrapping a freshly wrapped bounded fixed-point code returns the original code.
Rewrapping the code of a bounded fixed-point value returns the original value.
Reconstructing a value from its complete word preserves the value.
An in-range word is unchanged by bounded fixed-point encoding and decoding.
Constructing from an integer stores its two's-complement residue at the selected width.
Wrapping addition decodes to coefficient addition modulo 2 ^ width.
Wrapping subtraction decodes to coefficient subtraction modulo 2 ^ width.
Wrapping multiplication decodes to coefficient multiplication modulo 2 ^ outWidth.
Checked addition succeeds with the wrapped sum when the exact coefficient sum fits.
Checked subtraction succeeds with the wrapped difference when the exact coefficient fits.
Checked multiplication succeeds with the encoded product when the exact coefficient fits.
Checked addition is exact: whenever it returns a value, that value decodes to the rational sum of the operands. No width hypothesis is needed because success already certifies the absence of signed overflow.
Checked subtraction is exact: whenever it returns a value, that value decodes to the rational difference of the operands.
Checked multiplication is exact: whenever it returns a value at a positive destination width, that value decodes to the rational product of the operands at the composed scale.
Saturating addition decodes to exact coefficient addition followed by clamping.
Saturating subtraction decodes to exact coefficient subtraction followed by clamping.
Saturating multiplication decodes to the clamped exact product at the composed scale.