Mark Zellenrath wrote:
>> 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
>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?
The function sqr in Pascal means "square", not "square root" as it does in
BASIC. So replacing "x := sqr(x)" by "x := x * x" will not make a
difference for the end result.
Jorge Vidal Wulff wrote:
>This is *VERY* inefficient,try my algorithm. X^n=exp(n*ln(x))
I'm not sure which is more efficient. How sure are you that "exp" and "ln"
will execute faster than the program above?
I don't use MSX TP, but could someone who does use it do some timing on
both solutions? I'd be interested in the results.
Besides, the algorithm I mailed uses only integers, so no chance of
rounding flaws.
Bye,
Maarten
****
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/)
****