dc(1) dc(1)
NAME
dc - desk calculator
SYNOPSIS
dc [file]
DESCRIPTION
dc is an arbitrary precision arithmetic package. Ordinarily
it operates on decimal integers, but one may specify an
input base, output base, and a number of fractional digits
to be maintained. The overall structure of dc is a stacking
(reverse Polish) calculator. If an argument is given, input
is taken from that file until its end, then from the
standard input. The following constructions are recognized:
number Pushes the value of number on the stack. A
number is an unbroken string of one or more
digits in the range 0-9. It may be preceded
by an underscore () to indicate a negative
number. Numbers may contain decimal points.
+ - / * % ^ Operate on the top two values on the stack.
These are added (+), subtracted (-),
multiplied (*), divided (/), remaindered (%),
or exponentiated (^). The two entries are
popped off the stack; the result is pushed on
the stack in their place. Any fractional part
of an exponent is ignored.
sx Pops the top of the stack and stores it into a
register named x, where x may be any
character.
Sx Pushes the value on x, which is treated as a
stack.
lx Pushes the value in register x on the stack.
The register x is not altered. All registers
start with zero value.
Lx Pops the top value of register x, which is
treated as a stack, onto the main stack.
d Duplicates the top value on the stack.
p Prints the top value on the stack. The top
value remains unchanged.
P Interprets the top of the stack as an ASCII
string, removes it, and prints it.
f Prints all values on the stack.
Page 1 (last mod. 1/16/87)
dc(1) dc(1)
q Exits the program. If executing a string, the
recursion level is popped by two.
Alternately, CONTROL-d (EOF) will exit from
dc.
Q Pops the top value on the stack and pops the
string execution level by that value.
Alternately, CONTROL-d (EOF) will exit from
dc.
x Treats the top element of the stack as a
character string and executes it as a string
of dc commands.
X Replaces the number on the top of the stack
with its scale factor.
[string] Puts the bracketed ASCII string onto the top
of the stack.
<x >x =x
Pops the top two elements of the stack and
compares them. Register x is evaluated if
they obey the stated relation.
v Replaces 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.
! Interprets the rest of the line as a system
command.
c Pops all values on the stack.
i Pops the top value on the stack and uses it as
the number radix for further input.
I Pushes the input base on the top of the stack.
o Pops the top value on the stack and uses it as
the number radix for further output.
O Pushes the output base on the top of the
stack.
k Pops the top of the stack and uses that value
as a non-negative scale factor: prints the
appropriate number of places on output, and
maintains them during multiplication,
division, and exponentiation. The interaction
of scale factor, input base, and output base
Page 2 (last mod. 1/16/87)
dc(1) dc(1)
will be reasonable if all are changed
together.
z Pushes the stack level onto the stack.
Z Replaces the number on the top of the stack
with its length.
? Takes a line of input from the input source
(usually the terminal) and executes it.
; : Allow bc to perform array operations.
EXAMPLE
dc
24.2 56.2 + p
adds the two numbers and prints the result (top value in the
stack).
[la1+dsa*pla10>y]sy
0sa1
lyx
prints the first ten values of n!.
FILES
/usr/bin/dc
SEE ALSO
bc(1).
(bc is a preprocessor for dc, providing infix notation and a
C-like syntax, which implements functions and reasonable
control structures for programs.)
DIAGNOSTICS
x is unimplemented where x is an octal number.
stack empty for not enough elements on the stack
to do what was asked.
Out of space when the free list is exhausted (too
many digits).
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.
Page 3 (last mod. 1/16/87)