Campbell Scientific CR1000KD CR1000 Measurement and Control System - Page 144
FLOAT from LONG or Boolean, LONG from FLOAT or Boolean, Integers in Expressions, Constants
View all Campbell Scientific CR1000KD manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 144 highlights
Section 7. Installation BeginProg Fa = 0 Fb = 0.125 L = 126 Ba = Fa Bb = Fb Bc = L EndProg 'This will set Ba = False (0) 'This will Set Bb = True (-1) 'This will Set Bc = True (-1) FLOAT from LONG or Boolean When a LONG or Boolean is converted to FLOAT, the integer value is loaded into the FLOAT. Booleans are converted to -1 or 0. LONG integers greater than 24 bits (16,777,215; the size of the mantissa for a FLOAT) will lose resolution when converted to FLOAT. LONG from FLOAT or Boolean When converted to Long, Boolean is converted to -1 or 0. When a FLOAT is converted to a LONG, it is truncated. This conversion is the same as the INT function (Arithmetic Functions (p. 497) ). The conversion is to an integer equal to or less than the value of the float (e.g., 4.6 becomes 4, -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. 144) illustrates evaluation of integers as LONGs and FLOATs. CRBasic Example 21. Evaluation of Integers Public X, I As Long BeginProg I = 126 X = (I+3) * 3.4 'I+3 is evaluated as an integer, then converted to FLOAT before 'it is multiplied by 3.4 EndProg 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, i.e., if the expression has not yet encountered a FLOAT. CRBasic example Constants to LONGs or FLOATs (p. 145) lists a programming case wherein a value normally considered an integer (10) is assigned by the CR1000 to be As FLOAT. 144