Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
User Commands (a - b) bc(1)
NAME
bc - Arbitrary-precision arithmetic language processor
SYNOPSIS
bc [-cl][file ...]
The bc command is an interactive program that provides unlimited precision arithmetic. It is
a preprocessor for the dc command.
FLAGS
-c Compiles file, 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) flag is specified. If the
-c flag is specified, 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 first from the specified file. This input file 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 file, it reads standard input.
The following are valid items that can be used in the input file 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 significant decimal digits
scale (expression) Number of digits to right of decimal point
letter (expression,...,expression)
527188-003 Hewlett-Packard Company 1−31