converted to a LONG, it is truncated. This conversion is the same as the INT
function (Arithmetic Functions
(p. 568) ). The conversion is to an integer equal to or
less than the value of the float; for example, 4.6 becomes 4 and –4.6 becomes –5).
If a FLOAT is greater than the largest allowable LONG (+2,147,483,647), the
integer is set to the maximum. If a FLOAT is less than the smallest allowable
LONG (–2,147,483,648), the integer is set to the minimum.
Integers in Expressions
LONGs are evaluated in expressions as integers when possible. CRBasic example
Evaluation of Integers
(p. 163) illustrates evaluation of integers as LONGs and
FLOATs.
CRBasic Example 19. Evaluation of Integers
'This program example demonstrates the evaluation of integers.
Public I As Long
Public X As Float
BeginProg
I = 126
X = (I+3) * 3.4
'I+3 is evaluated as an integer, then converted to Float data type before it is
'multiplied by 3.4.
Constants Conversion
Constants are not declared with a data type, so the CR1000 assigns the data type
as needed. If a constant (either entered as a number or declared with CONST) can
be expressed correctly as an integer, the compiler will use the type that is most
efficient in each expression. The integer version is used if possible, for example, if
the expression has not yet encountered a FLOAT. CRBasic example Constants to
LONGs or FLOATs
(p. 163) lists a programming case wherein a value normally
considered an integer (10) is assigned by the CR1000 to be As FLOAT.
CRBasic Example 20. Constants to LONGs or FLOATs
'This program example demonstrates conversion of constants to Long or Float data types.
Public L As Long
Public F1 As Float
Public F2 As Float
Const ID = 10
BeginProg
F1 = F2 + ID
L = ID * 5
In CRBasic example Constants to LONGs or FLOATs (p. 163), I is an integer. A1
and A2 are FLOATS. The number 5 is loaded As FLOAT to add efficiently with
constant ID, which was compiled As FLOAT for the previous expression to avoid
an inefficient runtime conversion from LONG to FLOAT before each floating
point addition.
163