Arithmetic expressions (variables)

<< Click to Display Table of Contents >>

Navigation:  User guide > Arithmetic >

Arithmetic expressions (variables)

Arithmetic expressions are usually used with the D (define) command to set a variable to a value.

The term arithmetic expression represents expressions which take a numeric value. An arithmetic expression consists of one or more of the following:

ivar

colbin

wvar

cell

svar

inconstant

wconstant

combined with the operators:

+ plus

* multiplied

- minus

/ divide

NOTE: CL always evaluates an expression from left to right unless parentheses are used to control the order of evaluation.

All arithmetic is carried out in double precision mode

When a number is to be stored into an ivar or field it will be rounded to the nearest whole number before being stored unless F=TRU (see below).

Where the destination is a single precision table cell (F=NDBL) rounding to single precision occurs after the arithmetic and before the save.

Truncation (loss of any fractional part of a number) can only occur if format TRU is set and when the destination is a field or an ivar, and there are no wvars, wconstants or cells in the expression, in which case arithmetic is carried out in integer mode, and truncation can occur on division operations. Under these circumstances only, integer overflow can occur during the calculation. Integer overflow occurs if an intermediate or final result in the calculation exceeds 2000000000.

You are strongly advised never to set F=TRU. If you require truncation use the truncate functions %TRUN and %FRP .

An arithmetic expression may be "undefined". This value is represented in code by the letter U. Normally this will occur if either of formats IFF or IFB have been set to U and a field contains embedded blanks or multi-punches. Then the field will take the value U and will have that value when used in an arithmetic expression unless UZA is used.

The letter U, by itself, is an arithmetic expression.

IMPORTANT: If any part of an arithmetic expression is undefined, then the whole value is regarded as undefined unless UZA is used. This can cause variables defined by such an arithmetic expression to take value U. Records whose weighting or scoring factors are undefined are excluded from incrementation and calculation of statistics.

IMPORTANT: ivars and wvars are initialised to zero, not undefined, at the start of a stage unless RCP UNDEFINED is used.

Examples of arithmetic expressions:

45,

$SNUM,

U,

6.3,

$ISUM+$W3*0.25,

$112-116 + ($I2 * 45) / ($WALL + 983.88),

(#1(r1,c2)+1.0)/100.0,