私は固定小数点の平方根を見つけようとしています。次の計算を使用して、整数アルゴリズムを使用して平方根の近似値を見つけました。アルゴリズムはウィキペディアで説明されています: 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
どうもありがとう