beautypg.com

11 expressions – Campbell Scientific CR9000X Measurement and Control System User Manual

Page 162

background image

Section 4. CRBasic – Native Language Programming

4.2.11 Expressions

An expression is a series of words, operators, or numbers that produce a value
or result. Expressions are evaluated from left to right, with deference to
precedence rules. Table 4.2.11-1 lists the order of precedence for the operators
supported by the CR9000X. The result of each stage of the evaluation is of
type Long (integer) if the variables are of type Long (constants are integers) and
the functions give integer results, such as occurs with INTDV (). If part of the
equation has a floating point variable or constant, or a function that results in a
floating point, the rest of the expression will be evaluated using floating point
math, even if the final function is to convert the result to an integer; e.g. INT
((rtYear-1993)*.25). This is a critical feature to consider when:

1) trying to use Long integer math to retain numerical resolution beyond the

limit of floating point variables (24 bits), or

2) if the result is to be tested for equivalence against another value.

Table 4.2.11-1 Precedence ranking of operators

Rank Symbols

Functions

1

^

Raise to power

2

+, -
NOT

Positive, Negative
Logical Negation

3

*, /

INTDV, MOD

Multiply, Divide
Integer division, Modulo divide

4

+, -,
+, &

Addition, Subtraction,
String concatenation

5

=, <>
<, <=
>, >=
IS

Equal, Not equal
Less than, Less than or equal
Greater than, Greater than or equal
Select Case

6

<<, >>
AND, OR
XOR, IMP
EQV

Bit shift right, Bit shift left
Logical conjunction, Logical disjunction
Logical exclusion, Logical implication
Bit wise comparision

Two types of expressions, mathematical and logical, are used in CRBASIC. A
useful property of expressions in CRBASIC is that they are equivalent to and
often interchangeable with their results.

Consider the expressions:

x = (z * 1.8) + 32 (a mathematical expression)
If x = 23 then y = 5 (logical expression)

The variable x can be omitted and the expressions combined and written as:

If (z * 1.8 + 32 = 23) then y = 5

4-34