Mitsubishi Electric MELSEC iQ-R Series Programming Manual page 70

Hide thumbs Also See for MELSEC iQ-R Series:
Table of Contents

Advertisement

■ When a sign inversion operator is used in the arithmetic operational expression
If a sign inversion operator is used for the minimum value of each data type, the value remains unchanged.
For example, the minimum value of INT type data will be -(-32768) = -32768.
If a sign inversion operator is used for variables targeted for automatic conversion of data type, an intended operation result
may not be obtained.
Ex.
When the value of varInt1 (INT type) is -32768 and the value of varDint1 (DINT type) is 0
varDint2 := -varInt1 + varDint1;
In this program, the value of (-varInt1) remains unchanged. Therefore, the value, -32768, is assigned to varDint2.
To use a sign inversion operator in an arithmetic operational expression, automatically convert data type before the arithmetic
operation or do not use a sign inverted operator in the program.
Ex.
When data type is automatically converted before the arithmetic operation
varDint3 := varInt;
varDint2 := -varDint3 + varDint1;
Ex.
When a sign inversion operator is not used
varDint2 := varDint1 - varInt1
■ When the data type is converted from single-precision real number to double-precision real
number
When the type conversion function, REAL_TO_LREAL, is executed, an error may occur in the conversion result.
Consequently, when the data type is automatically converted or when a function with a return value of real number type (such
as SIN function) is used as the right side of an assignment statement or an operand of arithmetic operational expression, an
intended operation result may not be obtained.
Ex.
An error occurs.
varReal1 := -1234.567;
varLReal1 := ABS(varReal1);
In the above program, the data type of the return value of ABS(varReal1) is single-precision real number. Since the return
value is converted to a double-precision real number and assigned to varReal1, an error occurs.
Create a program using a function with the data type same as the assignment target.
Ex.
No error occurs.
varLReal2 := -1234.567;
varLReal1 := ABS(varLReal2);
6 STRUCTURED TEXT LANGUAGE
68
6.1 Configuration

Advertisement

Table of Contents
loading

Table of Contents