On 2005-03-22, Peter Nilsson <(E-Mail Removed)> wrote:

> But it does assume that there are no padding bits.
Yes.

> Why not? It's trivial...

>

> int value_bits = 0;

> untype_t x;

> for (x = -1, x = x/2+1; x; x >>= 1) value_bits++;
Yeah, I know it's trivial. I just didn't do it

> Or, as in the sample I gave in comp.programming you can simply

> mask the highest eventh bit and shift the mask as you go.
I'll have to look for your post on this.

> Assuming you have M value bits, your algorithm performs

> M-2 + M-4 + M-6 ... shifts. You could reduce this to

> precisely M.
I'm curious how you'd get around this? You need to extract 2 bits from the

radicand (a) for each iteration, and since you have to start with the most

significant bits, you can't just keep a running register and shift off the

bits to the right.

>> if (diff < a_i) /* overflow check */

>> root = 1;

>

> This last if-statement is an obfuscated way of writing...

>

> root = (a_i != 0);

>

> In other words, your 'overflow' occurs if and only if a_i is 0.
Thanks for your comments.

-Clint