SRL Archive - SRL Suggestions

AverageIntegerArray


Sir R. M8gic1an

2009-04-25 21:26:24

if this was ported to delphi and into wizzypluggin it might be nice…


Function AverageIntegerArray(TIA: TIntegerArray): integer;
var
i, t :integer;
begin
t := High(TIA);
for i := 0 to t do
Result := Result + TIA[i];

Result := Round(Result / Length(TIA));
end;

~RM

lordsaturn

2009-04-25 22:10:06

Added, thanks.

Sandstorm

2009-04-25 23:35:42

Lmao, I made one of these a while ago. It's like… 17 lines long xD.

~Sandstorm

Nava2

2009-04-26 08:33:19

Also added AverageExtended

Method

2009-04-26 10:03:09

Does SCAR truncate integers after division? If so, you probably wouldn't need Round in there at all.

EDIT: Nevermind, I'm tired. :(

senrath

2009-04-26 10:11:39

From: Method
Does SCAR truncate integers after division? If so, you probably wouldn't need Round in there at all.


Truncation is different from rounding. To demonstrate, run this:

program New;
begin
Writeln(IntToStr(Round(6.55)));
Writeln(IntToStr(655/100));
end.

Method

2009-04-26 10:20:02

Oh, whoops. I probably should get some sleep, considering this has happened multiple times recently.

n3ss3s

2009-04-26 13:01:21

In the day you didn't get functions to SRL like that :<

http://www.villavu.com/forum/showthread.php?t=2104

Naum

2009-04-26 13:18:53

Yeah, seems that he is a mod so he gets to do that :p

Nava2

2009-04-27 17:32:32

Getting off topic… closed. :)