Chapter 5. Data Types
69
5.4 Type Conversion
5.4.1 Type Conversion
BHT-BASIC has the type conversion facility which automatically converts a value of one data
type into another data type during value assignment to numeric variables and operations;
from a real number into an integer number by rounding off, and vice versa, depending upon
the conditions.
• The Interpreter automatically converts a value of a real into an integer, in any of the
following cases:
- Assignment of real expressions to integer variables
- Operands for an arithmetic operator MOD
- Operands for logical operators: AND, OR, NOT, and XOR
- Parameters for functions
- File numbers
In the type conversion from real into integer, the allowable value range of resultant
integer is limited as shown below. If the resultant integer comes out of the limit, a
run-time error will occur.
-32768 ≤resultantintegervalue ≤+32767
• In assignments or operations from integer to real, the type-converted real will have
higher accuracy:
Syntax: realvariable = integerexpression
In the above case, the Interpreter applies the type conversion to the evaluated
resultant of the integer expression before assigning the real value to the real variable.
Therefore, a in the following program will result in the value of 184.5.
a=123%*1.5
Komentáře k této Příručce