Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)

User Commands (a - b) bc(1)
NAME
bc - Arbitrary-precision arithmetic language processor
SYNOPSIS
bc [-cl][le ...]
The bc command is an interactive program that provides unlimited precision arithmetic. It is
a preprocessor for the dc command.
FLAGS
-c Compiles le, but does not invoke dc.
-l Includes a library of mathematical functions and initializes scale to 20, instead of the
default of 0 (zero).
DESCRIPTION
The bc command invokes dc automatically, unless the -c (compile only) ag is specied. If the
-c ag is specied, the output from bc goes to the standard output.
The bc command lets you specify an input and output base in decimal, octal, or hexadecimal
with the ibase and obase keywords (the default is decimal). The command also has a scaling
provision for decimal point notation through the scale keyword. The syntax for bc is similar to
that of the C language.
The bc command takes input rst from the specied le. This input le can contain additional
functions besides internal functions such as sqrt and length, and functions included in the math
library. When bc reaches the end of the input le, it reads standard input.
The following are valid items that can be used in the input le and for standard input. In the fol-
lowing description of syntax for bc, letter means one of the ASCII letters a-z.
The combination of a \ (backslash) character immediately followed by a newline character
delimits lexical tokens with the following exceptions:
When it is interpreted as a literal newline character in STRING tokens
When it is ignored as part of a multiline NUMBER token
Comments
Comments are enclosed in /* and */.
Names
Simple variables: letter
Array elements: letter[expression]
The words ibase, obase, and scale
Other Operands
Arbitrarily long numbers with optional sign and decimal point.
(expression)
sqrt (expression)
length (expression) Number of signicant decimal digits
scale (expression) Number of digits to right of decimal point
letter (expression,...,expression)
527188-004 Hewlett-Packard Company 131