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 />

7.7.3.9.2 Mathematical Operations<br />

7.7.3.9.3 Expressions with Numeric Data Types<br />

Note Single-precision float has 24 bits of mantissa. Double precision has a 32-bit<br />

extension of the mantissa, resulting in 56 bits of precision. Instructions that use<br />

double precision are AddPrecise(), Average(), AvgRun(), AvgSpa(), CovSpa(),<br />

MovePrecise(), RMSSpa(), StdDev(), StdDevSpa(), and Totalize().<br />

Floating-point arithmetic is common in many electronic, computational systems,<br />

but it has pitfalls high-level programmers should be aware of. Several sources<br />

discuss floating-point arithmetic thoroughly. One readily available source is the<br />

topic Floating Point at www.wikipedia.org. In summary, <strong>CR1000</strong> programmers<br />

should consider at least the following:<br />

• Floating-point numbers do not perfectly mimic real numbers.<br />

• Floating-point arithmetic does not perfectly mimic true arithmetic.<br />

• Avoid use of equality in conditional statements. Use >= and = Y then do rather than If X = Y then do.<br />

• When programming extended-cyclical summation of non-integers, use the<br />

AddPrecise() instruction. Otherwise, as the size of the sum increases,<br />

fractional addends will have an ever decreasing effect on the magnitude of<br />

the sum, because normal floating-point numbers are limited to about 7 digits<br />

of resolution.<br />

Mathematical operations are written out much as they are algebraically. For<br />

example, to convert Celsius temperature to Fahrenheit, the syntax is:<br />

TempF = TempC * 1.8 + 32<br />

Read More! To save code space while filling an array or partial array with the<br />

same value, see CRBasic example Use of Move() to Conserve Code Space (p. 150).<br />

CRBasic example Use of Variable Arrays to Conserve Code Space (p. 150) shows<br />

example code to convert twenty temperatures in a variable array from °C to °F.<br />

FLOATs, LONGs and Booleans are cross-converted to other data types, such as<br />

FP2, by using "=".<br />

Boolean from FLOAT or LONG<br />

When a FLOAT or LONG is converted to a Boolean as shown in CRBasic<br />

example Conversion of FLOAT / LONG to Boolean (p. 143), zero becomes false<br />

(0) and non-zero becomes true (-1).<br />

CRBasic Example 20.<br />

Conversion of FLOAT / LONG to Boolean<br />

Public Fa As Float<br />

Public Fb As Float<br />

Public L As Long<br />

Public Ba As Boolean<br />

Public Bb As Boolean<br />

Public Bc As Boolean<br />

143

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

Saved successfully!

Ooh no, something went wrong!