MPE/iX Shell and Utilities Reference Manual, Vol 1

bc(1) MPE/iX Shell and Utilities bc(1)
displays
4
By default, bc displays the result of any evaluated instruction followed by a newline. bc also
saves the last value displayed in a special variable . so that you can use it in subsequent cal-
culations.
Numbers
Numbers consist of an optional minus () sign followed by a sequence of zero or more digits,
followed by an optional decimal point (.), followed by a sequence of zero or more digits.
Valid digits are 0 through 9, and the hexadecimal digits A through F. The uppercase letters
represent the values from 10 through 15. There must be at least one digit, either before or
after the decimal point. If not, bc interprets the decimal point as the special variable . men-
tioned earlier.
A number can be arbitrarily long and may contain spaces. Here are some valid numbers with
an input base of 10:
0 0. .0 -3.14159 +09. -12 1 000 000
Here are some valid numbers with an input base of 16 (ibase=16):
0 FF FF.3 -10.444 A1
See Bases for more information.
A final point is that you cannot break up numbers with commas; you can write 1000000 or 1
000 000, but 1,000,000 results in an error message.
Identifiers
Identifiers are used as names for variables, functions, or arrays. Valid identifiers may include
sequences containing any number of letters, digits or the underscore (_) character, but must
start with a lowercase letter. Spaces are not allowed in identifiers. The ability to use identif-
iers more than one character in length is an extension not found in traditional implementations
of bc.
A variable holds a single numeric value. You can declare variables as local to a function
using the auto statement (see Functions). All other variables are global and can be used
anywhere. You do not need to declare global variables. bc creates variables as it
requires them, with an initial value of zero. (Remember that there is also the special vari-
able . (dot) which contains the result of the last calculation.)
A function is a sequence of instructions that calculates a single value. A list of zero or
more values enclosed in parentheses always follow a function name, as in
my_func(3.14159). See Functions later in this man page.
1-46 Commands and Utilities