clamp
Restrict an integer to an inclusive minimum and maximum range.
Signature
func clamp(num int, min int, max int) int
Parameters
num— the integer to restrict.min— the lowest permitted result.max— the highest permitted result.
Return Value
The intended result is:
numwhen it is already within the range;minwhennumis less thanmin;maxwhennumis greater thanmax.
Example
var volume = clamp(120, 0, 100)
print(volume)
The example writes 100 to standard output.