Specifications

Section 9. CR1000 Programming
9-23
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, and Totalize.
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 Wikipedia.org. In summary, CR1000
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 <= instead.
For example, use “If X => Y, then do” rather than using, “If X = Y, then
do”.
Avoid extended cyclical summation of non-integers. This applies to the
output processing instruction Totalize as well as user coded totalizing
routines. As the size of the sum increases, fractional addends will have
ever decreasing effect on the magnitude of the sum, because floating point
numbers are limited to about 7 digits of resolution.
9.13.2 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
EXAMPLE 9.13-1 shows example code to
convert twenty temperatures in a
variable array from C to F:
EXAMPLE 9.13-1. CRBASIC Code: Use of variable arrays to save code space.
For I = 1 to 20
TCTemp(I) = TCTemp(I) * 1.8 + 32
Next I
9.13.3 Expressions with Numeric Data Types
FLOATs, LONGs and Booleans are cross-converted to other data types, such
as FP2, by using “=”
9.13.3.1 Boolean from FLOAT or LONG
When a FLOAT or LONG is converted to a Boolean as shown in EXAMPLE
9.13-2, zero becomes False (0) and non-zero becomes True (-1).
NOTE