.BusinessSimulation.Functions.shiftList

Information

This information is part of the Business Simulation Library (BSL). Please support this work and ► donate.

The function will return a list shifted by n places (n < 0 ⇒ shift to the left), where the elements "pushed" out of range are added up and reported as carry. The gaps will be shifted with the real value fill, which by default is set to 0.

Syntax


Functions.shiftList( list, n );        // fill by default is set to zero
Functions.shiftList( list, n, fill );  // explicitly give a real value for fill

Examples

shiftList( {1, 2, 3, 4, 5},  0);   // ( {1, 2, 3, 4, 5}, 0. )
shiftList( {1, 2, 3, 4, 5}, -2); // ( {3, 4, 5, 0, 0}, 3. )
shiftList( {1, 2, 3, 4, 5}, 2); // ( {0, 0, 1, 2, 3}, 9. )

Interface

function shiftList
  extends BusinessSimulation.Icons.Function;
  input Real[:] list "List of values to be shifted";
  input Integer n "Number of steps to shift the list( n < 0 => shift to the left)";
  input Real fill = 0 "Value to fill the gaps with (default = 0)";
  output Real[size(list, 1)] shiftedList "Shifted list";
  output Real carry "Sum of elements that were pushed out of range by the shift";
end shiftList;

Revisions


Generated at 2024-12-21T19:25:56Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos