Re: No irrationals
- From: Han.deBruijn@xxxxxxxxxxxxxx
- Date: 2 Sep 2006 04:31:34 -0700
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
.
- References:
- Re: No irrationals
- From: Han . deBruijn
- Re: No irrationals
- Prev by Date: Re: algebra with finite field and isomorphic.
- Next by Date: Re: Ideals of Z[ sqrt(-3) ] that include 4.
- Previous by thread: Re: No irrationals
- Next by thread: Re: Justice For Pluto
- Index(es):