DC(1) General Commands Manual DC(1)
dc - desk calculator
dc [ filename ]
dc is an arbitrary precision arithmetic package. Ordinarily it oper-
ates on decimal integers, but an input base, output base, and a number
of fractional digits to be maintained may be specified. The overall
structure of dc is a stacking (reverse Polish) calculator. If an argu-
ment is given, input is taken from that file until its end, and then
from the standard input.
Note: bc(1) is a preprocessor for dc that provides infix (normal arith-
metic) notation, a C-like syntax for functions, and reasonable control
structures for programs.
The following input constructs are recognized:
number Push a number onto the stack. A number is an unbroken string
of the digits 0-9. It may be preceded by an underscore `_'
to input a negative number, and may contain decimal points.
+ - / * % ^
The top two values on the stack are: added (+), subtracted
(-), multiplied (*), divided (/), remaindered (%), or expo-
nentiated (^). The two entries are popped off the stack and
the result is pushed in their place. Any fractional part of
an exponent is ignored.
sx Pop the top of the stack and store into a register named x,
where x is any character.
Sx Treat x as a stack and push the value onto it.
lx Push the value in register x onto the stack. The register x
is not altered. All registers start with zero value.
Lx Treat register x as a stack, and pop its top value onto the
d Duplicate the top value on the stack.
p Print the top value on the stack. The top value remains
P Interpret the top of the stack as an ASCII string, remove and
f Print all values on the stack and in registers.
q Exit the program. If executing a string, pop the recursion
level by two.
Q Pop the top value on the stack, and pop the string execution
level by that value.
x Treat the top element of the stack as a character string and
execute it as a string of dc commands.
X Replace the number on the top of the stack with its scale
[...] Put the bracketed ASCII string onto the top of the stack.
<<x >>x =x
Pop and compare top two elements of the stack. Execute reg-
ister x if they obey the stated relation.
v Replace the top element on the stack by its square root. Any
existing fractional part of the argument is taken into
account, but otherwise the scale factor is ignored.
! Interpret the rest of the line as a command.
c Clear all values on the stack.
i Pop the top value on the stack and use that value as the
I Push the input base on the top of the stack.
o Pop the top value on the stack and use as the output radix.
O Push the output base on the top of the stack.
k The top of the stack is popped, and that value is used as a
non-negative scale factor: the appropriate number of places
are printed on output, and maintained during multiplication,
division, and exponentiation. The interaction of scale fac-
tor, input base, and output base will be reasonable if all
are changed together.
z Push the stack level onto the stack.
Z Replace the number on the top of the stack with its length.
? Take a line of input from the input source (usually the ter-
minal) and execute it.
; : Used by bc for array operations.
Print the first ten values of n!
x is unimplemented Where x is an octal number.
stack empty For not enough elements on the stack to do what
Out of space When the free list is exhausted (too many dig-
Out of headers For too many numbers being kept around.
Out of pushdown For too many items on the stack.
Nesting Depth For too many levels of nested execution.
Base conversions on fractions are truncated to the number of fractional
digits of the input value. The values are not rounded.
23 September 1987 DC(1)