From 364bafc38d9b703a09458431d9a6b2bc44fd9a39 Mon Sep 17 00:00:00 2001 From: c-mon <5995664+1f5@users.noreply.github.com> Date: Fri, 1 Mar 2024 18:00:22 +0100 Subject: [PATCH] Codechange: Replace custom rounded square root logic with standard library functions --- src/core/math_func.cpp | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/core/math_func.cpp b/src/core/math_func.cpp index f094e9ece8..7af8b7bca9 100644 --- a/src/core/math_func.cpp +++ b/src/core/math_func.cpp @@ -37,28 +37,8 @@ int DivideApprox(int a, int b) * Compute the integer square root. * @param num Radicand. * @return Rounded integer square root. - * @note Algorithm taken from http://en.wikipedia.org/wiki/Methods_of_computing_square_roots */ uint32_t IntSqrt(uint32_t num) { - uint32_t res = 0; - uint32_t bit = 1UL << 30; // Second to top bit number. - - /* 'bit' starts at the highest power of four <= the argument. */ - while (bit > num) bit >>= 2; - - while (bit != 0) { - if (num >= res + bit) { - num -= res + bit; - res = (res >> 1) + bit; - } else { - res >>= 1; - } - bit >>= 2; - } - - /* Arithmetic rounding to nearest integer. */ - if (num > res) res++; - - return res; + return (uint32_t)round(sqrt(num)); }