Subsections


Standard operators

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.


Method of description

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 SHORTs or LONGs, it should be replaced by the same number of SHORTs or LONGs throughout the definition of that operator. This is known as “consistent substitution”. Note that any number of SHORTs or LONGs 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.


Standard priorities

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.

  1. +:=, -:=, *:=, /:=, %:=, %*:=, +=:
    PLUSAB, MINUSAB, TIMESAB, DIVAB, OVERAB, MODAB, PLUSTO
  2. OR
  3. &, AND
  4. =, /=, EQ, NE
  5. <, <=, >=, >
    LT, LE, GE, GT
  6. -, +,
  7. *, /, %, %*,
    OVER, MOD, ELEM,
  8. **, UP, DOWN, SHL, SHR, LWB, UPB
  9. +*, I, (MIN, MAX)


Operators with row operands

Both monadic and dyadic forms are available. We shall use the mode ROW to denote the mode of any multiple.

  1. Monadic.
    OP LWB = (ROW)INT:
    OP UPB = (ROW)INT:
    Yields the lower or upper bound of the first or only dimension of its operand.
  2. Dyadic.
    OP LWB = (INT n,ROW r)INT:
    OP UPB = (INT n,ROW r)INT:
    Yields the lower or upper bound of the n-th dimension of the multiple r.


Operators with BOOL operands

  1. OP OR = (BOOL a,b)BOOL:
    Logical OR.
  2. OP & = (BOOL a,b)BOOL:
    Logical AND (synonym AND).
  3. OP NOT = (BOOL a)BOOL:
    Logical NOT: TRUE if a is FALSE and vice versa.
  4. OP = =(BOOL a,b)BOOL:
    TRUE if a equals b (synonym is EQ).
  5. OP /= =(BOOL a,b)BOOL:
    TRUE if a not equal to b (synonym is NE).
  6. OP ABS = (BOOL a)INT:
    ABS TRUE is 1 and ABS FALSE is 0.


Operators with INT operands

Most of these operators take values of any precision. The L shorthand is used for those that can.


Monadic operators

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.

  1. OP + = (L INT a)L INT:
    The identity operator. Does nothing.
  2. OP - = (L INT a)L INT:
    The negation operator.
  3. OP ABS = (L INT a)L INT:
    The absolute value. ABS -3 = +3
  4. OP SIGN = (L INT a)INT:
    Yields -1 for a negative operand, +1 for a positive operand and 0 for a zero operand.
  5. OP ODD = (L INT a)BOOL:
    Yields TRUE if the operand is odd.
  6. OP LENG = (L INT a)LONG L INT:
    OP LENG = (SHORT L INT a)L INT:
    Converts its operand to the next longer precision. Note that you cannot use both SHORT and LONG in the same mode.
  7. OP SHORTEN = (L INT a)SHORT L INT:
    OP SHORTEN = (LONG L INT a)L INT:
    Converts its operand to the next shorter precision. If the value exceeds l max int for the next shorter precision, the value will be truncated. This can lead to erroneous results. See also LENG.


Dyadic operators

In this section, consistent substitution is used wherever the L shorthand is used. For operators with mixed operands, see section 13.3.8.

  1. OP + = (L INT a,L INT b)L INT:
    Arithmetic addition: a + b. No check is made for integer overflow.
  2. OP - = (L INT a,L INT b)L INT:
    Arithmetic subtraction: a - b. No check is made for integer overflow.
  3. OP * = (L INT a,L INT b)L INT:
    Arithmetic multiplication: a x b. No check is made for integer overflow.
  4. OP / = (L INT a,L INT b)L REAL:
    Arithmetic fractional division. Even if the result is a whole number (for example, 6/3), the yield always has mode 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).
  5. OP % = (L INT a,L INT b)L INT:
    Arithmetic integer division. Division by zero in the a68toc implementation produces a floating-point exception paradoxically (synonym OVER).
  6. OP ** = (L INT a,INT b)L INT:
    Computes ab for b ≥ 0.
  7. OP %* = (L INT a,L INT b)L INT:
    Arithmetic modulo (synonym MOD). For example
       5 MOD 3 = 2
    
  8. OP +* = (L INT a,L INT b)L COMPL:
    Converts two integers into a complex number of the same precision (synonym I).
  9. OP < = (L INT a,L INT b)BOOL:
    Arithmetic “less than”: a < b (synonym LT).
  10. OP <= = (L INT a,L INT b)BOOL:
    Arithmetic “less than or equals”: ab (synonym LE).
  11. OP >= = (L INT a,L INT b)BOOL:
    Arithmetic “greater than or equals”: ab (synonym GE).
  12. OP > = (L INT a,L INT b)BOOL:
    Arithmetic “greater than”: a > b (synonym GT).
  13. OP = = (L INT a,L INT b)BOOL:
    Arithmetic equality: a = b (synonym EQ).
  14. OP /= = (L INT a,L INT b)BOOL:
    Arithmetic inequality: ab (synonym NE).


Operators with REAL operands

Most of these operators can have operands of any precision. The L shorthand is used for them.

Monadic operators

  1. OP + = (L REAL a)L REAL:
    Arithmetic identity. Does nothing.
  2. OP - = (L REAL a)L REAL:
    Arithmetic negation: - a.
  3. OP ABS = (L REAL a)L REAL:
    The absolute value. ABS -3.0 = +3.0
  4. OP SIGN = (L REAL a)INT:
    Yields -1 for negative operands, +1 for positive operands and 0 for a zero operand (0.0).
  5. OP ROUND = (REAL a)INT:
    Rounds its operand to the nearest integer. If the value ends with .5, it is rounded to the nearest even number. This is contrary to normal Linux C library practice, but is an internationally accepted standard which ensures that rounding errors do not accumulate. The operator checks for integer overflow (see section 13.6.1 for details).
  6. OP ROUND = (L REAL a)L INT: (for any precision except REAL)
    Rounds its operand to the nearest integer. Does not check integer overflow. If its operand exceeds 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).
  7. OP ENTIER = (REAL a)INT:
    Truncates its operand to the next lowest integer. The operator checks for integer overflow (see section 13.6.1 for details).
  8. OP ENTIER = (L REAL a)L INT: (for any precision except REAL)
    Truncates its operand to the next lowest integer. The operator does not check integer overflow. If its operand exceeds 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).
  9. OP LENG = (L REAL a)LONG L REAL:
    OP LENG = (SHORT L REAL a)L REAL:
    Converts its operand to the next longer precision. Note that you cannot use both SHORT and LONG in the same mode.
  10. OP SHORTEN = (L REAL a)SHORT L REAL:
    OP SHORTEN = (LONG L REAL a)L REAL:
    Converts its operand to the next shorter precision. If a value exceeds l max real for the next shorter precision, the value will be truncated leading to an erroneous result. The mantissa will always be truncated.


Dyadic operators

In this section, consistent substitution is used wherever the L shorthand appears. For operators with mixed operands, see section 13.3.8.

  1. OP + = (L REAL a,L REAL b)L REAL:
    Floating-point addition: a + b. Floating-point overflow will cause a trappable signal (see section 13.6.1).
  2. OP - = (L REAL a,L REAL b)L REAL:
    Floating-point subtraction: a - b. Floating-point overflow will cause a signal which can be trapped (see section 13.6.1).
  3. OP * = (L REAL a,L REAl b)L REAL:
    Floating-point multiplication: a x b. Floating-point overflow will cause a signal which can be trapped (see section 13.6.1).
  4. OP / = (L REAL a,L REAL b)L REAL:
    Floating-point divison: a/b. Floating-point overflow and divide-by-zero will cause a trappable signal (see section 13.6.1). Where a result of mode 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.
  5. OP +* = (L REAL a,L REAL b)L COMPL:
    Converts two reals into a complex number of the same precision (synonym I).
  6. OP < = (L REAL a,L REAL b)BOOL:
    Floating-point “less than”: a < b (synonym LT).
  7. OP <= = (L REAL a,L REAL b)BOOL:
    Floating-point “less than or equals”: ab (synonym LE).
  8. OP >= = (L REAL a,L REAL b)BOOL:
    (synonym GE)
    Floating-point “greater than or equals”: ab.
  9. |OP > = (L REAL a,L REAL b)BOOL:
    Floating-point “greater than”: a > b (synonym GT).
  10. OP = = (L REAL a,L REAL b)BOOL:
    Floating-point equality: a = b (synonym EQ).
  11. OP /= = (L REAL a,L REAL b)BOOL:
    Floating-point inequality: ab (synonym NE).


Operators with COMPL operands

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.

Monadic operators

  1. OP RE = (L COMPL a)L REAL:
    Yields the real component: re OF a.
  2. OP IM = (L COMPL a)L REAL:
    Yields the imaginary component: im OF a.
  3. OP ABS = (L COMPL a)L REAL:
    Yields √RE a2+IM a2
  4. OP ARG = (L COMPL a)L REAL:
    Yields the argument of the complex number.
  5. OP CONJ = (L COMPL a)L COMPL:
    Yields the conjugate complex number.
  6. OP + = (L COMPL a)L COMPL:
    Complex identity. Does nothing.
  7. OP - = (L COMPL a)L COMPL:
    Complex negation.
  8. OP LENG = (L COMPL a)LONG L COMPL:
    OP LENG = (SHORT L COMPL a)L COMPL:
    Converts its operand to the next longer precision. Note that you cannot use both 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)
    
  9. OP SHORTEN = (L COMPL a)SHORT L COMPL:
    OP SHORTEN = (LONG L COMPL a)L COMPL:
    Converts its operand to the next shorter precision. Note that you cannot use both 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.

Dyadic operators

The remarks in section 13.3.6 concerning floating-point overflow apply doubly here.

  1. OP + = (L COMPL a,L COMPL b)L COMPL:
    Floating-point addition for both components.
  2. OP - = (L COMPL a,L COMPL b)L COMPL:
    Floating-point subtraction for both components.
  3. OP * = (L COMPL a,L COMPL b)L COMPL:
    Standard complex multiplication with floating-point arithmetic.
  4. OP / = (L COMPL a,L COMPL b)L COMPL:
    Standard complex division with floating-point arithmetic.
  5. OP = = (L COMPL a,L COMPL b)BOOL:
    Complex equality with floating-point arithmetic (synonym EQ).
  6. OP /= = (L COMPL a,L COMPL b)BOOL:
    Complex inequality with floating-point arithmetic (synonym NE).


Operators with mixed operands

Consistent substitution is applicable to all operators using the L shorthand. Additional shorthands are used as follows:-


  1. OP P = (L INT a,L REAL b)L REAL:
  2. OP P = (L INT a,L COMPL b)L COMPL:
  3. OP P = (L REAL a,L COMPL b)L COMPL:
  4. OP P = (L REAL a,L INT b)L REAL:
  5. OP P = (L COMPL a,L INT b)L COMPL:
  6. OP P = (L COMPL a,L REAL b)L COMPL:
  7. OP R = (L INT a,L REAL b)BOOL:
  8. OP R = (L REAL a,L INT b)BOOL:
  9. OP E = (L INT a,L COMPL b)BOOL:
  10. OP E = (L REAL a,L COMPL b)BOOL:
  11. OP E = (L COMPL a,L INT b)BOOL:
  12. OP E = (L COMPL a,L REAL b)BOOL:
  13. OP ** = (L REAL a,INT b)L REAL:
    OP ** = (L COMPL a,INT b)L COMPL:
    Exponentiation: ab (synonym UP).
  14. OP +* = (L INT a,L REAL b)L COMPL:
    OP +* = (L REAL a,L INT b)L COMPL:
    (synonym I)


Operators with BITS operands

Consistent substitution applies to all operators using the L shorthand.

Monadic operators

  1. OP BIN = (L INT a)L BITS:
    Mode conversion which does not change the internal value.
  2. OP ABS = (L BITS a)L INT:
    Mode conversion which does not change the internal value.
  3. OP NOT = (L BITS a)L BITS:
    Yields the bits obtained by inverting each bit in the operand. That is, 0 goes to 1, 1 goes to 0.
  4. OP LENG = (L BITS a)LONG L BITS:
    OP LENG = (SHORT L BITS a)L BITS:
    Converts a bits value to the next longer precision by adding zero bits to the more significant end. Note that you cannot use both SHORT and LONG in the same mode.
  5. OP SHORTEN = (L BITS a)SHORT L BITS:
    OP SHORTEN = (LONG L BITS a)L BITS:
    Truncates a bits value to a value of the next shorter precision. The more significant bits are simply ignored.


Dyadic operators

  1. OP & = (L BITS a,L BITS b)L BITS:
    (synonym AND)
    The logical “and” of each pair of binary digits in a and b.
  2. OP OR = (L BITS a,L BITS b)L BITS:
    The logical “or” of each pair of binary digits in a and b.
  3. OP SHL = (L BITS a,INT b)L BITS:
    The left operand shifted left by the number of bits specified by the right operand. New bits shifted in are all zero. If the right operand is negative, shifting is to the right (synonym UP).
  4. OP SHR = (L BITS a,INT b)L BITS:
    (synonym DOWN)
  5. OP ELEM = (INT a,L BITS b)BOOL:
    Yields TRUE if bit a is 1.
  6. OP = = (L BITS a,L BITS b)BOOL:
    Logical equality (synonym EQ).
  7. OP /= = (L BITS a,L BITS b)BOOL:
    Logical inequality (synonym NE).
  8. OP <= = (L BITS a,L BITS b)BOOL:
    Yields TRUE if each bit in the left operand implies the corresponding bit in the right operand (synonym LE).
  9. OP >= = (L BITS a,L BITS b)BOOL:
    Yields TRUE if each bit in the right operand implies the corresponding bit in the left operand (synonym GE).


Operators with CHAR operands

The shorthands in section 13.3.8 apply here.

  1. OP ABS = (CHAR a)INT:
    The integer equivalent of a character.
  2. OP REPR = (INT a)CHAR:
    The reverse of ABS. The operand should be in the range [0:max abs char].
  3. OP + = (CHAR a,CHAR b)STRING:
    The character b is appended to the character a (concatenation).
  4. OP E = (CHAR a,CHAR b)BOOL:
    Comparison of the arithmetic equivalents of a and b.


Operators with STRING operands

  1. OP + = (STRING a,STRING b)STRING:
    String b is appended to string a (concatenation).
  2. OP + = (CHAR a,STRING b)STRING:
    String b is appended to character a.
  3. OP + = (STRING a,CHAR b)STRING:
    Character b is appended to string a.
  4. OP * = (INT a,STRING b)STRING:
    Yields a lots of string b concatenated.
  5. OP * = (STRING a,INT b)STRING:
    Yields b lots of string a concatenated.
  6. OP * = (INT a,CHAR b)STRING:
    Yields a lots of character b concatenated.
  7. OP * = (CHAR a,INT b)STRING:
    Yields b lots of character a concatenated.
  8. OP < = (STRING a,STRING b)BOOL:
    The absolute value of each character of a is compared with the absolute value of the corresponding character in b (for the purpose of the comparison, the lower bounds of both strings are regarded as equal to 1). If the strings are equal upto the end of the shorter of the strings, then the longer string is the greater (synonym LT).
  9. OP <= = (STRING a,STRING b)BOOL:
    (synonym LE)
    The text for the operator < in this section applies.
  10. OP >= = (STRING a,STRING b)BOOL:
    (synonym GE)
    The text for the operator < in this section applies.
  11. OP > = (STRING a,STRING b)BOOL:
    (synonym GT)
    The text for the operator < in this section applies.
  12. OP = = (STRING a,STRING b)BOOL:
    If the strings differ in length, they are unequal, else they are compared as for the operator < in this section (synonym EQ).
  13. OP /= = (STRING a,STRING b)BOOL
    (synonym NE)
    If the strings differ in length, they are unequal, else they are compared as for the operator < in this section.
  14. OP E = (STRING a,CHAR b)BOOL:
    OP E = (CHAR a,STRING b)BOOL:
    The shorthand E as described in section 13.3.8 applies for these cases.


Assigning operators

Consistent substitution applies to all operators containing the L shorthand.

  1. +:= (synonym PLUSAB)
    The operator is a shorthand for 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
  2. +=: (synonym PLUSTO)
    The operator is a shorthand for b:=a+b.
    Left operand Right operand Yield
    STRING REF STRING REF STRING
    CHAR REF STRING REF STRING
  3. -:= (synonym MINUSAB)
    The operator is a shorthand for 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
  4. *:= (synonym TIMESAB)
    The operator is a shorthand for 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
  5. /:= (synonym DIVAB)
    The operator is a shorthand for 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

  6. OP %:= = (REF L INT a,L INT b)REF L INT:
    (synonym OVERAB)
    The operator is a shorthand for a:=a%b.
  7. OP %*:= = (REF L INT a,L INT b)REF L INT:
    (synonym MODAB)
    The operator is a shorthand for a:=a%*b.


Other operators

This section contains those operators which appear neither in the Revised Report nor in the section concerning a68toc extensions (section 13.5).

  1. OP &* = (REAL r,INT e)REAL:
    Multiply r by 2e. The routine does not use multiplication, but simply increments the exponent of r accordingly.
  2. OP ELEM = (INT a)BITS:
    The operator yields a value with all bits zero except the bit specified by the operand.
  3. OP MIN = (L INT a,L INT b)L INT:
    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:
    The lesser of the two operands.
  4. OP MAX = (L INT a,L INT b)L INT:
    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:
    The greater of the two operands.
  5. OP VALID = (REAL r)BOOL:
    Whether the real value r is a valid real in terms of the IEEE standard.
Sian Mountbatten 2012-01-19