1dc(1) User Commands dc(1)
2
3
4
6 dc - desk calculator
7
9 /usr/bin/dc [filename]
10
11
12 /usr/xpg6/bin/dc [filename]
13
14
16 dc is an arbitrary precision arithmetic package. Ordinarily it operates
17 on decimal integers, but one may specify an input base, output base,
18 and a number of fractional digits to be maintained. The overall struc‐
19 ture of dc is a stacking (reverse Polish) calculator. If an argument is
20 given, input is taken from that file until its end, then from the stan‐
21 dard input.
22
23
24 bc is a preprocessor for dc that provides infix notation and a C-like
25 syntax that implements functions. bc also provides reasonable control
26 structures for programs. See bc(1).
27
29 /usr/bin/dc, /usr/xpg6/bin/dc
30 The following constructions are recognized under both /usr/bin/dc and
31 /usr/xpg6/bin/dc:
32
33 number The value of the number is pushed on the stack. A number
34 is an unbroken string of the digits 0−9. It may be pre‐
35 ceded by an underscore (_) to input a negative number.
36 Numbers may contain decimal points.
37
38
39 sx The top of the stack is popped and stored into a regis‐
40 ter named x, where x may be any character. If the s is
41 capitalized, x is treated as a stack and the value is
42 pushed on it.
43
44
45 lx The value in register x is pushed on the stack. The reg‐
46 ister x is not altered. All registers start with zero
47 value. If the l is capitalized, register x is treated
48 as a stack and its top value is popped onto the main
49 stack.
50
51
52 d The top value on the stack is duplicated.
53
54
55 p The top value on the stack is printed. The top value
56 remains unchanged.
57
58
59 P Interprets the top of the stack as an ASCII string,
60 removes it, and prints it.
61
62
63 f All values on the stack are printed.
64
65
66 q Exits the program. If executing a string, the recursion
67 level is popped by two.
68
69
70 Q Exits the program. The top value on the stack is popped
71 and the string execution level is popped by that value.
72
73
74 x Treats the top element of the stack as a character
75 string and executes it as a string of dc commands.
76
77
78 X Replaces the number on the top of the stack with its
79 scale factor.
80
81
82 [ ... ] Puts the bracketed ASCII string onto the top of the
83 stack.
84
85
86 <x >x =x The top two elements of the stack are popped and com‐
87 pared. Register x is evaluated if they obey the stated
88 relation.
89
90
91 v Replaces the top element on the stack by its square
92 root. Any existing fractional part of the argument is
93 taken into account, but otherwise the scale factor is
94 ignored.
95
96
97 ! Interprets the rest of the line as a shell command.
98
99
100 c All values on the stack are popped.
101
102
103 i The top value on the stack is popped and used as the
104 number radix for further input.
105
106
107 I Pushes the input base on the top of the stack.
108
109
110 o The top value on the stack is popped and used as the
111 number radix for further output.
112
113
114 O Pushes the output base on the top of the stack.
115
116
117 k The top of the stack is popped, and that value is used
118 as a non-negative scale factor: the appropriate number
119 of places are printed on output, and maintained during
120 multiplication, division, and exponentiation. The
121 interaction of scale factor, input base, and output
122 base will be reasonable if all are changed together.
123
124
125 K Pushes the current scale factor on the top of the stack.
126
127
128 z The stack level is pushed onto the stack.
129
130
131 Z Replaces the number on the top of the stack with its
132 length.
133
134
135 ? A line of input is taken from the input source (usually
136 the terminal) and executed.
137
138
139 Y Displays dc debugging information.
140
141
142 ; : Used by bc(1) for array operations.
143
144
145 /usr/bin/dc
146 The following construction is recognized under /usr/bin/dc, using the
147 scale of whatever the result is.
148
149 + − / * % ^ The top two values on the stack are added (+), sub‐
150 tracted (−), multiplied (*), divided (/), remaindered
151 (%), or exponentiated (^). The two entries are popped
152 off the stack; the result is pushed on the stack in
153 their place. Any fractional part of an exponent is
154 ignored.
155
156
157 /usr/xpg6/bin/dc
158 The following construction is recognized under /usr/xpg6/bin/dc. The
159 results of division are forced to be a scale of 20.
160
161 + − / * % ^ The top two values on the stack are added (+), sub‐
162 tracted (−), multiplied (*), divided (/), remaindered
163 (%), or exponentiated (^). The two entries are popped
164 off the stack. The result is pushed on the stack in
165 their place. Any fractional part of an exponent is
166 ignored.
167
168 Ensures that the scale set prior to division is the
169 scale of the result.
170
171
173 Example 1 Printing the first ten values of n!
174
175
176 This example prints the first ten values of n!:
177
178
179 [la1+dsa*pla10>y]sy
180 0sa1
181 lyx
182
183
184
186 See attributes(5) for descriptions of the following attributes:
187
188
189
190
191 ┌─────────────────────────────┬─────────────────────────────┐
192 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
193 ├─────────────────────────────┼─────────────────────────────┤
194 │Availability │SUNWesu │
195 └─────────────────────────────┴─────────────────────────────┘
196
198 bc(1), attributes(5)
199
201 x is unimplemented x is an octal number.
202
203
204 out of space The free list is exhausted (too many dig‐
205 its).
206
207
208 out of stack space Too many pushes onto the stack (stack
209 overflow).
210
211
212 empty stack Too many pops from the stack (stack under‐
213 flow).
214
215
216 nesting depth Too many levels of nested execution.
217
218
219 divide by 0 Division by zero.
220
221
222 sqrt of neg number Square root of a negative number is not
223 defined (no imaginary numbers).
224
225
226 exp not an integer dc only processes integer exponentiation.
227
228
229 exp too big The largest exponent allowed is 999.
230
231
232 input base is too large The input base x: 2<= x <= 16.
233
234
235 input base is too small The input base x: 2<= x <= 16.
236
237
238 output base is too large The output base must be no larger than
239 BC_BASE_MAX.
240
241
242 invalid scale factor Scale factor cannot be less than 1.
243
244
245 scale factor is too large A scale factor cannot be larger than
246 BC_SCALE_MAX.
247
248
249 symbol table overflow Too many variables have been specified.
250
251
252 invalid index Index cannot be less than 1.
253
254
255 index is too large An index cannot be larger than
256 BC_DIM_MAX.
257
258
259
260
261SunOS 5.11 29 Aug 2003 dc(1)