Maximal-/Minimal-Value Expression Functions

On This Page
Note
  • min and max are supported in update expressions.

  • Regarding the use of the min and max functions with arrays, note that in the current release this is restricted to the web APIs.

max

The max function supports the following variations:

Compare Simple Values

max(a, b)

When max receives two parameters, it returns the highest (maximal) parameter value. The function supports comparison of Boolean, numeric, and string values. The values can also be provided as expressions (for example, attr1+attr1 or attr1==attr2).

For example, given attr1, attr2, and attr3 attributes with the respective values 5, 1, and 6, "max(attr1, attr2+attr3)" returns the sum of attr2 and attr3 — 7.

Note
  • Strings are compared using lexicographic string comparison.
  • Numeric values of different data types are compared using numeric promotion. The type of the return value is that of the largest data type from among the compared values. For example, "max(1.0, 9) returns 9.0 (double).
  • Boolean values are implicitly converted to numbers to allow comparison — true = 1 and false = 0. However, the data type of the function's return value in the case of a Boolean operand is the winning data type — i.e., the original data type of the returned value. For example, "max(1==1, 1==2)" and "max(1==1, 0)" both return true (Boolean), but "max(1==1, 3)" returns 3 (integer).

Compare Array Elements

max(ARRAY)

When max receives a single array or array-slice parameter (ARRAY), it returns the highest (maximal) value from among the values of all elements of the specified array or array slice. The parameter can be the name of an array attribute (ARRAY-ATTRIBUTE), or a slice of an array attribute that indicates the zero-based index range of the array elements to compare (ARRAY-ATTRIBUTE[istart..iend]).

For example, for a myArray integer-array attribute with the values 7, 13, 5, and 1, "max(myArray)" returns 13 and "max(myArray[2..3])" returns 5.

min

The min function supports the following variations:

Compare Simple Values

min(a, b)

When min receives two parameters, it returns the lowest (minimal) parameter value. The function supports comparison of Boolean, numeric, and string values. The values can also be provided as expressions (for example, attr1+attr1 or attr1==attr2).

For example, given attr1, attr2, and attr3 attributes with the respective values 5, 1, and 6, "min(attr1, attr2+attr3)" returns the value of attr1 — 5.

Note
  • Strings are compared using lexicographic string comparison.
  • Numeric values of different data types are compared using numeric promotion. The type of the return value is that of the largest data type from among the compared values. For example, "min(1, 9.0) returns 1.0 (double).
  • Boolean values are implicitly converted to numbers to allow comparison — true = 1 and false = 0. However, the data type of the function's return value in the case of a Boolean operand is the winning data type — i.e., the original data type of the returned value. For example, "min(1==1, 1==2)" and "min(1==2, 1)" both return false (Boolean), but "min(1==1, 0)" returns 0 (integer).

Compare Array Elements

min(ARRAY)

When min receives a single array or array-slice parameter (ARRAY), it returns the lowest (minimal) value from among the values of all elements of the specified array or array slice. The parameter can be the name of an array attribute (ARRAY-ATTRIBUTE), or a slice of an array attribute that indicates the zero-based index range of the array elements to compare (ARRAY-ATTRIBUTE[istart..iend]).

For example, for a myArray integer-array attribute with the values 7, 13, 5, and 1, "min(myArray)" returns 1 and "min(myArray[1..2])" returns 5.

See Also