>> p := 1;
>> while n <> 0 do
>> begin
>>      if n mod 2 = 1 then p := p * x;
>>      n := n div 2;
>>      x := sqr(x);
>> end;
>
>  Well, I think you made a small error here, Maarten. If you want to
>calculate x^n with n being an integer, so n = {0, 1, 2, 3, ....}, then


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.

>the formula for x should be "x := x * x". I'm not sure how to calculate
>x^n with 0<n<1 (so for instance x^0.25). Suggestions, anyone?


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?

Cas Cremers
Parallax MSX Games
(oh, btw: there's an update AND an editor to download...)
http://www.stack.nl/~cas/par/





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