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"
12 \fB/usr/bin/dc\fR [\fIfilename\fR]
17 \fB/usr/xpg6/bin/dc\fR [\fIfilename\fR]
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.
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).
34 .SS "/usr/bin/dc, /usr/xpg6/bin/dc"
37 The following constructions are recognized under both \fB/usr/bin/dc\fR and
38 \fB/usr/xpg6/bin/dc\fR:
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.
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.
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
79 The top value on the stack is duplicated.
88 The top value on the stack is printed. The top value remains unchanged.
97 Interprets the top of the stack as an ASCII string, removes it, and prints it.
106 All values on the stack are printed.
115 Exits the program. If executing a string, the recursion level is popped by two.
124 Exits the program. The top value on the stack is popped and the string
125 execution level is popped by that value.
134 Treats the top element of the stack as a character string and executes it as a
135 string of \fBdc\fR commands.
144 Replaces the number on the top of the stack with its scale factor.
153 Puts the bracketed ASCII string onto the top of the stack.
159 \fB\fB<\fR\fIx \fR \fB>\fR\fIx \fR \fB=\fR\fIx \fR\fR
162 The top two elements of the stack are popped and compared. Register \fIx\fR is
163 evaluated if they obey the stated relation.
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
183 Interprets the rest of the line as a shell command.
192 All values on the stack are popped.
201 The top value on the stack is popped and used as the number radix for further
211 Pushes the input base on the top of the stack.
220 The top value on the stack is popped and used as the number radix for further
230 Pushes the output base on the top of the stack.
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
252 Pushes the current scale factor on the top of the stack.
261 The stack level is pushed onto the stack.
270 Replaces the number on the top of the stack with its length.
279 A line of input is taken from the input source (usually the terminal) and
289 Displays \fBdc\fR debugging information.
298 Used by \fBbc\fR(1) for array operations.
304 The following construction is recognized under \fB/usr/bin/dc\fR, using the
305 scale of whatever the result is.
309 \fB\fB+ \(mi / * % ^\fR\fR
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
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.
327 \fB\fB+ \(mi / * % ^\fR\fR
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
336 Ensures that the scale set prior to division is the scale of the result.
341 \fBExample 1 \fRPrinting the first ten values of n!
344 This example prints the first ten values of n!:
359 \fBbc\fR(1), \fBattributes\fR(5)
364 \fB\fIx\fR \fBis unimplemented\fR\fR
367 \fIx\fR is an octal number.
373 \fB\fBout of space\fR\fR
376 The free list is exhausted (too many digits).
382 \fB\fBout of stack space\fR\fR
385 Too many pushes onto the stack (stack overflow).
391 \fB\fBempty stack\fR\fR
394 Too many pops from the stack (stack underflow).
400 \fB\fBnesting depth\fR\fR
403 Too many levels of nested execution.
409 \fB\fBdivide by 0\fR\fR
418 \fB\fBsqrt of neg number\fR\fR
421 Square root of a negative number is not defined (no imaginary numbers).
427 \fB\fBexp not an integer\fR\fR
430 \fBdc\fR only processes integer exponentiation.
436 \fB\fBexp too big\fR\fR
439 The largest exponent allowed is 999.
445 \fB\fBinput base is too large\fR\fR
448 The input base x: 2<= x <= 16.
454 \fB\fBinput base is too small\fR\fR
457 The input base x: 2<= x <= 16.
463 \fB\fBoutput base is too large\fR\fR
466 The output base must be no larger than \fBBC_BASE_MAX\fR.
472 \fB\fBinvalid scale factor\fR\fR
475 Scale factor cannot be less than 1.
481 \fB\fBscale factor is too large\fR\fR
484 A scale factor cannot be larger than \fBBC_SCALE_MAX\fR.
490 \fB\fBsymbol table overflow\fR\fR
493 Too many variables have been specified.
499 \fB\fBinvalid index\fR\fR
502 Index cannot be less than 1.
508 \fB\fBindex is too large\fR\fR
511 An index cannot be larger than \fBBC_DIM_MAX\fR.