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 SINT, INT, DINT, LINT, REAL, LREAL.

Inputs

Name

Type

Description

IN

ANY_NUM

The numeric value to compute the absolute value of.

Outputs

Name

Type

Description

Return value

ANY_NUM

The non-negative magnitude of IN. Same type as IN.

Description

Returns the absolute value of IN. For signed integer types, the result of ABS applied to the most negative value is undefined because the positive value cannot be represented.

Example

result := ABS(-42);    (* result = 42 *)
value := ABS(REAL#-3.14);  (* value = 3.14 *)

See Also

  • SQRT — square root

  • EXPT — exponentiation

References