Absolute value
ABS calculates the value in the accumulator into an absolute value. The result is saved in the output variable.
Input
Input data type
Output
Output as input: absolute value
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
input_value: INT:=-123;
output_value: INT:=0;
END_VAR
This example uses variables. You can also use a constant for the input variable.
input_value of the data type INTEGER is converted into an absolute value of the data type INTEGER. The converted value is written into absolute_value.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,ABS!,Instance,8,2,13,4,,?D?C);
B(B_VARIN,,input_value,6,2,8,4,);
B(B_VAROUT,,output_value,13,2,15,4,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
absolute_value:=ABS(input_value);
LD |
input_value |
ABS |
|
ST |
absolute_value |