ABS¶
Returns the absolute value of a numeric input.
Signature¶
┌─────────┐
IN ─┤ ABS ├─ OUT
└─────────┘
FUNCTION ABS : ANY_NUM
VAR_INPUT
IN : ANY_NUM;
END_VAR
END_FUNCTION
The return type matches the input type. ABS accepts every numeric
type: SINT, INT, DINT, LINT, USINT, UINT, UDINT,
ULINT, REAL and LREAL.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
The numeric value to compute the absolute value of. |
Outputs
Name |
Type |
Description |
|---|---|---|
Return value |
|
The non-negative magnitude of IN. Same type as IN. |
Description¶
Returns the absolute value of IN. For unsigned integer types, the result
is IN itself. For signed integer types, the result of ABS applied to
the most negative value is undefined because the positive value cannot be
represented.
When IN is an integer literal, the result is computed when compiling:
ABS(-42) is the constant 42. ABS(SINT#-128) is 128, which is
not a SINT, so it is reported as
P2026.
Example¶
result := ABS(-42); (* result = 42 *)
value := ABS(REAL#-3.14); (* value = 3.14 *)
See Also¶
References¶
IEC 61131-3 §2.5.1.5.2