dc(1) dc(1)
NAME
dc - desk calculator
SYNOPSIS
dc [file]
ARGUMENTS
file Specifies the file from which the input is used.
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.
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.
+ - / * % ^
Operates 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 in 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.
January 1992 1
dc(1) dc(1)
f Prints all values on the stack.
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 will be reasonable if all are changed together.
z Pushes the stack level onto the stack.
2 January 1992
dc(1) dc(1)
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.
; : Allows bc to perform array operations.
EXAMPLES
The command:
dc
24.2 56.2 + p
adds the two numbers and prints the result (top value in the
stack).
The command:
[la1+dsa*pla10>y]sy
0sa1
lyx
prints the first ten values of n!.
STATUS MESSAGES AND VALUES
x is unimplemented
The argument, x, is an octal number.
stack empty
Not enough elements on the stack to do what was asked.
Out of space
The free list is exhausted (too many digits).
Out of headers
Too many numbers being kept around.
Out of pushdown
Too many items on the stack.
Nesting Depth
Too many levels of nested execution.
FILES
/usr/bin/dc
Executable file
SEE ALSO
bc(1)
January 1992 3
``dc Reference,'' in A/UX Programming Languages and Tools,
Volume 2
4 January 1992