تابعی ساده و بسیار بهینه برای محاسبه رادیکال
uint16_t sqrt32(uint32_t a) {
uint32_t rem = 0, root = 0;
for (int i = 32 / 2; i > 0; i--)
{
root <<= 1;
rem = (rem << 2) | (a >> (32 - 2));
a <<= 2;
if (root < rem)
{
rem -= root | 1;
root += 2;
}
}
return root >> 1;
}09 8月 2023, 06:06
