Integer Square Root (sqrti)
Integer square root computation without floating-point operations, suitable for embedded platforms without an FPU.
Algorithm
Based on the digit-by-digit method, determining each bit of the square root starting from the most significant bit. Similar to long division for square roots, all operations are integer addition, subtraction, and shifts, with no floating-point dependency.
API
unsigned long sqrti(unsigned long x);
Computes the integer square root of x, returning ⌊√x⌋.
x = 0returns 0x = 1returns 1x = 4returns 2x = 5returns 2 (rounded down)
Usage Examples
Calculate distance (Pythagorean theorem)
unsigned long dx = x2 - x1;
unsigned long dy = y2 - y1;
unsigned long dist = sqrti(dx * dx + dy * dy);
Graphics scaling
unsigned long ratio = sqrti(src_size * src_size / dst_size);