Cicode Programming Reference > Cicode Function Categories > Table (Array) Functions Introduction > TableMath


Performs mathematical operations on a table of real (floating-point) numbers. This function supports minimum, maximum, average, standard deviation, and total operations on a table of values. Use this function for operating on tables returned from the trend system with the TrnGetTable() function. You can set the Mode to either accept or ignore invalid or gated data returned from TrnGetTable().

This function cannot check the length of any arrays passed to it. If the array is shorter than the size argument, unpredictable results can occur, such as data in memory being overwritten, or a general protection fault.

This function only supports arrays declared in Cicode and not variable tag arrays.



Always confirm that arrays are of appropriate length before passing them to the TableMath function.

Failure to follow these instructions can result in death, serious injury, or equipment damage.


TableMath(Table, Size, Command [, Mode] )


Any table of floating-point numbers.


The maximum number of items in the table.


The mathematical operation to perform on the table:

0 - Minimum

1 - Maximum

2 - Average

3 - Standard deviation

4 - Total


The mode of the operation:

0 - Operate on all data - default

1 - Ignore invalid or gated data returned from the TrnGetTable() function

Return Value

Returns the value related to the requested mathematical operation performed on the table (Minimum, Maximum, Average, Standard deviation or Total).\

Related Functions

TableLookup TrnGetTable


REAL Array[5]=10,15,50,100,200;
REAL Min,Avg;
! Get the minimum value.
Min=TableMath(Array, 5, 0, 0); ! Sets Min to 10.
! Get the average value.
Avg=TableMath(Array, 5, 2, 0); ! Sets Avg to 75.

See Also

Table (Array) Functions