Previous Topic: Comparisons With Real Numbers

Next Topic: Arithmetic Operators

Arithmetic Expressions

A simple arithmetic expression in NCL consists of two numbers (real or integer) separated by an arithmetic operator. For example:

1 + 2
497021 - 7832
0.08 + 76.889
38 - 97
1E5 - 22.9
44 / 11

A number can also be the name of a variable that contains a numeric value, for example:

&A + 1
&COUNTER + &INCREMENT

The number on the left is operated on by the number on the right. There must be one or more blanks between the operator and the numbers on each side of it.

An expression can also be enclosed in parentheses, in which case blanks are not mandatory between the numbers and the operator. Parentheses can also be used to control the order in which the statement expressions are evaluated.

A compound arithmetic expression consists of two or more numbers and operators, surrounded by parenthesis, which are processed according to the standard rules of precedence to yield a result, for example:

(32 + 6) - (7.8 * 2)

would yield 38 - 15.6 giving an answer of:

+.224000000000000E+02 equivalent to 22.4.