Goto https://www.stucuk.netGoto https://www.atlanticaonlinewiki.comGoto https://www.game-requirements.com


Menu


It is currently Sat Sep 22, 2018 2:09 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Math function: POWER of a number
PostPosted: Fri Feb 26, 2010 4:41 pm 
Offline
Moderator
Moderator
User avatar

Joined: Fri Jan 13, 2006 6:20 pm
Posts: 2325
Location: Argentina
Function: Math_Power(num:Integer, index:Integer)
Returns the power of a number with a specified exponent/index

WARNING: Don't think this is a real math function. Exponents must be plain integers (1,2,3), don't try to use something like 0,3 because its not programmed like that, sadly.
Any enhancements are welcome.


Code:
//Returns the power of a number with a specified exponent/index
Export Function Math_Power(number,index);
var i;
begin
  if index < 1 then
    result := 1 //Anything to the power of 0 is 1.
  else
    result := Number;

  if index > 1 then
  for i=1 to index-1 do
  begin
    result:=result*number;
  end;
end;


Dedicated to McBenn. He might already solved this by himself. I remember he was wondering time ago.

And this is not mine. I googled it and then adapted it to OW. But hey, I'm posting it here. :P
Even more, the example that I googled had a flaw I had to fix, hehe.

_________________
-Aleph.

THE Very active person

"You can only do well at something if you put the time in. Doesn't matter what subject it is. You can't make a master piece over night."
Wise man Stu-


Top
 Profile  
 
 Post subject: Re: Math function: POWER of a number
PostPosted: Fri Feb 26, 2010 5:25 pm 
Offline
OW Support Owner
OW Support Owner
User avatar

Joined: Wed Dec 28, 2005 11:13 pm
Posts: 5001
Location: UK, Scotland
2^1 should be 2, with yours its 4. Your code would do anything to the power of Index+1. It should be:

Code:
//Returns the power of a number with a specified exponent/index
Export Function Math_Power(number,index);
var i;
begin
  if index < 1 then
    result := 1 //Anything to the power of 0 is 1.
  else
    result := Number;

  if index > 1 then
  for i=1 to index-1 do
  begin
    result:=result*number;
  end;
end;


P.S ^ = Power of in maths(Just not in SAIL).

_________________
Image
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Top
 Profile  
 
 Post subject: Re: Math function: POWER of a number
PostPosted: Fri Feb 26, 2010 6:09 pm 
Offline
Moderator
Moderator
User avatar

Joined: Fri Jan 13, 2006 6:20 pm
Posts: 2325
Location: Argentina
stucuk wrote:
P.S ^ = Power of in maths(Just not in SAIL).


I know that. Thanks for the fix. Updated.

_________________
-Aleph.

THE Very active person

"You can only do well at something if you put the time in. Doesn't matter what subject it is. You can't make a master piece over night."
Wise man Stu-


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Original War is an RTS / RPG game by Altar Games
Original War Support is not part of Altar Games but is maintaining Original War for Altar Games

Privacy Policy