beautypg.com

A.6 processing and math instructions, A.6.1 mathematical operators, A.6.2 arithmetic operators – Campbell Scientific CR1000 Measurement and Control System User Manual

Page 493: A.6.3 bitwise operators, Table 116. arithmetic operators

background image

Appendix A. CRBasic Programming Instructions

493

 

A.6 Processing and Math Instructions

A.6.1 Mathematical Operators

Note Program declaration AngleDegrees() (see Program Declarations

(p. 473)

)

sets math functions to use degrees instead of radians.

A.6.2 Arithmetic Operators

Table 116. Arithmetic Operators

Symbol Name

Notes

^

Raise to power

Result is always promoted to a float

(p. 142)

to avoid problems that

may occur when raising an integer to a negative power. However,
loss of precision occurs if result is > 24 bits.
For example:
(46340 ^ 2) will yield 2,147,395,584 (not precisely correct)
whereas,
(46340 * 46340) will yield 2,147,395,600 (precisely correct)
Simply use repeated multiplications instead of ^ operators when
full 32-bit precision is required.
Same functionality as PWR()

(p. 497)

instruction.

*

Multiply

/

Divide Use

INTDV()

(p. 497)

to retain 32-bit precision

+

Add

-

Subtract

=

Equal to

<>

Not equal to

>

Greater than

<

Less than

>=

Greater than or
equal to

<=

Less than or
equal to

 

A.6.3 Bitwise Operators

Bitwise shift operators (<< and >>) allow the program to manipulate the positions
of patterns of bits within an integer (CRBasic Long type). Here are some example
expressions and the expected results:

&B00000001 << 1 produces &B00000010 (decimal 2)
&B00000010 << 1 produces &B00000100 (decimal 4)
&B11000011 << 1 produces &B10000110 (decimal 134)
&B00000011 << 2 produces &B00001100 (decimal 12)
&B00001100 >> 2 produces &B00000011 (decimal 3)