Skip to content

CLAMP Expression

CLAMP constrains a numeric value to a minimum and maximum.

Syntax

CLAMP{value,min,max}

All three arguments are parsed as numbers. min must not be greater than max; the production implementation rejects that case.

Behavior

  • values below min return min;
  • values above max return max;
  • values already inside the range are returned unchanged.

Examples

These forms are already covered by ACE's expression tests:

CLAMP{5,0,10}           -> 5
CLAMP{-3,0,10}          -> 0
CLAMP{15,0,10}          -> 10
CLAMP{CALC{2+3},1,9}    -> 5