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