Copyright © 1996, 1997 Lucent Technologies Inc. All rights reserved.

8.3 Binary expressions

Binary expressions are either monadic expressions, or have two operands and an infix operator; the syntax is


binary-expression: monadic-expression binary-expression binary-operator binary-expression binary-operator: one of * / % + - << >> < > <= >= == != & ^ | :: && ||
All these binary operators are left-associative except for ::, which associates to the right. Their precedence is as listed here, with tightest first:
			* / %
			+ -
			<< >>
			< > <= >=
			== !=
			&
			^
			|
			::
			&&
			||

8.3.1 Multiplicative operators

The *, /, and % operators respectively accomplish multiplication, division, and remainder. The operands must be of identical arithmetic type, and the result has that same type. The remainder operator does not apply to type real. If overflow or division by 0 occurs, the result is undefined. The absolute value of a%b is less than the absolute value of b; (a/b)*b + a%b is always equal to a; and a%b is non-negative if a and b are.

8.3.2 Additive operators

The + and - operators respectively accomplish addition and subtraction of arithmetic operands of identical type; the result has the same type. The behavior on overflow or underflow is undefined. The + operator may also be applied to strings; the result is a string that is the concatenation of the operands.

8.3.3 Shift operators

The shift operators are << and >>. The left operand may be big, int, or byte; the right operand is int. The type of the value is the same as its left operand. The value of the right operand must be non-negative and smaller than the number of bits in the left operand. For the left-shift operator <<, the fill bits are 0; for the right-shift operator >>, the fill bits are a copy of the sign for the int case, and 0 for the byte case.

8.3.4 Relational operators

The relational operators are < (less than), > (greater than), <= (less than or equal), >= (greater than or equal), == (equal to), != (not equal to). The first four operators, which generate orderings, apply only to arithmetic types and to strings; the types of their operands must be identical, except that a string may be compared to nil. Comparison on strings is lexicographic over the Unicode character set.

The equality operators == and != accept operands of arithmetic, string, and reference types. In general, the operands must have identical type, but reference types and strings may be compared for identity with nil. Equality for reference types occurs when the operands refer to the same object, or when both are nil. An uninitialized string, or one set to nil, is identical to the empty string denoted "" for all the relational operators.

The value of any comparison is the int value 1 if the stated relation is true, 0 if it is false.

8.3.5 Bitwise logical operators

The logical operators & (and), ^ (exclusive or) and | (inclusive or) require operands of the same type, which must be byte, int, or big. The result has the same type and its value is obtained by applying the operation bitwise.

8.3.6 List concatenation

The concatenation operator :: takes a object of any data type as its left operand and a list as its right operand. The list's underlying type must be the same as the type of the left operand. The result is a new list with the left operand tacked onto the front:

	hd (a :: l)
is the same as a.

8.3.7 Logical operators

The logical and operator && first evaluates its left operand. If the result is zero, then the value of the whole expression is the int value 0. Otherwise the right operand is evaluated; if the result is zero, the value of the whole expression is again 0; otherwise it is 1. The operands must have the same arithmetic type.

The logical or operator || first evaluates its left operand. If the result is non-zero, then the value of the whole expression is the int value 1. Otherwise the right operand is evaluated; if the result is non-zero, the value of the whole expression is again 1; otherwise it is 0. The operands must have the same arithmetic type.

05/Jun/97