我试图找到一个固定点的平方根,我使用以下计算来使用整数算法找到平方根的近似值。该算法在维基百科中有所描述: http ://en.wikipedia.org/wiki/Methods_of_computing_square_roots
uint32_t SquareRoot(uint32_t a_nInput)
{
uint32_t op = a_nInput;
uint32_t res = 0;
uint32_t one = 1uL << 30; // The second-to-top bit is set: use 1u << 14 for uint16_t type; use 1uL<<30 for uint32_t type
// "one" starts at the highest power of four <= than the argument.
while (one > op)
{
one >>= 2;
}
while (one != 0)
{
if (op >= res + one)
{
op = op - (res + one);
res = res + 2 * one;
}
res >>= 1;
one >>= 2;
}
return res;
}
但我无法理解代码中发生的事情评论// "one" starts at the highest power of four <= than the argument.
到底意味着什么。有人可以提示我代码中发生了什么来计算参数的平方根吗 a_nInput
非常感谢