Q-Format Converter

Float ↔ Q7 / Q15 / Q31 with hex, quantization error and the arithmetic rules.

The three rules of Q arithmetic

A Qn number stores in an integer, covering with resolution . The rules that prevent 90% of fixed-point bugs:

1. Addition — same format in, same format out, but the result can overflow: adding two Q15 values needs either saturation or one guard bit. 2. Multiplication — formats add: , so the int32 product must be shifted right by 15 (and rounded: add before the shift) to come back to Q15. 3. The asymmetry — −1.0 is representable but +1.0 is not, and overflows: the only multiply that saturates in hardware MAC units. That's why CMSIS-DSP's __SSAT exists.