SRL Archive - SRL Archives

PowerOf (math.scar)


Richard

2010-12-20 20:01:12

I was trying to use the ^ symbol for doing powers, but it never seemed to work in Simba (not sure whether Simba has a different way of doing indices, my computer [those it happens both on my laptop and my desktop], or there is no function existance for indices). So I created a little mini powers function. It's nothing special, and I'm guessing loads of people have created one for use in their scripts, but here it is for people who might wish to use it:

function PowerOf(int, power: integer): integer;
var
i: integer;
begin
Result := int;
for i := 1 to power - 1 do
Result := Result * int;
end;

This can't deal with negative or fractional indices, I'll update this when I've created one (probably named PowerOfEx).

If there is actually a way of doing this currently, I'd love to know! :p

Ogre

2010-12-20 20:17:00

pow(base: Extended; exponent: Extended): Extended

Dgby714

2010-12-20 20:22:15

Too bad we cant just do
program new;

operator^(Param1, Param2: extended): extended;
begin
Result := Pow(Param1, Param2);
end;

begin
WriteLn(2 ^ 2);
end.

Daniel

2010-12-25 07:04:38

^ refers to a pointer type PASCAL. Also, in C and other languages, ^ is bitwise exclusive-OR. :)