How to mulitiplay numbers

Please discuss general Delphi programming topics here.

How to mulitiplay numbers

Postby zok965 » July 6th, 2005, 12:23 pm

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
zok965
Member
Member
 
Posts: 1
Joined: July 6th, 2005, 12:16 pm

Postby Kambiz » July 6th, 2005, 12:35 pm

For that purpose the following function is defined in the Math unit.

Code: Select all
function Power(const Base, Exponent: Extended): Extended;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Radagast » July 6th, 2005, 12:37 pm

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.
Radagast
Active Member
Active Member
 
Posts: 24
Joined: May 1st, 2005, 9:32 pm
Location: Poland


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron