> > 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.

Mark, you're making a small mistake here: Maarten means with 'Sqr(X)', X 
squared! NOT the square root!! Then he'd write 'Sqrt(x)'... Freshen up your 
Pascal dude! ;-))

Grtjs, Manuel

PS: MSX 4 EVER! (Questions? See: http://www.faq.msxnet.org)
PPS: Visit my homepage at http://www.sci.kun.nl/marie/home/manuelbi 


****
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