The number of distinct operators is vastly increased by the
availability of SHORT
and LONG
modes. Thus
it is imperative that some kind of shorthand be used to describe the
operators. Following the subsection on the method of description are
sections devoted to operators with classes of operands. The end of
this section contains tables of all the operators.
Where an operator has operands and yield which may include LONG
or
SHORT
, the mode is written using L
. For example,
OP + = (L INT, L INT)L INT:
is a shorthand for the following operators:-
OP + = (LONG INT,LONG INT)LONG INT: OP + = (INT,INT)INT: OP + = (SHORT INT,SHORT INT)SHORT INT: OP + = (SHORT SHORT INT,SHORT SHORT INT) SHORT SHORT INT:
Ensure that wherever L
is replaced by
SHORT
s or LONG
s, it should be replaced by
the same number of SHORT
s or LONG
s
throughout the definition of that operator. This is known as
“consistent substitution”. Note that any number of
SHORT
s or LONG
s can be given in the mode of
any value whose mode accepts such constructs (INT
,
REAL
, COMPL
and BITS
), but the
only modes which can be distinguished are those specified by the
environment enquiries in
section 13.2.1. However, you
should note that even though values of modes LONG REAL
and LONG LONG REAL
cannot be distinguished internally,
the Algol 68 compiler still regards them as having unique modes
and you will need to use the LENG
operator to convert a
value of mode LONG REAL
to a value of mode LONG
LONG REAL
.
The priority of an operator is independent of the mode of the operator and so is given in a separate subsection. Each operator is accompanied by a short description of its function.
The priority of declarations of the standard operators can be changed in subsidiary ranges using the PRIO declaration (see section 6.2.3). Each of the following enumerated nine sections contains a list of those operators which have that priority. Operators in parentheses are not defined in the Revised Report. See section 13.6 for their details.
+:=
, -:=
, *:=
, /:=
,
%:=
, %*:=
, +=:
&
, ANDEQ
, NE
LT
, LE
, GE
, GT
%
, %*
, UP
, DOWN
,
SHL, SHR,
LWB, UPB+*
, I, (MIN, MAX)Both monadic and dyadic forms are available. We shall use the mode
ROW
to denote the mode of any multiple.
r
.
OR
.OP & = (BOOL a,b)BOOL:
AND
(synonym AND).NOT
: TRUE
if a
is
FALSE
and vice versa.TRUE
if a
equals b
(synonym is
EQ
).TRUE
if a
not equal to b
(synonym is
NE
).ABS TRUE
is 1 and ABS
FALSE
is 0.Most of these operators take values of any precision. The
L
shorthand is used for those that can.
Consistent substitution applies to all those operators in this
section which use the L
shorthand: apart from
LENG
and SHORTEN
, the precision of the yield
is the same as the precision of the operand.
OP ABS = (L INT a)L INT:
ABS -3 = +3
TRUE
if the operand is odd.OP LENG = (SHORT L INT a)L INT:
SHORT
and LONG
in the same mode.OP SHORTEN = (LONG L INT a)L INT:
l max int
for the next shorter precision, the value will be
truncated. This can lead to erroneous results. See also LENG
.
In this section, consistent substitution is used wherever the L
shorthand is used. For operators with mixed operands, see section 13.3.8.
L
REAL
. Where a result of mode L REAL
needs to be output,
but cannot be output due to the limitations built into the definition of
the mode SIMPLOUT
, the operators LENG
or
SHORTEN
should be used. Floating-point overflow can be checked
(see section 13.6.1).OP % = (L INT a,L INT b)L INT:
OP %* = (L INT a,L INT b)L INT:
5 MOD 3 = 2
LT
).LE
).GE
).GT
).EQ
).NE
).Most of these operators can have operands of any precision. The
L
shorthand is used for them.
ABS -3.0 = +3.0
OP ROUND = (L REAL a)L INT:
(for any precision except
REAL
) l max int
, an erroneous result will
ensue. ROUND
should be used for a REAL
operand if
you want to check for integer overflow (see section 13.6.1 for details of floating-point
overflow checking).OP ENTIER = (L REAL a)L INT:
(for any precision except
REAL
) l max int
, an
erroneous result will ensue. Use ENTIER
for a
REAL
operand if you want to check for integer overflow (see
section 13.6.1 for details of
floating-point overflow checking).OP LENG = (SHORT L REAL a)L REAL:
SHORT
and LONG
in the same mode.OP SHORTEN = (LONG L REAL a)L REAL:
l max real
for the next shorter precision, the value will be
truncated leading to an erroneous result. The mantissa will always be
truncated.In this section, consistent substitution is used wherever the L
shorthand appears. For operators with mixed operands, see section 13.3.8.
L REAL
needs to be output, but it cannot be output due
to the limitations built into the definition of the mode
SIMPLOUT
, the operators LENG
or
SHORTEN
should be used.LT
).LE
).
GE
) GT
).EQ
).NE
).Algol 68 is one of the few programming languages which have a
built-in mode for complex numbers. It is complemented by a rich set of
operators, some of which are only available for values of mode
COMPL
. Again, consistent substitution is applicable to
all operators using the L
shorthand.
re OF a
.im OF a
.OP LENG = (SHORT L COMPL a)L COMPL:
SHORT
and LONG
in the same mode.
Unfortunately, although a68toc will translate a program
containing this operator apparently without errors, the resulting
C file will not compile. The error produced will be “conversion
to non-scalar type requested”. You should use the following code
instead:-
(LENG RE z,LENG IM z)
OP SHORTEN = (LONG L COMPL a)L COMPL:
SHORT
and LONG
in the same mode.
Unfortunately, the a68toc translator will generate
incorrect code (see the note for the operator LENG
). Use the
following code instead:-
(SHORTEN RE z,SHORTEN IM z)If either of the components of the complex number exceeds
l max
real
for the next shorter precision, an erroneous result will
ensue, but no error will be generated.The remarks in section 13.3.6 concerning floating-point overflow apply doubly here.
EQ
).
NE
).Consistent substitution is applicable to all operators using the L
shorthand. Additional shorthands are used as follows:-
P
stands for +,
-
, *
or /
.R
stands for <, <=, =
,
/=
, >=, >, LT
, LE
, EQ
, NE
,
GE
, GT
.E
stands for =
/=
,
EQ
or NE
.
OP P = (L INT a,L REAL b)L REAL:
OP P = (L INT a,L COMPL b)L COMPL:
OP P = (L REAL a,L COMPL b)L COMPL:
OP P = (L REAL a,L INT b)L REAL:
OP P = (L COMPL a,L INT b)L COMPL:
OP P = (L COMPL a,L REAL b)L COMPL:
OP R = (L INT a,L REAL b)BOOL:
OP R = (L REAL a,L INT b)BOOL:
OP E = (L INT a,L COMPL b)BOOL:
OP E = (L REAL a,L COMPL b)BOOL:
OP E = (L COMPL a,L INT b)BOOL:
OP E = (L COMPL a,L REAL b)BOOL:
OP ** = (L COMPL a,INT b)L COMPL:
OP +* = (L REAL a,L INT b)L COMPL:
Consistent substitution applies to all operators using the
L
shorthand.
OP LENG = (SHORT L BITS a)L BITS:
SHORT
and LONG
in the same mode.OP SHORTEN = (LONG L BITS a)L BITS:
OP & = (L BITS a,L BITS b)L BITS:
UP
).DOWN
)TRUE
if bit a is 1.EQ
).NE
).TRUE
if each bit in the left operand implies the
corresponding bit in the right operand (synonym LE
).TRUE
if each bit in the right operand implies the
corresponding bit in the left operand (synonym GE
).The shorthands in section 13.3.8 apply here.
ABS
. The operand should be in the range
[0:max abs char]
.OP E = (CHAR a,CHAR b)BOOL:
OP + = (CHAR a,STRING b)STRING:
OP + = (STRING a,CHAR b)STRING:
OP * = (STRING a,INT b)STRING:
OP * = (INT a,CHAR b)STRING:
OP * = (CHAR a,INT b)STRING:
LT
).LE
) <
in this section applies.GE
) <
in this section applies.GT
) <
in this section applies.<
in this section (synonym
EQ
).NE
) <
in this section.OP E = (STRING a,CHAR b)BOOL:
OP E = (CHAR a,STRING b)BOOL:
Consistent substitution applies to all operators containing the
L
shorthand.
+:=
(synonym PLUSAB) a:=a+b
. Left operand | Right operand | Yield |
REF L INT | L INT | REF L INT |
REF L REAL | L INT | REF L REAL |
REF L COMPL | L INT | REF L COMPL |
REF L REAL | L REAL | REF L REAL |
REF L COMPL | L REAL | REF L COMPL |
REF L COMPL | L COMPL | REF L COMPL |
REF STRING | CHAR | REF STRING |
REF STRING | STRING | REF STRING |
+=:
(synonym PLUSTO) b:=a+b
. Left operand | Right operand | Yield |
STRING | REF STRING | REF STRING |
CHAR | REF STRING | REF STRING |
-:=
(synonym MINUSAB) a:=a-b
. Left operand | Right operand | Yield |
REF L INT | L INT | REF L INT |
REF L REAL | L INT | REF L REAL |
REF L COMPL | L INT | REF L COMPL |
REF L REAL | L REAL | REF L REAL |
REF L COMPL | L REAL | REF L COMPL |
REF L COMPL | L COMPL | REF L COMPL |
*:=
(synonym TIMESAB) a:=a*b
. Left operand | Right operand | Yield |
REF L INT | L INT | REF L INT |
REF L REAL | L INT | REF L REAL |
REF L COMPL | L INT | REF L COMPL |
REF L REAL | L REAL | REF L REAL |
REF L COMPL | L REAL | REF L COMPL |
REF L COMPL | L COMPL | REF L COMPL |
REF L COMPL | INT | REF L COMPL |
/:=
(synonym DIVAB) a:=a/b
. Left operand | Right operand | Yield |
REF L REAL | L INT | REF L REAL |
REF L REAL | L REAL | REF L REAL |
REF L COMPL | L INT | REF L COMPL |
REF L COMPL | L REAL | REF L COMPL |
REF L COMPL | L COMPL | REF L COMPL |
OP %:= = (REF L INT a,L INT b)REF L INT:
a:=a%b
.OP %*:= = (REF L INT a,L INT b)REF L INT:
a:=a%*b
.This section contains those operators which appear neither in the Revised Report nor in the section concerning a68toc extensions (section 13.5).
r
by 2e. The
routine does not use multiplication, but simply increments the exponent of
r
accordingly.OP MIN = (L REAL a,L REAL b)L REAL:
OP MIN = (L INT a,L REAL b)L REAL:
OP MIN = (L REAL a,L INT b)L REAL:
OP MAX = (L REAL a,L REAL b)L REAL:
OP MAX = (L INT a,L REAL b)L REAL:
OP MAX = (L REAL a,L INT b)L REAL:
r
is a valid real in terms of the IEEE
standard.