MPE/iX Shell and Utilities Reference Manual, Vol 1

bc(1) MPE/iX Shell and Utilities bc(1)
Long numbers are output with a maximum of 70 characters per line. If a number is longer
than this, bc puts a backslash (\) at the end of the line, indicating that the number is con-
tinued on the next line.
Internal calculations are performed in decimal, regardless of the input and output bases.
Therefore, the number of places after the decimal point are dictated by the scale when num-
bers are expressed in decimal form.
The maximum value for obase is given by the configuration variable {BC_BASE_MAX}.
Arithmetic Operations
bc provides a large number of arithmetic operations. Following standard arithmetic conven-
tions, some operations are calculated before others; for example, multiplication take place
before addition unless you use parentheses to group operations. Operations that take place
first are said to have a higher precedence than operations which take place later.
Operations also have an associativity. The associativity dictates the order of evaluation when
you have a sequence of operations with equal precedence. Some operations are evaluated left
to right while others are evaluated right to left. The Operator Associativity table shows the
operators of bc from highest precedence to lowest. Programmers familiar with C will note
that bc’s order of precedence is not the same as C’s. In C, assignment operators have the
lowest precedence. The precedence is shown in Table 1-3, bc Operators.
Operator Associativity
() left to right
unary ++ -- not applicable
unary -! not applicable
ˆ right to left
*/% left to right
+- left to right
=*=/=%=+= right to left
== <= >= != < > none
&& left to right
|| left to right
Table 1-3: bc Operators
The following list describes each operator. In the descriptions, A and B can be numbers, vari-
ables, array elements, or other expressions. V must be either a variable or an array element.
(A) An expression in parentheses is evaluated before any other operations are per-
formed on it.
Commands and Utilities 1-49