limit

limit the range of a number

Use: limit( num,  lim1, lim2 )
Description: limits a number to be within the specified range
Parameters: num integer number to be limited
lim1 first limit of the range
lim2 second limit of the range
Returns: The number limited within the range
Related:  map()


Use the limit command to restrict a number to be within the range lim1 to lim2.

If the number is between lim1 and lim2, then the returned number will be unchanged. If the number is outside the range then the returned number will be limited to either lim1 or lim2, (which ever of the two limit values is closest to the num).

Example


x = 23
y = limit(x,  100,  200)   # limit the number to be within the range 100 to 200
print y                    # prints 100,  23 is outside the range

This example takes a number x which is 23 and limits it to be within the range 100 to 200,  as 23 is outside the range, the limit command will return the closest limit value lim1 which is 100.