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