home *** CD-ROM | disk | FTP | other *** search
- Function PwrR(x,y : real): real;
- {Written by Paul F. Hultquist. Found in May 1985 PC Tech Journl }
- {PwrR finds X (real) to the power Y (real) using logarithms and exponentials.}
- {If Y is an integer PwrI is faster. The function eliminates the undefined }
- {cases, and the case where the result is complex. }
-
- Begin
- if x > 0 then
- PwrR := exp(y*ln(x))
- else
- if x < 0 then
- begin
- writeln('x < 0. Halt.');
- Halt;
- end
- else
- if (x = 0) and (y = 0) then
- begin
- writeln('0 to the 0 power. Halt.');
- Halt;
- end
- else
- if (x = 0) and (y < 0) then
- begin
- writeln('0 to a negative power. Halt.');
- Halt;
- end
- else
- PwrR := 0.0;
- End; {PwrR}function Mpwr(num : real; expon : integer): real;
- Var
- M : real;
- I : integer;
- begin
- M := num;
- for I := 2 to expon do
- num := num * M;
- Mpwr := num;
- end; {Rpwr}
- function Rpwr(num : real; expon : integer): real;
- begin
- if expon = 0 then Rpwr :=1
- else
- Rpwr := num * Rpwr(num, expon - 1);
- end; {Rpwr}