vmin ..., vmax ...

Prev Next

Function Names

vmin, vmax, vmin 123, vmax 123, vmin numeral, vmax numeral, vmin abc, vmax abc, vmin abc ignore case, vmax abc ignore case, vmin string, vmax string, vmin string ignore case, vmax string ignore case

Description

The vmin / vmax (...) functions take exactly two function parameters and compare their contents. The contents can either be single values or sets with multiple values. See below on vectorization for this.

  • vmin, vmax: Compares values of the same type. Errors are asserted if the types differ, e.g. comparing numbers with strings.
  • vmin 123, vmax 123: Contents are converted to numbers and compared afterwards
  • vmin numeral, vmax numeral: Compares two numbers. Other types will be rejected and result in errors.
  • vmin abc, vmax abc: Contents are converted to strings and compared afterwards. e.g. 30 is string-wise greater than 200.
  • vmin abc ignore case, vmax abc ignore case: Like above, but ignores cases.
  • vmin string, vmax string: Compares two strings. Other types will be rejected and result in errors.
  • vmin string ignore case, vmax string ignore case: Like above, but ignores cases.



vmin abc and vmax abc compares strings. Numerals and other types will be converted to strings before comparing. If the numerals or dates contain text representations, e.g. vmin abc(02, 1) then 1 is alphabetically the bigger value. The results are always strings.

Vectorization: This function supports vectorization in the 1st and 2nd function parameters. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st and 2nd function parameters

Parameter count

2

Parameters

No.TypeDescription
1, 2
input
valid types
set
2 Values to compare

The two values or set of values will be compared.

Return value

TypeDescription
valid types
set
Result

Calculated result. If vectorization is used, then a set containing the results is returned.

Exceptions

Attempting to compare incompatible types, e.g. numerals with strings

Examples

a[] = { { 1, 2, 3 }, { 6, 5, 4 }};
b[] = { { 4, 2, 0 }, { 1, 3, 5 }};
s[] = { Hello, Ahoi, He, Huh };
t[] = { Hallo, Ho,   Hi, Hey };

echo( new line, "vmin:");
echo( vmin( 1, 2 ) ); // The simple way
echo( vmin( a[], b[] ) );
echo( vmin( a[], 3 ) );
echo( vmin( a[], {{ 2, 1, 4 }, 5 } ) );
echo( vmin( s[], t[] ) );
echo( vmin( {10.02.2024, 02.08.2024}, {11.02.2024,01.08.2024} ) );
echo( vmin( {true, false}, {false, true} ) );

echo( new line, "vmax:");
echo( vmax( 1, 2 ) ); // The simple way
echo( vmax( a[], b[] ) );
echo( vmax( a[], 3 ) );
echo( vmax( a[], {{ 2, 1, 4 }, 5 } ) );
echo( vmax( {10.02.2024, 02.08.2024}, {11.02.2024,01.08.2024} ) );
echo( vmax( {true, false}, {false, true} ) );

a[] = { 100, "100", 30,   5, abc, Text };
b[] = { 2,   "2",   200, 05, DEF, ''   };

echo(new line, "Comparing ", a[], " with ", b[] );
echo( "vmin abc: ", vmin abc( a[], b[] ), ' ignore case: ', vmin abc ignore case( a[], b[] ) );
echo( "vmax abc: ", vmax abc( a[], b[] ), ' ignore case: ', vmax abc ignore case( a[], b[] ) );
echo( "vmin 123: ", vmin 123( a[], b[] ) );
echo( "vmax 123: ", vmax 123( a[], b[] ) );

Output

vmin:
1
{{1,2,0},{1,3,4}}
{{1,2,3},{3,3,3}}
{{1,1,3},{5,5,4}}
{'Hallo','Ahoi','He','Hey'}
{'10.02.2024','01.08.2024'}
{false,false}

vmax:
2
{{4,2,3},{6,5,5}}
{{3,3,3},{6,5,4}}
{{2,2,4},{6,5,5}}
{'11.02.2024','02.08.2024'}
{true,true}

Comparing {100,'100',30,5,'abc','Text'} with {2,'2',200,05,'DEF',''}
vmin abc: {'100','100','200','05','DEF',''} ignore case: {'100','100','200','05','abc',''}
vmax abc: {'2','2','30','5','abc','Text'} ignore case: {'2','2','30','5','DEF','Text'}
vmin 123: {2,2,30,5,0,0}
vmax 123: {100,100,200,5,0,0}
Try it yourself: Open LIB_Function_vmin.b4p in B4P_Examples.zip. Decompress before use.

See also

min
max
min 123
max 123
min numeral
max numeral
min abc
max abc
min string
max string
min abc ignore case
max abc ignore case
min string ignore case
max string ignore case