Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual

Page 32

Advertising
background image

Publication 2098-PM001E-EN-P — July 2002

1-20

Programming Motion Control in C

lists the precedence and describes the functions and any limitations
placed on the arithmetic operations in C.

Operator:

Precedence:

Function:

Limitations:

*

1

Multiplies the value on its
right by the value on its
left.

/

Divides the value at its left
by the value on its right.

Answer is truncated if
both operands are
integer or long.

%

Yields the remainder when
the value at its left is
divided by the value to it
right.

Integer or long

++

2

In the prefix mode, adds 1
to the value of the variable
to its right, before the value
is used.
In the suffix mode, adds 1
to the value of the variable
to its left, after the value
was used.

If n is 5, then x = ++n
sets x to 6, but x = n++
sets x to 5.
(incrementing n after
its value is used). In
both cases

n

becomes

6

).

--

In the prefix mode,
subtracts 1 from the value
of the variable to its right.
In the suffix mode,
subtracts 1 from the value
of the variable to its left.

If n is 5, then x = --n
sets x to 4, but x = n--
leaves x at 5
(decrements n after its
value is used). In both
cases

n

becomes 4).

+

(unary form)

3

Changes the sign of the
value on its right.

-

(unary form)

Changes the sign of the
value on its right.

+

(binary form)

4

Adds the value at its right
to the value at its left.

-

(binary form)

Subtracts the value at its
right from the value at its
left.

Advertising