Research V7 development
[unix-history] / usr / man / man1 / dc.1
CommitLineData
e98c27ab
LC
1.TH DC 1
2.SH NAME
3dc \- desk calculator
4.SH SYNOPSIS
5.B dc
6[ file ]
7.SH DESCRIPTION
8.I Dc
9is an arbitrary precision arithmetic package.
10Ordinarily it operates on decimal integers,
11but one may specify an input base, output base,
12and a number of fractional digits to be maintained.
13The overall structure of
14.I dc
15is
16a stacking (reverse Polish) calculator.
17If an argument is given,
18input is taken from that file until its end,
19then from the standard input.
20The following constructions are recognized:
21.HP 6
22number
23.br
24The value of the number is pushed on the stack.
25A number is an unbroken string of the digits 0-9.
26It may be preceded by an underscore _ to input a
27negative number.
28Numbers may contain decimal points.
29.HP 6
30+ \- / * % ^
31.br
32The
33top two values on the stack are added
34(+),
35subtracted
36(\-),
37multiplied (*),
38divided (/),
39remaindered (%),
40or exponentiated (^).
41The two entries are popped off the stack;
42the result is pushed on the stack in their place.
43Any fractional part of an exponent is ignored.
44.TP
45.BI s x
46The
47top of the stack is popped and stored into
48a register named
49.I x,
50where
51.I x
52may be any character.
53If
54the
55.B s
56is capitalized,
57.I x
58is treated as a stack and the value is pushed on it.
59.TP
60.BI l x
61The
62value in register
63.I x
64is pushed on the stack.
65The register
66.I x
67is not altered.
68All registers start with zero value.
69If the
70.B l
71is capitalized,
72register
73.I x
74is treated as a stack and its top value is popped onto the main stack.
75.TP
76.B d
77The
78top value on the stack is duplicated.
79.TP
80.B p
81The top value on the stack is printed.
82The top value remains unchanged.
83.B P
84interprets the top of the stack as an ascii string,
85removes it, and prints it.
86.TP
87.B f
88All values on the stack and in registers are printed.
89.TP
90.B q
91exits the program.
92If executing a string, the recursion level is
93popped by two.
94If
95.B q
96is capitalized,
97the top value on the stack is popped and the string execution level is popped
98by that value.
99.TP
100.B x
101treats the top element of the stack as a character string
102and executes it as a string of dc commands.
103.TP
104.B X
105replaces the number on the top of the stack with its scale factor.
106.TP
107.B "[ ... ]"
108puts the bracketed ascii string onto the top of the stack.
109.HP 6
110.I "<x >x =x"
111.br
112The
113top two elements of the stack are popped and compared.
114Register
115.I x
116is executed if they obey the stated
117relation.
118.TP
119.B v
120replaces the top element on the stack by its square root.
121Any existing fractional part of the argument is taken
122into account, but otherwise the scale factor is ignored.
123.TP
124.B !
125interprets the rest of the line as a UNIX command.
126.TP
127.B c
128All values on the stack are popped.
129.TP
130.B i
131The top value on the stack is popped and used as the
132number radix for further input.
133.B I
134pushes the input base on the top of the stack.
135.TP
136.B o
137The top value on the stack is popped and used as the
138number radix for further output.
139.TP
140.SM
141.B O
142pushes the output base on the top of the stack.
143.TP
144.B k
145the top of the stack is popped, and that value is used as
146a non-negative scale factor:
147the appropriate number of places
148are printed on output,
149and maintained during multiplication, division, and exponentiation.
150The interaction of scale factor,
151input base, and output base will be reasonable if all are changed
152together.
153.TP
154.B z
155The stack level is pushed onto the stack.
156.TP
157.SM
158.B Z
159replaces the number on the top of the stack with its length.
160.TP
161.B ?
162A line of input is taken from the input source (usually the terminal)
163and executed.
164.TP
165.B "; :"
166are used by
167.I bc
168for array operations.
169.PP
170An example which prints the first ten values of n! is
171.nf
172.PP
173.in +3
174[la1+dsa*pla10>y]sy
175.br
1760sa1
177.br
178lyx
179.fi
180.SH "SEE ALSO"
181bc(1),
182which is a preprocessor for
183.I dc
184providing infix notation and a C-like syntax
185which implements functions and reasonable control
186structures for programs.
187.SH DIAGNOSTICS
188`x is unimplemented' where x is an octal number.
189.br
190`stack empty' for not enough elements on the stack to do what was asked.
191.br
192`Out of space' when the free list is exhausted (too many digits).
193.br
194`Out of headers' for too many numbers being kept around.
195.br
196`Out of pushdown' for too many items on the stack.
197.br
198`Nesting Depth' for too many levels of nested execution.