Executable bounded fixed-point operations #
Bounded fixed point stores an exact signed coefficient in a fixed-width two's-complement carrier.
Conversion and arithmetic take an (overflow := ...) option: .reject, the default, returns
none when the exact coefficient does not fit, .wrap reduces it modulo 2 ^ width, and
.saturate clamps it to the signed range.
Multiplication also exposes the composed input scale and chosen destination width in its result type. The implementation reuses the generic fixed-integer kernels and their refinement theorems.
What a bounded fixed-point conversion or operation does with a coefficient that does not fit.
- reject : OverflowPolicy
Return
none, or reject a conversion asoutOfRange. - wrap : OverflowPolicy
Reduce the coefficient modulo
2 ^ width. - saturate : OverflowPolicy
Clamp the coefficient to the signed destination range.
Instances For
Wrap a complete bounded fixed-point code without conversion.
Instances For
Recover the complete bounded fixed-point code without conversion.
Instances For
Construct a bounded fixed-point value from its complete unsigned word.
Instances For
Read the complete bounded fixed-point word as an unsigned natural number.
Instances For
Encode an integer coefficient modulo 2 ^ width.
Instances For
Round an exact rational to the nearest coefficient, ties to even, then apply the overflow
policy when that coefficient does not fit.
Instances For
Recover the stored signed integer coefficient.
Instances For
Decode a bounded fixed-point value to its exact rational meaning.
Instances For
Same-scale addition, applying the overflow policy when the exact coefficient sum does not
fit.
Instances For
Same-scale subtraction, with the overflow options of add.
Instances For
Multiplication into an outWidth-bit coefficient with exact scale composition, p + q
fractional digits, and the overflow options of add at the destination width.