Subtraction - Mitsubishi Electric MELSEC iQ-R Series Programming Manual

Motion module instructions, standard functions/ function blocks
Hide thumbs Also See for MELSEC iQ-R Series:
Table of Contents

Advertisement

14.3

Subtraction

SUB
This function outputs the difference between input values ((s1)-(s2)).
Structured text
d:=SUB(s1,s2);
Setting data
■Description, type, data type
Argument
Description
s1 (IN1)
Input
s2 (IN2)
Input
d
Output
Processing details
■Operation processing
• This function performs subtraction between the INT, DINT, WORD, DWORD, REAL, or LREAL data type values input to
(s1) and (s2) ((s1)-(s2)), and output the operation result, in the same data type as (s), from (d).
Ex.
Data type: INT
(s1)
(s2)
12345
-
6789
INT
INT
• Input an INT, DINT, WORD, DWORD, REAL, or LREAL data type value to (s1) and (s2).
• If an underflow or overflow occurs in the operation result, the output from (d) will be as follows.
Data type
Description
INT
Even if an underflow or overflow occurs, no operation error is issued.
[Example 1]
32767-(-2)=-32767
(7FFFH)-(FFFEH)=(8001H)
A negative value results because the most significant bit is 1.
[Example 2]
-32767-2=32766
(8000H)-(0002H)=(7FFEH)
A positive value results because the most significant bit is 0.
DINT
Even if an underflow or overflow occurs, no operation error is issued.
[Example 1]
2147483647-(-2)=-2147483647
(7FFFFFFFH)-(0000FFFEH)=(80000001H)
A negative value results because the most significant bit is 1.
[Example 2]
-2147483648-2=2147483646
(80000000H)-(00000002H)=(7FFFFFFEH)
A positive value results because the most significant bit is 0.
WORD
Even if an underflow occurs, no operation error is issued.
[Example]
0 - 1 = 65535
(0000H) - (0001H) = (FFFFH)
DWORD
Even if an underflow occurs, no operation error is issued.
[Example]
0 - 1 = 4294967295
(00000000H) - (00000001H) = (FFFFFFFFH)
REAL
An operation error occurs and an undefined value is output.
LREAL
(d)
5556
INT
14 ARITHMETIC OPERATION FUNCTIONS
Type
Data type
Input variable
ANY_NUM
Input variable
ANY_NUM
Output variable
ANY_NUM
14.3 Subtraction
14
181

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents