Definition:
|
object x1 = max(object x2, object x3)
-- or --
object x1 = max(sequence s1)
|
Description:
|
Returns the largest of x2 and x3, or the largest element in sequence s1.
Atoms are considered to be less than sequences. Sequences are compared
"alphabetically" (case sensitive, ie 'a'>'Z') starting with the first
element until a difference is found.
|
Example 1:
|
x = max(7,5) -- x is 7
y = max({7,5,3}) -- y is 7
|
Example 2:
|
x = max("one","two") -- x is "two"
y = max({"one","two","three","four"}) -- y is "two"
|
See Also:
|
equal,
compare,
min,
relational operators,
sequence operations
|
Technicalia
|
max(s1) is an alias for maxsq(s1); the compiler automatically substitutes
the function being called when only one parameter is passed. However should
you code maxsq(x,y) then expect a compilation error. Both routines are
declared in builtins\pmaths.e (an auto-include). Some extra care must be taken
with routine_id("max"), as obviously no equivalent mapping occurs for the one
or two parameter cases.
The OpenEuphoria version of max() only accepts a single argument and behaves as
maxsq(flatten(s1)), whereas the Phix version is not recursive. Unlike the
OpenEuphoria version, max(<atom>) generates a runtime error, as does max({}).
This function is only compatible with OpenEuphoria when passed a single argument that
is a non-empty and non-nested sequence of atoms. Unlike several other functions there
is no separate sq_max function. Should you (for some strange reason) want
max({"one","two","three"}) to yield 'w', or max({}) to yield -inf, then may I politely
suggest that you write your own version of this routine.
|