Simvik

Integer square root

Compute the square root of a 32-bit value without floating point. A medium embedded C problem (Fixed-point and signal processing), run and graded in the…

medium · Fixed-point and signal processing · math · bit-by-bit

Computing a magnitude or an RMS value needs a square root, and a Cortex-M0 has no FPU.

Return the largest integer r such that r * r <= x.

Starter code

uint16_t isqrt32(uint32_t x) {
  // Largest r with r * r <= x.
  return 0;
}

Example tests

Perfect square

printf("%u\n", isqrt32(16));

Expected output:

4

Rounds down

printf("%u\n", isqrt32(17));

Expected output:

4

Learn it first

More Fixed-point and signal processing problems