Clamp

clamp

Description:
Function clamp brings the number to the specified range.
This function name starts with a lowercase letter.


Parameters:
(value, min = cellmin, max = cellmax)
int value The value to force in a range.
int min The low bound of the range.
int max The high bound of the range.


Return Values:
value, if it is in the range min–max, min, if value is lower than min or max, if value is higher than max.


Examples:
new
    valueA = 3,
    valueB = 7,
    valueC = 100
;
printf("The value is: %d", clamp(valueA, 5, 10)); // output: "The value is: 5" because 3 is less than 5.
printf("The value is: %d", clamp(valueB, 5, 10)); // output: "The value is: 7" because 7 is between 5 and 10.
printf("The value is: %d", clamp(valueC, 5, 10)); // output: "The value is: 10" because 100 is more than 10.


Related Functions
The following functions may be useful, as they are related to this function in one way or another.
  • min: Specifies the smallest of the two numbers.
  • max: Specifies the highest of the two numbers.