> as far as I can see, Maarten is right. P is the intermediate result, while X
> goes from X to X^2 to X^4 to X^8.... as the bits of N (powers of 2) are
> inspected.... it's a standard algorithm.

  I think you misunderstood me. Maarten wrote the routine as followed:

p := 1;
while n <> 0 do
begin
     if n mod 2 = 1 then p := p * x;
     n := n div 2;
     x := sqr(x);
end;

  This, however, is not the correct routine. It should be, as I
suggested by replacing x:=sqr(x) by x:=x*x, as followed:

p := 1;
while n <> 0 do
begin
     if n mod 2 = 1 then p := p * x;
     n := n div 2;
     x := x * x;
end;

  As you see, with x:=sqr(x) x goes from x to x^0.5 to x^0.25... With
x:=x*x, however, your statement does hold for x goes from x to x^2 to
x^4...
  Anyway, it's no biggy. I just wanted to point out a small error in
Maarten routine, not to make a big deal out of it.

> erm I don't suppose this has anything to do with the initial question, but I
> suppose (without checking) that you would do it with something like
> Newton-Raphson iteration: that is the usual way to approximate the square
> root (X^0.5) and I believe it's not too hard to set it up for other values
> between 0 and 1. Anyone making the code?

  It has nothing to do with the initial question, but just with my
inquisitive mind. =)

  Bye, /\/\ark

****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****

Reply via email to