9070 Remove wanboot from gate
[unleashed.git] / usr / src / man / man1 / dc.1
blobf395d7e8a098c95e637e29b0a8960867cdabf2c0
1 '\" te
2 .\"  Copyright 1989 AT&T  Copyright (c) 2003, Sun Microsystems, Inc.  All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH DC 1 "Aug 29, 2003"
7 .SH NAME
8 dc \- desk calculator
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fB/usr/bin/dc\fR [\fIfilename\fR]
13 .fi
15 .LP
16 .nf
17 \fB/usr/xpg6/bin/dc\fR [\fIfilename\fR]
18 .fi
20 .SH DESCRIPTION
21 .sp
22 .LP
23 \fBdc\fR is an arbitrary precision arithmetic package. Ordinarily it operates
24 on decimal integers, but one may specify an input base, output base, and a
25 number of fractional digits to be maintained. The overall structure of \fBdc\fR
26 is a stacking (reverse Polish) calculator. If an argument is given, input is
27 taken from that file until its end, then from the standard input.
28 .sp
29 .LP
30 \fBbc\fR is a preprocessor for \fBdc\fR that provides infix notation and a
31 C-like syntax that implements functions. \fBbc\fR also provides reasonable
32 control structures for programs. See \fBbc\fR(1).
33 .SH USAGE
34 .SS "/usr/bin/dc, /usr/xpg6/bin/dc"
35 .sp
36 .LP
37 The following constructions are recognized under both \fB/usr/bin/dc\fR and
38 \fB/usr/xpg6/bin/dc\fR:
39 .sp
40 .ne 2
41 .na
42 \fB\fInumber\fR\fR
43 .ad
44 .RS 15n
45 The value of the number is pushed on the stack. A number is an  unbroken string
46 of the digits 0\(mi9. It may be preceded by an underscore (\fB_\fR) to input a
47 negative number. Numbers may  contain decimal points.
48 .RE
50 .sp
51 .ne 2
52 .na
53 \fB\fBs\fR\fIx\fR\fR
54 .ad
55 .RS 15n
56 The top of the stack is popped and stored into a register named \fIx\fR, where
57 \fIx\fR may be any character.  If the \fBs\fR is capitalized, \fIx\fR is
58 treated as a stack and the value is pushed on it.
59 .RE
61 .sp
62 .ne 2
63 .na
64 \fB\fBl\fR\fIx\fR\fR
65 .ad
66 .RS 15n
67 The value in register \fIx\fR is pushed on the stack. The register \fIx\fR is
68 not altered. All registers start with zero value.  If the \fBl\fR is
69 capitalized, register \fIx\fR is treated as a stack and its top value is popped
70 onto the main stack.
71 .RE
73 .sp
74 .ne 2
75 .na
76 \fB\fBd\fR\fR
77 .ad
78 .RS 15n
79 The top value on the stack is duplicated.
80 .RE
82 .sp
83 .ne 2
84 .na
85 \fB\fBp\fR\fR
86 .ad
87 .RS 15n
88 The top value on the stack is printed. The top value remains  unchanged.
89 .RE
91 .sp
92 .ne 2
93 .na
94 \fB\fBP\fR\fR
95 .ad
96 .RS 15n
97 Interprets the top of the stack as an ASCII string, removes it,  and prints it.
98 .RE
101 .ne 2
103 \fB\fBf\fR\fR
105 .RS 15n
106 All values on the stack are printed.
110 .ne 2
112 \fB\fBq\fR\fR
114 .RS 15n
115 Exits the program. If executing a string, the recursion level is popped by two.
119 .ne 2
121 \fB\fBQ\fR\fR
123 .RS 15n
124 Exits the program.  The top value on the stack is popped and the string
125 execution level is popped by that value.
129 .ne 2
131 \fB\fBx\fR\fR
133 .RS 15n
134 Treats the top element of the stack as a character string and executes it as a
135 string of \fBdc\fR commands.
139 .ne 2
141 \fB\fBX\fR\fR
143 .RS 15n
144 Replaces the number on the top of the stack with its scale factor.
148 .ne 2
150 \fB\fB[ ... ]\fR\fR
152 .RS 15n
153 Puts the bracketed ASCII string onto the top of the stack.
157 .ne 2
159 \fB\fB<\fR\fIx \fR \fB>\fR\fIx \fR \fB=\fR\fIx \fR\fR
161 .RS 15n
162 The top two elements of the stack are popped and compared. Register \fIx\fR is
163 evaluated if they obey the stated relation.
167 .ne 2
169 \fB\fBv\fR\fR
171 .RS 15n
172 Replaces the top element on the stack by its square root.  Any  existing
173 fractional part of the argument is taken into account, but  otherwise the scale
174 factor is ignored.
178 .ne 2
180 \fB\fB!\fR\fR
182 .RS 15n
183 Interprets the rest of the line as a shell command.
187 .ne 2
189 \fB\fBc\fR\fR
191 .RS 15n
192 All values on the stack are popped.
196 .ne 2
198 \fB\fBi\fR\fR
200 .RS 15n
201 The top value on the stack is popped and used as the number radix  for further
202 input.
206 .ne 2
208 \fB\fBI\fR\fR
210 .RS 15n
211 Pushes the input base on the top of the stack.
215 .ne 2
217 \fB\fBo\fR\fR
219 .RS 15n
220 The top value on the stack is popped and used as the number radix for  further
221 output.
225 .ne 2
227 \fB\fBO\fR\fR
229 .RS 15n
230 Pushes the output base on the top of the stack.
234 .ne 2
236 \fB\fBk\fR\fR
238 .RS 15n
239 The top of the stack is popped, and that value is used as a  non-negative scale
240 factor: the appropriate number of places are  printed on output, and maintained
241 during multiplication, division,  and exponentiation.  The interaction of scale
242 factor, input base, and  output base will be reasonable if all are changed
243 together.
247 .ne 2
249 \fB\fBK\fR\fR
251 .RS 15n
252 Pushes the current scale factor on the top of the stack.
256 .ne 2
258 \fB\fBz\fR\fR
260 .RS 15n
261 The stack level is pushed onto the stack.
265 .ne 2
267 \fB\fBZ\fR\fR
269 .RS 15n
270 Replaces the number on the top of the stack with its length.
274 .ne 2
276 \fB\fB?\fR\fR
278 .RS 15n
279 A line of input is taken from the input source (usually the terminal) and
280 executed.
284 .ne 2
286 \fB\fBY\fR\fR
288 .RS 15n
289 Displays \fBdc\fR debugging information.
293 .ne 2
295 \fB\fB; :\fR\fR
297 .RS 15n
298 Used by  \fBbc\fR(1) for array operations.
301 .SS "/usr/bin/dc"
304 The following construction is recognized under \fB/usr/bin/dc\fR, using the
305 scale of whatever the result is.
307 .ne 2
309 \fB\fB+ \(mi / * % ^\fR\fR
311 .RS 18n
312 The top two values on the stack are added (\fB+\fR), subtracted (\fB\(mi\fR),
313 multiplied (\fB*\fR), divided (\fB/\fR), remaindered (\fB%\fR), or
314 exponentiated (\fB^\fR). The two entries are popped off the stack; the result
315 is pushed on the stack in their place. Any fractional part of an exponent is
316 ignored.
319 .SS "/usr/xpg6/bin/dc"
322 The following construction is recognized under \fB/usr/xpg6/bin/dc\fR. The
323 results of division are forced to be a scale of 20.
325 .ne 2
327 \fB\fB+ \(mi / * % ^\fR\fR
329 .RS 18n
330 The top two values on the stack are added (\fB+\fR), subtracted (\fB\(mi\fR),
331 multiplied (\fB*\fR), divided (\fB/\fR), remaindered (\fB%\fR), or
332 exponentiated (\fB^\fR). The two entries are popped off the stack. The result
333 is pushed on the stack in their place. Any fractional part of an exponent is
334 ignored.
336 Ensures that the scale set prior to division is the scale of the result.
339 .SH EXAMPLES
341 \fBExample 1 \fRPrinting the first ten values of n!
344 This example prints the first ten values of n!:
347 .in +2
349 [la1+dsa*pla10>y]sy
350 0sa1
353 .in -2
356 .SH SEE ALSO
359 \fBbc\fR(1), \fBattributes\fR(5)
360 .SH DIAGNOSTICS
362 .ne 2
364 \fB\fIx\fR \fBis unimplemented\fR\fR
366 .RS 29n
367 \fIx\fR is an octal number.
371 .ne 2
373 \fB\fBout of space\fR\fR
375 .RS 29n
376 The free list is exhausted (too many digits).
380 .ne 2
382 \fB\fBout of stack space\fR\fR
384 .RS 29n
385 Too many pushes onto the stack (stack overflow).
389 .ne 2
391 \fB\fBempty stack\fR\fR
393 .RS 29n
394 Too many pops from the stack (stack underflow).
398 .ne 2
400 \fB\fBnesting depth\fR\fR
402 .RS 29n
403 Too many levels of nested execution.
407 .ne 2
409 \fB\fBdivide by 0\fR\fR
411 .RS 29n
412 Division by zero.
416 .ne 2
418 \fB\fBsqrt of neg number\fR\fR
420 .RS 29n
421 Square root of a negative number is not defined (no imaginary numbers).
425 .ne 2
427 \fB\fBexp not an integer\fR\fR
429 .RS 29n
430 \fBdc\fR only processes integer exponentiation.
434 .ne 2
436 \fB\fBexp too big\fR\fR
438 .RS 29n
439 The largest exponent allowed is 999.
443 .ne 2
445 \fB\fBinput base is too large\fR\fR
447 .RS 29n
448 The input base x: 2<= x <= 16.
452 .ne 2
454 \fB\fBinput base is too small\fR\fR
456 .RS 29n
457 The input base x: 2<= x <= 16.
461 .ne 2
463 \fB\fBoutput base is too large\fR\fR
465 .RS 29n
466 The output base must be no larger than  \fBBC_BASE_MAX\fR.
470 .ne 2
472 \fB\fBinvalid scale factor\fR\fR
474 .RS 29n
475 Scale factor cannot be less than 1.
479 .ne 2
481 \fB\fBscale factor is too large\fR\fR
483 .RS 29n
484 A scale factor cannot be larger than  \fBBC_SCALE_MAX\fR.
488 .ne 2
490 \fB\fBsymbol table overflow\fR\fR
492 .RS 29n
493 Too many variables have been specified.
497 .ne 2
499 \fB\fBinvalid index\fR\fR
501 .RS 29n
502 Index cannot be less than 1.
506 .ne 2
508 \fB\fBindex is too large\fR\fR
510 .RS 29n
511 An index cannot be larger than  \fBBC_DIM_MAX\fR.