Re: No irrationals



Han.deBruijn@xxxxxxxxxxxxxx wrote:

But ... HOW ABOUT IRRATIONAL EXPONENTS ? (No logarithms please)

While thinking about a partial answer to this question ...

program poster;
{
It is demonstrated in this program how arbitrary real powers
of a real number can be approximated, with nothing else than
elementary arithmetic operations and a square root function.
}
function macht(x,a : double) : double;
{
Power x^a
}
var
m,k : integer;
g,p,q,y : double;
begin
m := Trunc(a);
y := x;
p := 1;
while m > 0 do begin
if (m and 1) > 0 then p := p * y;
m := m div 2; { m := m shr 1 }
y := y * y;
end;
g := a - Trunc(a);
y := x;
q := 1;
for k := 0 to 50 do
begin
g := g * 2;
y := sqrt(y); { Square Root HERE }
if (Trunc(g) and 1) > 0 then q := q * y;
end;
macht := p * q;
end;

procedure Test;
{
Just a Test
}
begin
Writeln(macht(4,0.5));
Writeln(macht(9,0.5));
Writeln(macht(81,1/4));
Writeln(macht(27,1/3));
Writeln(macht(exp(1),7),' = ',exp(7));
Writeln(macht(exp(1),0.7),' = ',exp(0.7));
Writeln(macht(exp(1),7.7),' = ',exp(7.7));
Writeln(macht(exp(1),Pi),' = ',exp(Pi));
end;

begin
Test;
end.

Han de Bruijn

.


Quantcast