In the statement pack(a,i,z) and in the statement unpack(z,a,i) the following shall hold: a and z shall be variable-accesses; a shall possess an array-type not designated packed; z shall possess an array-type designated packed; the component-types of the types of a and z shall be the same; and the value of the expression i shall be assignment-compatible with the index-type of the type of a.
Let j and k denote auxiliary variables that the program does not otherwise contain and that have the type that is the index-type of the type of z and a, respectively. Let u and v denote the smallest and largest values of the index-type of the type of z. Each of the statements pack(a,i,z) and unpack(z,a,i) shall establish references to the variables denoted by a and z for the remaining execution of the statements; let aa and zz, respectively, denote the referenced variables within the following sentence. Then the statement pack(a,i,z) shall be equivalent to
begin
k := i;
for j := u to v do
begin
zz[j] := aa[k];
if j <> v then k := succ(k)
end
end
and the statement unpack(z,a,i) shall be equivalent to
begin
k := i;
for j := u to v do
begin
aa[k] := zz[j];
if j <> v then k := succ(k)
end
end
NOTE --- Errors will arise if the references cannot be established, if one or more of the values attributed to j is not assignment-compatible with the index-type of the type of a, or if an evaluated array component is undefined.
Required functions
General
The required functions shall be arithmetic functions, transfer functions, ordinal functions, and Boolean functions.
Arithmetic functions
For the following arithmetic functions, the expression x shall be either of real-type or integer-type. For the functions abs and sqr, the type of the result shall be the same as the type of the parameter, x. For the remaining arithmetic functions, the result shall always be of real-type. The result shall be as shown in table 2.
Table 2 --- Arithmetic function results
FunctionResult
abs(x) absolute value of x
sqr(x) square of x
It shall be an error if such a value does not exist.
sin(x) sine of x, where x is in radians
cos(x) cosine of x, where x is in radians
exp(x) base of natural logarithms raised to the power x
ln(x) natural logarithm of x, if x is greater than zero
It shall be an error if x is not greater than zero.
sqrt(x) non-negative square root of x, if x is not negative
It shall be an error if x is negative.
`arctan(x) principal value, in radians, of the arctangent of x
Transfer functions
trunc(x)
From the expression x that shall be of real-type, this function shall return a result of integer-type. The value of trunc(x) shall be such that if x is positive or zero, then 0£x-trunc(x)<1; otherwise, -1<x-trunc(x)£0. It shall be an error if such a value does not exist.
Examples:
trunc(3.5) {yields 3}
trunc(-3.5) {yields -3}
round(x)
From the expression x that shall be of real-type, this function shall return a result of integer-type. If x is positive or zero, round(x) shall be equivalent to trunc(x+0.5); otherwise, round(x) shall be equivalent to trunc(x-0.5). It shall be error if such a value does not exist.
Examples:
round(3.5) {yields 4}
round(-3.5) {yields -4}
Ordinal functions
ord(x)
From the expression x that shall be of an ordinal-type, this function shall return a result of integer-type that shall be the ordinal number (see 6.4.2.2 and 6.4.2.3) of the value of the expression x.
chr(x)
From the expression x that shall be of integer-type, this function shall return a result of char-type that shall be the value whose ordinal number is equal to the value of the expression x, if such a character value exists. It shall be an error if such a character value does not exist. For any value, ch, of char-type, it shall be true that
chr(ord(ch)) = ch
succ(x)
From the expression x that shall be of an ordinal-type, this function shall return a result that shall be of the same type as that of the expression (see 6.7.1). The function shall yield a value whose ordinal number is one greater than that of the expression x, if such a value exists. It shall be an error if such a value does not exist.
pred(x)
From the expression x that shall be of an ordinal-type, this function shall return a result that shall be of the same type as that of the expression (see 6.7.1). The function shall yield a value whose ordinal number is one less than that of the expression x, if such a value exists. It shall be an error if such a value does not exist.
Boolean functions
odd(x)
From the expression x that shall be of integer-type, this function shall be equivalent to the expression
(abs(x) mod 2 = 1).
eof(f)
The parameter f shall be a file-variable; if the actual-parameter-list is omitted, the function shall be applied to the required textfile input (see 6.10) and the program shall contain a program-parameter-list containing an identifier with the spelling input. When eof(f) is activated, it shall be an error if f is undefined; otherwise, the function shall yield the value true if f.R is the empty sequence (see 6.4.3.5); otherwise, false.
eoln(f)
The parameter f shall be a textfile; if the actual-parameter-list is omitted, the function shall be applied to the required textfile input (see 6.10) and the program shall contain a program-parameter-list containing an identifier with the spelling input. When eoln(f) is activated, it shall be an error if f is undefined or if eof(f) is true; otherwise, the function shall yield the value true if f.R.first is an end-of-line component (see 6.4.3.5); otherwise, false.
Expressions
General
An expression shall denote a value. The use of a variable-access as a factor shall denote the value, if any, attributed to the variable accessed thereby. When a factor is used, it shall be an error if the variable denoted by a variable-access of the factor is undefined. Operator precedences shall be according to four classes of operators as follows. The operator not shall have the highest precedence, followed by the multiplying-operators, then the adding-operators and signs, and finally, with the lowest precedence, the relational-operators. Sequences of two or more operators of the same precedence shall be left associative.
Any factor whose type is S, where S is a subrange of T, shall be treated as if it were of type T. Similarly, any factor whose type is set of S shall be treated as if it were of the unpacked-canonical-set-of-T-type, and any factor whose type is packed set of S shall be treated as of the packed-canonical-set-of-T-type.
A set-constructor shall denote a value of a set-type. The set-constructor [ ] shall denote the value in every set-type that contains no members. A set-constructor containing one or more member-designators shall denote either a value of the unpacked-canonical-set-of-T-type or, if the context so requires, the packed-canonical-set-of-T-type, where T is the type of every expression of each member-designator of the set-constructor. The type T shall be an ordinal-type. The value denoted by the set-constructor shall contain zero or more members, each of which shall be denoted by at least one member-designator of the set-constructor.
The member-designator x, where x is an expression, shall denote the member that shall be the value of x. The member-designator x..y, where x and y are expressions, shall denote zero or more members that shall be the values of the base-type in the closed interval from the value of x to the value of y. The order of evaluation of the expressions of a member-designator shall be implementation-dependent. The order of evaluation of the member-designators of a set-constructor shall be implementation-dependent.
NOTES
2 The member-designator x..y denotes no members if the value of x is greater than the value of y.
3 The set-constructor [ ] does not have a single type, but assumes a suitable type to satisfy the assignment-compatibility rules, or the compatibility rules for operators, if possible.
Examples:
a) Factors:
(x + y + z)
sin(x + y)
[red, c, green]
[1, 5, 10..19, 23]
not p
b) Terms:
x * y
i / (1 - i)
(x <= y) and (y < z)
c) Simple Expressions:
p or q
x + y
-x
hue1 + hue2
i * j + 1
d) Expressions:
x = 1.5
p <= q
p = q and r
(i < j) = (j < k)
c in hue1
Operators
General
multiplying-operator = '*' ½ '/' ½ 'div' ½ 'mod' ½ 'and' .
adding-operator = '+' ½ '-' ½ 'or' .
relational-operator = '=' ½ '<>' ½ '<' ½ '>' ½'<=' ½ '>=' ½ 'in' .
A factor, a term, or a simple-expression shall be designated an operand. The order of evaluation of the operands of a dyadic operator shall be implementation-dependent.
NOTE --- This means, for example, that the operands may be evaluated in textual order, or in reverse order, or in parallel, or they may not both be evaluated.