262 Rockwell Automation Publication 1756-RM003N-EN-P - October 2011
Chapter 6 Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
You can mix data types, but loss of accuracy and rounding error might occur and
the instruction takes more time to execute. Check the S:V bit to see whether the
result was truncated.
For relay ladder instructions, bold data types indicate optimal data types. An
instruction executes faster and requires less memory if all the operands of the
instruction use the same optimal data type, typically DINT or REAL.
Compute (CPT)
The CPT instruction performs the arithmetic operations you define in the
expression.
Operands:
Relay Ladder
Structured Text
Structured text does not have a CPT instruction, but you can achieve the same
results by using an assignment and expression.
destination := numeric_expression;
See Structured Text Programming
for information on the syntax of assignments
and expressions within structured text.
Calculate the square root of a value SQR
SQRT
(3)
Relay ladder
Structured text
Function block
283
Take the opposite sign of a value NEG Relay ladder
Structured text
(2)
Function block
286
Take the absolute value of a value ABS Relay ladder
Structured text
Function block
289
(1) There is no equivalent structured text instruction. Use other structured text programming to achieve the same result. See the description for the instruction.
(2) There is no equivalent structured text instruction. Use the operator in an expression.
(3) Structured text only.
If you want to Use this instruction Available in these languages Page
Operand Type Format Description
Destination SINT
INT
DINT
REAL
Tag Tag to store the result
Expression SINT
INT
DINT
REAL
Immediate Tag An expression consisting of tags and/or
immediate values separated by operators
A SINT or INT tag converts to a DINT value by sign-extension.