LIMIT¶
Clamps a value to a specified range.
Signature¶
┌─────────┐
MN ─┤ │
IN ─┤ LIMIT ├─ OUT
MX ─┤ │
└─────────┘
FUNCTION LIMIT : ANY
VAR_INPUT
MN : ANY;
IN : ANY;
MX : ANY;
END_VAR
END_FUNCTION
The return type matches the input type. LIMIT accepts SINT,
INT, DINT, LINT, USINT, UINT, UDINT, ULINT,
REAL, LREAL. All three inputs must share the same type.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Lower bound of the range. |
|
|
Value to clamp. |
|
|
Upper bound of the range. |
Outputs
Name |
Type |
Description |
|---|---|---|
Return value |
|
IN clamped to [MN, MX]. Same type as the inputs. |
Description¶
LIMIT(MN, IN, MX) clamps IN to the range [MN, MX]. The
function returns:
MN if IN < MN
MX if IN > MX
IN otherwise
The behavior is undefined if MN > MX.
Example¶
result := LIMIT(0, 50, 100); (* result = 50 *)
result := LIMIT(0, -10, 100); (* result = 0 *)
result := LIMIT(0, 200, 100); (* result = 100 *)
See Also¶
References¶
IEC 61131-3 §2.5.1.5.5