maxx


The maxx function returns the maximum value of a general lua table that may contain non-numeric values, named keys, and sub-tables. Only numeric values found in the table are used in the calculation. The related max function returns the maximum value of a 1-dimensional array, CImage, or list of numbers. Since an array is a specific type of table that contains only numbers or sub-tables, this function can also be used for arrays.

Syntax

nMax = ( tbl )

bullet.gif    tbl is a general lua table.

bullet.gif    nMax is returned as the maximum value found in tbl. If tbl contains no numbers, the huge negative number -1.e308 is returned.

Examples

The following script returns the minimum value for an ugly table:

t = { { 1, "c", a=-12, dar={17,"v"} }, {-15, 24, 3, "55"} }

-- create a table

v = ( t )

-- find the maximum

Printf("Max = %lg\n", v )

-- Result: Max = 24

  

The next script returns the minimum value for a 2-dimensional array with no keys or non-numeric values:

row = {}

-- setup a table of rows

for j = 1, 4 do

-- for each row

  col = {}

-- create a column table

  for i = 1,3 do

-- for each column

    col[i] = i*j

-- assign the value to the column

  end

 

  row[j] = col

-- assign the column table to the row

end

 

v = ( row )

-- calculate the maximum of the array of 12 elements

Printf("Max = %lg\n", v )

-- Result: Min = 12

Related Topics

Table and Array Functions, max, minn


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.