Arithmetic expressions

<< Click to Display Table of Contents >>

Navigation:  Reference > Pre-processor >

Arithmetic expressions

An PP arithmetic expression (AE) consists of numbers between -1000000000 and +1000000000 inclusive, indices, and the four operators:

+ plus

- minus

* multiply

/ divide

A number on its own and an index on its own are both valid AEs.

The value of an AE is the value of the index or the number, if either appears singly, or the result of the computation involving the operators.

IMPORTANT: computation always proceeds from left to right unless parentheses are used to control the order of processing. So, for example:

[*set First = 4]

[*set Second = 5]

[*set NewOne = First + Second * 2]

[*set NewTwo = First + (Second * 2)]

Sets NewOne to 18 and NewTwo to 14.

IMPORTANT: the result of division will be whole numbers which are truncated. Thus, 11/4 will equal 2 and not 2.75 or 3. So, for example:

[*set First = 4]

[*set Second = 5]

[*set Number = ((First/2)+(Second/2))*3]

Sets Number to 12.

The evaluation of an AE must never result in a value less than -1000000000 or greater than +1000000000. An AE must never contain a reference to an index whose value is unset; all indices must be set before they are referenced.

Examples of valid PP AEs:

[Next]

[4365]

[Total+1]

[FirstPart*10-1]

[(Prod1*5)+(Prod2*4)+ProdExtra]