Skip to content
ezeioDocs
  1. Reference
  2. Script reference
  3. Math and control

CLAMP

Macro that will return a value limited to a given range

Description#

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.

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

Last updated Nov 19, 2019