beetlebug▾
/

tcl::mathfunc max

Gives the largest of one or more numbers.

tcl::mathfunc::max NUMBER ?NUMBER ...?
expr {max(NUMBER, ?NUMBER, ...?)}

Description

Compares the arguments as numbers and gives the largest one as it is: an integer stays an integer and a float stays a float. Of two equal arguments the first one is the result, so max(1, 1.0) is 1. NaN is an error.

Arguments

ArgumentTypeDefaultDescription
NUMBERnumberrequiredA number.

Returns

One of the arguments.

Examples

% expr {max(3, 9, 4)}
9

% expr {max(1, 2.5)}
2.5

% expr {max(1, 1.0)}
1

# With {*}, the command form works on the elements of a list.
% tcl::mathfunc::max {*}{4 8 2}
8

Errors

% expr {max()}
not enough arguments to math function "max"
-errorcode NONE

# Tcl 9.1 only
% expr {max("a", 1)}
cannot use non-numeric string "a" as operand of "max"
-errorcode ARITH DOMAIN {non-numeric string}

# Tcl 8.6 only
% expr {max("a", 1)}
can't use non-numeric string as operand of "max"
-errorcode ARITH DOMAIN {non-numeric string}

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also