# 3.1 Arithmetic Assignment Statement

The arithmetic assignment statement assigns the value of the expression on the right of the equal sign to the numeric scalar memory reference on the left of the equal sign. It takes the following form:

    v = e

v
  Is a numeric scalar memory reference.
e
  Is an arithmetic expression.

Although the symbolic name on the left of the equal sign can be undefined, values must have been previously assigned to all symbolic references in the expression on the right of the equal sign.

The expression e must yield a value that conforms to the range requirements of v. For example, a real expression that produces a value greater than 32767 is invalid if the entity on the left of the equal sign is an INTEGER*2 variable. Significance can be lost if an INTEGER*4 value, which can exactly represent values of approximately the range -2*10**9 to +2*10**9, is converted to REAL*4 (including the real part of a complex constant), which is accurate to only about seven digits.

Note
  When the run-time system assigns a value to a scalar memory reference and the memory reference is shorter than the value being assigned, the assigned value may be truncated and significant bits lost. This truncation can occur without warning, and can cause the run-time system to pass incorrect information back to the program.

If v has the same data type as that of the expression on the right, the statement assigns the value directly. If the data types are different, the value of the expression is converted to the data type of the entity on the left of the equal sign before it is assigned.

Examples

The following examples show valid and invalid assignment statements and explain why the invalid ones are not valid:

Valid |
`BETA = -1./(2.*X)+A*A /(4.*(X*X))`
`PI = 3.14159` |
`SUM = SUM + 1.` |
`NEW = RECORD1.FIELD1` |
Invalid | Explanation
`3.14 = A - B` | Entity on the left must be a numeric scalar memory reference.
`-J = I**4` | Entity on the left must not be signed.
`ALPHA = ((X+6)*B*B/(X-Y)` | Left and right parentheses do not balance.
`ICOUNT = A//B(3:7)` | Expression on the right cannot have a character data type if the entity on the left does not.

Figure 3-1 summarizes the data conversion rules for assignment statements. Remember that REAL*16 and COMPLEX*16 are language extensions.

### Figure 3-1 Conversion Rules for Assignment Statements

Previous Page Next Page Table of Contents