Q-Format Fixed-Point Converter
embedcalc_qformat_convertEncode floating-point numbers to signed Qm.n fixed-point integers or decode them back, with format validation, quantization error, and clamping.
Instructions
Convert between float and signed Qm.n fixed point (1 sign + m integer + n fractional bits; e.g. Q0.15 = 16-bit "Q15").
Args:
m (int >= 0), n (int >= 0): format; m+n+1 <= 32.
value (float) OR raw_int (stored integer): provide exactly one.
Returns (structured): { format, total_bits, scale, range_min, range_max, raw_int, hex, bin, actual, error, clamped }. hex/bin are two's complement in the format's bit width. Examples: 0.5 in Q0.15 -> 16384 = 0x4000; raw 0x8000 (-32768) in Q0.15 -> -1.0. Do not round by hand — quantization error matters.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| m | Yes | Integer bits (excluding sign) | |
| n | Yes | Fractional bits | |
| value | No | Float value to encode (provide this OR raw_int) | |
| raw_int | No | Stored fixed-point integer to decode (provide this OR value) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bin | Yes | ||
| hex | Yes | ||
| error | Yes | |input - actual| (0 when decoding raw_int) | |
| scale | Yes | 2^n | |
| actual | Yes | Value actually represented after quantization | |
| format | Yes | ||
| clamped | Yes | ||
| raw_int | Yes | ||
| range_max | Yes | ||
| range_min | Yes | ||
| total_bits | Yes |