Campbell Scientific CR6 CR6 Measurement and Control System - Page 162
Floating-Point Arithmetic, 8.3.10.2, Mathematical Operations, 8.3.10.3, Expressions
View all Campbell Scientific CR6 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 162 highlights
Section 7. Installation 7.8.3.10.1 7.8.3.10.2 Consider the expressions: x = (z * 1.8) + 32 '(mathematical expression) If x = 23 then y = 5 '(programming expression) The variable x can be omitted and the expressions combined and written as: If (z * 1.8 + 32 = 23) then y = 5 Replacing the result with the expression should be done judiciously and with the realization that doing so may make program code more difficult to decipher. Floating-Point Arithmetic Variables and calculations are performed internally in single-precision IEEE fourbyte floating point with some operations calculated in double precision. Note Single-precision float has 24 bits of mantissa. Double precision has a 32-bit extension of the mantissa, resulting in 56 bits of precision. Instructions that use double precision are AddPrecise(), Average(), AvgRun(), AvgSpa(), CovSpa(), MovePrecise(), RMSSpa(), StdDev(), StdDevSpa(), Totalize(), and TotRun(). Floating-point arithmetic is common in many electronic, computational systems, but it has pitfalls high-level programmers should be aware of. Several sources discuss floating-point arithmetic thoroughly. One readily available source is the topic Floating Point at www.wikipedia.org. In summary, CR6 programmers should consider at least the following: • Floating-point numbers do not perfectly mimic real numbers. • Floating-point arithmetic does not perfectly mimic true arithmetic. • Avoid use of equality in conditional statements. Use >= and = Y then do rather than If X = Y then do. • When programming extended-cyclical summation of non-integers, use the AddPrecise() instruction. Otherwise, as the size of the sum increases, fractional addends will have an ever decreasing effect on the magnitude of the sum, because normal floating-point numbers are limited to about 7 digits of resolution. Mathematical Operations Mathematical operations are written out much as they are algebraically. For example, to convert Celsius temperature to Fahrenheit, the syntax is: TempF = TempC * 1.8 + 32 Read More To save code space while filling an array or partial array with the same value, see CRBasic example Use of Move() to Conserve Code Space. CRBasic example Use of Variable Arrays to Conserve Code Space shows example code to convert twenty temperatures in a variable array from °C to °F. 7.8.3.10.3 Expressions with Numeric Data Types FLOATs, LONGs and Booleans are cross-converted to other data types, such as FP2, by using '='. 162