2-159
2 Instruction Descriptions
NJ-series Instructions Reference Manual (W502)
Math Instructions
2
SubOU (-OU)
The following example is for when In1 is SINT#-128, In2 is SINT#1 and variable abc has an SINT data
type. The subtraction result (−129) exceeds the valid range of SINT data, so the value of P_CY changes
to TRUE. The value of variable abc will be SINT#127 (the lower 8 bits of −129).
The functions of the SubOU instruction and the -OU instruction are exactly the same. Use the form that
is easier to use.
• When you calculate real numbers, use the CheckReal instruction (page 2-209) to see if Out is posi-
tive infinity, negative infinity, or nonnumeric data.
• Use the SUB (−) instruction (page 2-156) if there is no need for an overflow/underflow check. It will
reduce processing time.
• Set the data type of Out to include the valid ranges of In1 and In2.
• If In1, In2, and Out are integers, make sure the subtraction result will fit in the valid range of Out. Oth-
erwise, the value of Out will be an illegal value. An error will not occur.
• If the data types of In1 and In2 are different, calculations and processing of P_CY are performed with
the data type that includes the data types of In1 and In2. For example, if In1 is INT data and In2 is
DINT data, calculations and P_CY processing are performed with DINT data.
• If In1 or In2 contains real data, the value of P_CY does not change.
• Subtraction results of positive or negative infinity are handled as follows for real number values.
• If the value of either In1 or In2 is nonnumeric data, the value of Out is nonnumeric data.
Related System-defined Variables
Name Meaning Data type Description
P_CY Carry (CY) Flag BOOL TRUE: There is an overflow or underflow.
FALSE: There is no overflow or underflow.
Additional Information
Precautions for Correct Use
Subtraction Subtraction result
+∞ minus number +∞
Number minus +∞−∞
−∞
minus number −∞
Number minus −∞ +∞
+∞
minus +∞
Nonnumeric data
+∞ minus −∞ +∞
−∞
minus +∞−∞
−∞
minus −∞
Nonnumeric data
SubOU
EN ENO
In1
In2
abc:=SubOU(SINT#-128, SINT#1);
LD ST
abc
SINT#-128
SINT#1