2 - 17 2 - 17
MELSEC-Q
2 THE BASICS OF AD51H-BASIC
2.9 Type Conversion
BASIC changes the type of numeric constants to another type as needed. In this case,
it follows the following rules.
(1) When a numeric constant of a certain type is assigned to a numeric variable of a
different type, the value of the constant will be changed to the type declared in the
variable name and stored. (If a numeric value is assigned to a character string
variable, or vice versa, a “Type mismatch” error will occur.)
Example
10 A% =23.42
20 PRINT A%
RUN
23
OK
(2) If an expression contains different types of numeric constants or numeric
variables, the operation result will be as follows.
• When two values are used for an operation:
Value 1
Value 2
Operation Result
Integer
Integer
Integer
Integer
Single-precision real number
Single-precision real number
Integer
Double-precision real number
Double-precision real number
Single-precision real number
Single-precision real number
Single-precision real number
Single-precision real number
Double-precision real number
Double-precision real number
Double-precision real number
Double-precision real number
Double-precision real number
(The result is the same when Value 1 and Value 2 are reversed.)
Example
10 D#=6#/7
20 PRINT D#
RUN
.8571428571428571
OK
Since double-precision is divided by single-precision here,
the arithmetic operation is performed in double-precision.
The result will be assigned to D# as a double-precision value.
………………
(3) When a logical operation is performed, numeric constants and numeric variables
within the expression are converted to integers before carrying out the operation.
The value must be within the range from –32768 to 32767. An “Overflow” error
will occur if this range is exceeded.