How to mulitiplay numbers

Posted:
July 6th, 2005, 12:23 pm
by zok965
Dear all
Please help me to solve one problem. For example i wana multiplay two numbers like this X^Y. 2^3=8 or 5^4=625
Plese give me a code.
Thanks

Posted:
July 6th, 2005, 12:35 pm
by Kambiz
For that purpose the following function is defined in the
Math unit.
- Code: Select all
function Power(const Base, Exponent: Extended): Extended;

Posted:
July 6th, 2005, 12:37 pm
by Radagast
- Code: Select all
function multiply (base: real; power: integer): real;
begin
if power<0 then
begin
base:=1/base;
power:=-power;
end;
if power=0 then Result:=1
else Result:=base*multiply(base, power-1);
end;
It's the easiest one. I'll try to find you faster one, using binary value of power (is it called like that?).
EDIT: Kambiz was faster.