RosettaCodeData/Task/Averages-Simple-moving-average/PL-I/averages-simple-moving-average-1.pli
2023-07-01 13:44:08 -04:00

20 lines
452 B
Text

SMA: procedure (N) returns (float byaddr);
declare N fixed;
declare A(*) fixed controlled,
(p, q) fixed binary static initial (0);
if allocation(A) = 0 then signal error;
p = p + 1; if q < 20 then q = q + 1;
if p > hbound(A, 1) then p = 1;
A(p) = N;
return (sum(float(A))/q);
I: ENTRY (Period);
declare Period fixed binary;
if allocation(A) > 0 then FREE A;
allocate A(Period);
A = 0;
p = 0;
end SMA;