An arithmetic assignment assigns the value of the arithmetic expression on the right side of the assignment operator (:=) to the arithmetic target on the left side.
<arithmetic assignment>
──┬─<arithmetic variable>─┬─────────────────────┬──────────────────────► │ └─<partial word part>─┤ ├─<arithmetic type transfer variable>─────────┤ └─<arithmetic attribute>──────────────────────┘ ►─┬─ := ──<arithmetic expression>──┬───────────────────────────────────┤ └─<arithmetic update assignment>─┘
Arithmetic Variable
The attribute error number returned from the operating system can be captured in the arithmetic variable.
<arithmetic variable>
──<variable>───────────────────────────────────────────────────────────┤
──┬──────────────────────────────┬─┬─<simple variable>──────┬──────────┤ ├─<connection block qualifier>─┤ └─<subscripted variable>─┘ └─<structure block qualifier>──┘
<simple variable>
──<identifier>─────────────────────────────────────────────────────────┤
<subscripted variable>
┌◄───── , ────┐ ──<array name>── [ ─┴─<subscript>─┴─ ] ────────────────────────────────┤
If the <arithmetic variable> <partial word part> syntax or the <arithmetic attribute> syntax appears in a statement with multiple assignments, then it must appear as the leftmost target in the statement. The following examples illustrate this rule:
|
Allowed |
Not Allowed |
|
X.[7:8] := Y := 1 |
Y := X.[7:8] := 1 |
|
F1.MAXRECSIZE:= RECLNGTH:= 30 |
RECLNGTH:= F1.MAXRECSIZE:= 30 |
An <arithmetic variable> <partial word part> assignment leaves the remainder of the arithmetic variable unchanged, despite any possible side effects, such as embedded assignments, in the arithmetic expression. The rightmost <number of bits> of the <arithmetic expression> is assigned, unchanged, to the specified field of the <arithmetic variable>. If the arithmetic variable is double-precision, the field applies to its first word, and its second word is unchanged.
Arithmetic Type Transfer Variable
<arithmetic type transfer variable>
──┬─ ALPHA ────┬───────────────────────────────────────────────────────► ├─ DINTEGER ─┤ ├─ DOUBLE ───┤ ├─ INTEGER ──┤ └─ REAL ─────┘ ►─┬─ ( ──<variable>── ) ────────────────────────┬──────────────────────┤ ├─ ( ──<variable>── <partial word part> ── ) ─┤ └─ ( ──<variable>── ) ── <partial word part> ─┘
If the declared type of the target item to the left of the assignment operator (:=) and the type of the value to be assigned to it are different, then the appropriate implicit type conversion is performed according to the following rules (ALPHA is semantically identical to REAL):
-
If the left side is of type INTEGER and the expression value is of type REAL, then the value is rounded to an integer before it is stored.
-
If the left side is of type INTEGER and the expression value is of type DINTEGER or DOUBLE, then the value is rounded to a single-precision integer before it is stored.
-
If the left side is of type REAL and the expression value is of type INTEGER, then the value is stored unchanged.
-
If the left side is of type REAL and the expression value is of type DINTEGER or DOUBLE, then the value is rounded to single-precision before it is stored.
-
If the left size is of type DINTEGER and the expression value is of type INTEGER, REAL, or DOUBLE, then the value is converted to double integer before it is stored.
-
If the left side is of type DOUBLE and the expression value is of type INTEGER or REAL, then the value is converted to double-precision by appending a second word of zero (all bits equal to zero) before it is stored.
The use of an arithmetic type transfer variable causes the value on the right side of the assignment operator to be stored unchanged into the variable on the left side, regardless of type. However, if an attempt is made to assign a double-precision value into a single-precision variable by using the DINTEGER and DOUBLE forms of the construct, only the first word of the double-precision value is stored unchanged into the single-precision variable. For more information, see Type Coercion of One-Word and Two-Word Operands.
If more than one assignment operator appears in a single assignment (for example, A := B := C := 1.414), assignment of values is executed from right to left. If, during this process, a value is converted to another type so that it can be assigned, then it remains in that converted form following that assignment; that is, the value does not resume its original form. For example, assume you are executing the following program:
BEGIN DOUBLE DBL1, DBL2; REAL REL1, REL2; INTEGER INT1; DBL2 := REL2 := INT1 := REL1 := DBL1 := 1.414213562373095048801@@0; END.
In this program, the variables are assigned the following values:
DBL1 = 1.414213562373095048801 REL1 = 1.41421356237 INT1 = 1 REL2 = 1.0 DBL2 = 1.0
Arithmetic Attribute
<arithmetic attribute>
──┬─<arithmetic file attribute>─────────┬──────────────────────────────┤ ├─<arithmetic direct array attribute>─┤ ├─<arithmetic task attribute>─────────┤ └─<arithmetic library attribute>──────┘
<arithmetic file attribute>
──<file designator>─┬─────────────────────────────────────┬─ . ────────►
└─<attribute parameter specification>─┘
►─<arithmetic-valued file attribute name>──────────────────────────────►
►─┬─────────────────────────────────┬──────────────────────────────────┤
└─ ( ──<arithmetic variable>── ) ─┘<attribute parameter specification>
── ( ──<attribute parameter list>── ) ─────────────────────────────────┤
<attribute parameter list>
──┬─<arithmetic expression>─┬─┬──────────────────────────────┬─────────┤ └─<file attribute>────────┘ └─ , ──<arithmetic expression>─┘
A <file attribute> name that can also be interpreted as an <arithmetic expression> is ambiguous. In this case, use the intrinsic function VALUE, specifying the attribute name, to obtain the attribute number that corresponds to that attribute name. For example, the file attribute UNITS has the same name as the Advanced Data Dictionary System (ADDS) <units function>. To ensure that the file attribute number for UNITS is specified in the parameter for file F, use F(VALUE(UNITS)) rather than F(UNITS).
<arithmetic direct array attribute>
──<direct array row>── . ──────────────────────────────────────────────► ►─<arithmetic-valued direct array attribute name>──────────────────────┤
<arithmetic-valued direct array attribute name>
ALGOL supports all direct array attributes and direct array attribute values described in the File Attributes Programming Reference Manual.
<arithmetic task attribute>
──<task designator>── . ──<arithmetic-valued task attribute name>──────┤
<arithmetic-valued task attribute name>
ALGOL supports all task attributes of type real and integer described in the Task Attributes Programming Reference Manual.
<arithmetic library attribute>
──<library attribute designator>── . ──────────────────────────────────► ►─<arithmetic-valued library attribute name>───────────────────────────┤
<library attribute designator>
──┬─<library identifier>─────────────────────────────────────────────────────┬─┤
├─<thiscl intrinsic>───────────────────────────────────────────────────────┤
└─ LIBRARY ── ( ──<connection lib id>─┬──────────────────────────────┬─ ) ─┘
└─ [ ──<arith expression>── ] ─┘Arithmetic Update Assignment
<arithmetic update assignment>
──<update symbols>─┬────────────────────────────────────────────────┬──┤
└─<arithmetic operator>──<arithmetic expression>─┘<update symbols>
── := ── * ────────────────────────────────────────────────────────────┤
The arithmetic update assignment is a shorthand form of assignment that can be used when the arithmetic target on the left side of the assignment operator also appears in the arithmetic expression on the right side of the operator. The arithmetic update assignment form can be specified only following an arithmetic target that does not contain a partial word part. The asterisk (*) represents a duplication of the item to the left of the assignment operator. For example, the same results are produced by the following two assignments:
A := * + 1 A := A + 1
The target item is not reevaluated at the appearance of the asterisk. Hence, if I equals zero initially, the following applies:
|
Assignment |
Equivalent |
Not Equivalent |
|
B[I := I + 1] := * + 1 |
B[1] := B[1] + 1 |
B[1] := B[2] + 1 |
If the item to the left of the assignment operator is a subscripted variable, it cannot reference a value array.
If an expression is used as a subscript to a variable, the subscript is evaluated first. In the following example, the expression used as a subscript [I+2] is evaluated first:
A[I+2] := I := 10
Examples of an Arithmetic Assignment
VAL := 7 A[4,5].[30:4] := X FYLE.AREAS := 50 FYLE(5).AREAS := 10 FYLE.SYNCHRONIZE := VALUE(OUT) DIRARAY.IOCW := 4"1030" TSK.COREESTIMATE := 10000 NEWARRAY[I] := * + OLDARRAY[I] ONE := SIN(X := 3)**2 + COS(X)**2 DISTANCE := SQRT(X**2 + Y**2 + 2**2) CONNECTION_LIBRARY_INT.R := CONNECTION_LIBRARY_EXT[4].T;

