math.max
Defined in module
"math"from "math" import maxpure fastcall max(x: number, y: number, ...: number): number
Returns the maximum value from the arguments
Parameters
x | number | a number to compare |
y | number | a number to compare |
... | number | more numbers to compare repeats |
Return value
The largest argument, returned unchanged.
Errors
Throws parameter N of 'max' has an invalid type when an argument is not a number, and wrong number of parameters passed to native closure 'max' when called with fewer than two arguments.
Notes
The winner is returned as the original object, so the result keeps its own type and not x's: type(max(5, 8.0)) is float because 8.0 is the larger value, while type(max(8, 5.0)) is integer because 8 is larger. When two arguments compare equal, the earlier one in the argument list is kept.
Every argument is reported by the function's own name and by its true position, whether it was matched by x, by y, or by the trailing ....
Example
from "math" import max
println("max(3, 1, 2) =", max(3, 1, 2))
println("max(-1.5, 2) =", max(-1.5, 2))
// the larger value is returned as is, so its own type wins, not x's
println("type(max(5, 8.0)) =", type(max(5, 8.0)))
println("type(max(8, 5.0)) =", type(max(8, 5.0)))
try {
max(1)
} catch (e) {
println("max(1) throws:", e)
}Output:
max(3, 1, 2) = 3
max(-1.5, 2) = 2
type(max(5, 8.0)) = float
type(max(8, 5.0)) = integer
max(1) throws: wrong number of parameters passed to native closure 'max' (2 passed, at least 3 required)See also
min | Returns the minimum value from the arguments |
clamp | Clamps x to the range [min, max] |
| math | module index |