Fixed-Point Multiply (Q15)
Implement a fixed-point multiplication for Q15 format in C. Inputs are signed 16-bit, output also Q15. Prevent overflow and maintain saturation.
Constraints
- Inputs int16_t.
- Multiply produce 32-bit temp.
- Shift right 15.
- Clamp to [-32768, 32767].
- Return int16_t.
1#include <stdint.h>2int16_t q15_mul(int16_t a, int16_t b);