Move everything from /var/adm to /var/log
[unleashed.git] / share / man / man1 / dc.1
blob4d5f8a719984976abf89fd4473c140054e43b6b3
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 "Oct 25, 2017"
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 .SH DESCRIPTION
16 .sp
17 .LP
18 \fBdc\fR is an arbitrary precision arithmetic package. Ordinarily it operates
19 on decimal integers, but one may specify an input base, output base, and a
20 number of fractional digits to be maintained. The overall structure of \fBdc\fR
21 is a stacking (reverse Polish) calculator. If an argument is given, input is
22 taken from that file until its end, then from the standard input.
23 .sp
24 .LP
25 \fBbc\fR is a preprocessor for \fBdc\fR that provides infix notation and a
26 C-like syntax that implements functions. \fBbc\fR also provides reasonable
27 control structures for programs. See \fBbc\fR(1).
28 .SH USAGE
29 .sp
30 .LP
31 The following constructions are recognized:
32 .sp
33 .ne 2
34 .na
35 \fB\fInumber\fR\fR
36 .ad
37 .RS 15n
38 The value of the number is pushed on the stack. A number is an  unbroken string
39 of the digits 0\(mi9. It may be preceded by an underscore (\fB_\fR) to input a
40 negative number. Numbers may  contain decimal points.
41 .RE
43 .sp
44 .ne 2
45 .na
46 \fB\fBs\fR\fIx\fR\fR
47 .ad
48 .RS 15n
49 The top of the stack is popped and stored into a register named \fIx\fR, where
50 \fIx\fR may be any character.  If the \fBs\fR is capitalized, \fIx\fR is
51 treated as a stack and the value is pushed on it.
52 .RE
54 .sp
55 .ne 2
56 .na
57 \fB\fBl\fR\fIx\fR\fR
58 .ad
59 .RS 15n
60 The value in register \fIx\fR is pushed on the stack. The register \fIx\fR is
61 not altered. All registers start with zero value.  If the \fBl\fR is
62 capitalized, register \fIx\fR is treated as a stack and its top value is popped
63 onto the main stack.
64 .RE
66 .sp
67 .ne 2
68 .na
69 \fB\fBd\fR\fR
70 .ad
71 .RS 15n
72 The top value on the stack is duplicated.
73 .RE
75 .sp
76 .ne 2
77 .na
78 \fB\fBp\fR\fR
79 .ad
80 .RS 15n
81 The top value on the stack is printed. The top value remains  unchanged.
82 .RE
84 .sp
85 .ne 2
86 .na
87 \fB\fBP\fR\fR
88 .ad
89 .RS 15n
90 Interprets the top of the stack as an ASCII string, removes it,  and prints it.
91 .RE
93 .sp
94 .ne 2
95 .na
96 \fB\fBf\fR\fR
97 .ad
98 .RS 15n
99 All values on the stack are printed.
103 .ne 2
105 \fB\fBq\fR\fR
107 .RS 15n
108 Exits the program. If executing a string, the recursion level is popped by two.
112 .ne 2
114 \fB\fBQ\fR\fR
116 .RS 15n
117 Exits the program.  The top value on the stack is popped and the string
118 execution level is popped by that value.
122 .ne 2
124 \fB\fBx\fR\fR
126 .RS 15n
127 Treats the top element of the stack as a character string and executes it as a
128 string of \fBdc\fR commands.
132 .ne 2
134 \fB\fBX\fR\fR
136 .RS 15n
137 Replaces the number on the top of the stack with its scale factor.
141 .ne 2
143 \fB\fB[ ... ]\fR\fR
145 .RS 15n
146 Puts the bracketed ASCII string onto the top of the stack.
150 .ne 2
152 \fB\fB<\fR\fIx \fR \fB>\fR\fIx \fR \fB=\fR\fIx \fR\fR
154 .RS 15n
155 The top two elements of the stack are popped and compared. Register \fIx\fR is
156 evaluated if they obey the stated relation.
160 .ne 2
162 \fB\fBv\fR\fR
164 .RS 15n
165 Replaces the top element on the stack by its square root.  Any  existing
166 fractional part of the argument is taken into account, but  otherwise the scale
167 factor is ignored.
171 .ne 2
173 \fB\fB!\fR\fR
175 .RS 15n
176 Interprets the rest of the line as a shell command.
180 .ne 2
182 \fB\fBc\fR\fR
184 .RS 15n
185 All values on the stack are popped.
189 .ne 2
191 \fB\fBi\fR\fR
193 .RS 15n
194 The top value on the stack is popped and used as the number radix  for further
195 input.
199 .ne 2
201 \fB\fBI\fR\fR
203 .RS 15n
204 Pushes the input base on the top of the stack.
208 .ne 2
210 \fB\fBo\fR\fR
212 .RS 15n
213 The top value on the stack is popped and used as the number radix for  further
214 output.
218 .ne 2
220 \fB\fBO\fR\fR
222 .RS 15n
223 Pushes the output base on the top of the stack.
227 .ne 2
229 \fB\fBk\fR\fR
231 .RS 15n
232 The top of the stack is popped, and that value is used as a  non-negative scale
233 factor: the appropriate number of places are  printed on output, and maintained
234 during multiplication, division,  and exponentiation.  The interaction of scale
235 factor, input base, and  output base will be reasonable if all are changed
236 together.
240 .ne 2
242 \fB\fBK\fR\fR
244 .RS 15n
245 Pushes the current scale factor on the top of the stack.
249 .ne 2
251 \fB\fBz\fR\fR
253 .RS 15n
254 The stack level is pushed onto the stack.
258 .ne 2
260 \fB\fBZ\fR\fR
262 .RS 15n
263 Replaces the number on the top of the stack with its length.
267 .ne 2
269 \fB\fB?\fR\fR
271 .RS 15n
272 A line of input is taken from the input source (usually the terminal) and
273 executed.
277 .ne 2
279 \fB\fBY\fR\fR
281 .RS 15n
282 Displays \fBdc\fR debugging information.
286 .ne 2
288 \fB\fB; :\fR\fR
290 .RS 15n
291 Used by  \fBbc\fR(1) for array operations.
296 The results of division are forced to be a scale of 20.
298 .ne 2
300 \fB\fB+ \(mi / * % ^\fR\fR
302 .RS 18n
303 The top two values on the stack are added (\fB+\fR), subtracted (\fB\(mi\fR),
304 multiplied (\fB*\fR), divided (\fB/\fR), remaindered (\fB%\fR), or
305 exponentiated (\fB^\fR). The two entries are popped off the stack. The result
306 is pushed on the stack in their place. Any fractional part of an exponent is
307 ignored.
309 Ensures that the scale set prior to division is the scale of the result.
312 .SH EXAMPLES
314 \fBExample 1 \fRPrinting the first ten values of n!
317 This example prints the first ten values of n!:
320 .in +2
322 [la1+dsa*pla10>y]sy
323 0sa1
326 .in -2
329 .SH SEE ALSO
332 \fBbc\fR(1), \fBattributes\fR(5)
333 .SH DIAGNOSTICS
335 .ne 2
337 \fB\fIx\fR \fBis unimplemented\fR\fR
339 .RS 29n
340 \fIx\fR is an octal number.
344 .ne 2
346 \fB\fBout of space\fR\fR
348 .RS 29n
349 The free list is exhausted (too many digits).
353 .ne 2
355 \fB\fBout of stack space\fR\fR
357 .RS 29n
358 Too many pushes onto the stack (stack overflow).
362 .ne 2
364 \fB\fBempty stack\fR\fR
366 .RS 29n
367 Too many pops from the stack (stack underflow).
371 .ne 2
373 \fB\fBnesting depth\fR\fR
375 .RS 29n
376 Too many levels of nested execution.
380 .ne 2
382 \fB\fBdivide by 0\fR\fR
384 .RS 29n
385 Division by zero.
389 .ne 2
391 \fB\fBsqrt of neg number\fR\fR
393 .RS 29n
394 Square root of a negative number is not defined (no imaginary numbers).
398 .ne 2
400 \fB\fBexp not an integer\fR\fR
402 .RS 29n
403 \fBdc\fR only processes integer exponentiation.
407 .ne 2
409 \fB\fBexp too big\fR\fR
411 .RS 29n
412 The largest exponent allowed is 999.
416 .ne 2
418 \fB\fBinput base is too large\fR\fR
420 .RS 29n
421 The input base x: 2<= x <= 16.
425 .ne 2
427 \fB\fBinput base is too small\fR\fR
429 .RS 29n
430 The input base x: 2<= x <= 16.
434 .ne 2
436 \fB\fBoutput base is too large\fR\fR
438 .RS 29n
439 The output base must be no larger than  \fBBC_BASE_MAX\fR.
443 .ne 2
445 \fB\fBinvalid scale factor\fR\fR
447 .RS 29n
448 Scale factor cannot be less than 1.
452 .ne 2
454 \fB\fBscale factor is too large\fR\fR
456 .RS 29n
457 A scale factor cannot be larger than  \fBBC_SCALE_MAX\fR.
461 .ne 2
463 \fB\fBsymbol table overflow\fR\fR
465 .RS 29n
466 Too many variables have been specified.
470 .ne 2
472 \fB\fBinvalid index\fR\fR
474 .RS 29n
475 Index cannot be less than 1.
479 .ne 2
481 \fB\fBindex is too large\fR\fR
483 .RS 29n
484 An index cannot be larger than  \fBBC_DIM_MAX\fR.