iDevOS CALC "MAX" Command

Get the maximum value from a set of variables or an array of variables.

Description

CALC( y, a, b, "MAX" );     // y = max(a, b) = maximum of a, b
CALC( y, a, b, c, "MAX" );  // y = max(a, b, c) = maximum of a, b, c
CALC( y, array, "MAX" );    // y = max(array) = maximum value in array

If the parameters passed to this command are two or three individual variables (a, b, c) then this command returns the maximum value y of these variables. If an array is passed to this command then the returned value y is the maximum value found in the array.

See "MIN" to get the minimum value.

Parameters

y
Calculation result.
Parameter type: entity name of a numeric variable (eg U8, S32, FLT3 etc).
a, b and c
Input values.
Parameter type: immediate number, or entity name of a numeric variable (eg U8, S32, FLT3 etc).
Input array.
Parameter type: entity name of a numeric array (eg U8 array, S32 array, FLT3 array etc).
"MAX"
CALC command operator.
Parameter type: immediate string.

Examples

Example 1

  VAR(d, 0, S32);
  
  CALC(d, 10, 20, "MAX");      // d = 20
  CALC(d, 100, -69, 5, "MAX"); // d = 100

Example 2

VAR(arr, 0, S8, 6); // create array of size 6
VAR(res, 0, S8);    // result

// Initialise array: arr = { 5, -12, 0, 90, -15, 0 }
LOAD(arr.0, 5);
LOAD(arr.1, -12);
LOAD(arr.3, 90);
LOAD(arr.4, -15);

CALC(res, arr, "MAX"); // res = 90