Fixed-Point Square Root

Hard C Precision Asked at Analog Devices
Solve this problem

Implement an integer square root for Q16.16 fixed-point numbers on a core with no FPU. Return the Q16.16 square root of a Q16.16 input.

Constraints

  • Signature: `uint32_t sqrt_q16(uint32_t x)`.
  • No floating point anywhere in the implementation.
  • No division instructions.
  • Result must be accurate to within 1 LSB of the true value.
  • Must terminate in a bounded number of iterations.
  • sqrt_q16(0) must return 0.
Starter codeC
1#include <stdint.h>2 3/* x and the return value are both Q16.16 fixed point. */4uint32_t sqrt_q16(uint32_t x) {5    // TODO: integer square root, no FPU6    return 0;7}