Macro that will return a value limited to a given range


CLAMP( value, minimum, maximum )

Returns the value if it is within the range minimum to maximum.

If the value is smaller than minimum, returns minimum.

If the value is larger than maximum, returns maximum.

Works with both float and integer parameters.


value input value
minimum smallest allowed value
maximum largest allowed value

Return value

Returns the value limited to within the given range.

Example usage

   new n, x;
   n = 60;
   x = CLAMP(n, 30, 90);   // 60
   x = CLAMP(n, 10, 20);   // 20
  • ezeio2/scriptref/clamp.txt
  • Last modified: 2019-11-19 00:19
  • by andreh