04.01.2015 Views

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Section 7. Installation<br />

BeginProg<br />

Fa = 0<br />

Fb = 0.125<br />

L = 126<br />

Ba = Fa 'This will set Ba = False (0)<br />

Bb = Fb 'This will Set Bb = True (-1)<br />

Bc = L 'This will Set Bc = True (-1)<br />

EndProg<br />

FLOAT from LONG or Boolean<br />

When a LONG or Boolean is converted to FLOAT, the integer value is loaded<br />

into the FLOAT. Booleans are converted to -1 or 0. LONG integers greater than<br />

24 bits (16,777,215; the size of the mantissa for a FLOAT) will lose resolution<br />

when converted to FLOAT.<br />

LONG from FLOAT or Boolean<br />

When converted to Long, Boolean is converted to -1 or 0. When a FLOAT is<br />

converted to a LONG, it is truncated. This conversion is the same as the INT<br />

function (Arithmetic Functions (p. 497) ). The conversion is to an integer equal to or<br />

less than the value of the float (e.g., 4.6 becomes 4, -4.6 becomes -5).<br />

If a FLOAT is greater than the largest allowable LONG (+2,147,483,647), the<br />

integer is set to the maximum. If a FLOAT is less than the smallest allowable<br />

LONG (-2,147,483,648), the integer is set to the minimum.<br />

Integers in Expressions<br />

LONGs are evaluated in expressions as integers when possible. CRBasic example<br />

Evaluation of Integers (p. 144) illustrates evaluation of integers as LONGs and<br />

FLOATs.<br />

CRBasic Example 21.<br />

Public X, I As Long<br />

Evaluation of Integers<br />

BeginProg<br />

I = 126<br />

X = (I+3) * 3.4<br />

'I+3 is evaluated as an integer, then converted to FLOAT before<br />

'it is multiplied by 3.4<br />

EndProg<br />

Constants Conversion<br />

Constants are not declared with a data type, so the <strong>CR1000</strong> assigns the data type<br />

as needed. If a constant (either entered as a number or declared with CONST) can<br />

be expressed correctly as an integer, the compiler will use the type that is most<br />

efficient in each expression. The integer version is used if possible, i.e., if the<br />

expression has not yet encountered a FLOAT. CRBasic example Constants to<br />

LONGs or FLOATs (p. 145) lists a programming case wherein a value normally<br />

considered an integer (10) is assigned by the <strong>CR1000</strong> to be As FLOAT.<br />

144

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!