1DC(1)                       General Commands Manual                      DC(1)
2
3
4

NAME

6       dc - desk calculator
7

SYNOPSIS

9       dc [ file ]
10

DESCRIPTION

12       Dc  is  an arbitrary precision arithmetic package.  Ordinarily it oper‐
13       ates on decimal integers, but one may specify  an  input  base,  output
14       base,  and a number of fractional digits to be maintained.  The overall
15       structure of dc is a stacking (reverse Polish) calculator.  If an argu‐
16       ment  is  given, input is taken from that file until its end, then from
17       the standard input.  The following constructions are recognized:
18
19       number
20             The value of the number is pushed on the stack.  A number  is  an
21             unbroken  string  of  the  digits  0-9.  It may be preceded by an
22             underscore _ to input a negative  number.   Numbers  may  contain
23             decimal points.
24
25       +  - /  *  %  ^
26             The  top  two  values on the stack are added (+), subtracted (-),
27             multiplied (*), divided (/), remaindered  (%),  or  exponentiated
28             (^).   The  two  entries  are popped off the stack; the result is
29             pushed on the stack in their place.  Any fractional  part  of  an
30             exponent is ignored.
31
32       sx    The  top  of the stack is popped and stored into a register named
33             x, where x may be any character.  If the s is capitalized,  x  is
34             treated as a stack and the value is pushed on it.
35
36       lx    The  value  in register x is pushed on the stack.  The register x
37             is not altered.  All registers start with zero value.  If  the  l
38             is  capitalized,  register  x  is  treated as a stack and its top
39             value is popped onto the main stack.
40
41       d     The top value on the stack is duplicated.
42
43       p     The top value on the stack is printed.   The  top  value  remains
44             unchanged.  P interprets the top of the stack as an ascii string,
45             removes it, and prints it.
46
47       f     All values on the stack and in registers are printed.
48
49       q     exits the program.  If executing a string, the recursion level is
50             popped  by  two.  If q is capitalized, the top value on the stack
51             is popped and the string execution level is popped by that value.
52
53       x     treats the top element of the stack as  a  character  string  and
54             executes it as a string of dc commands.
55
56       X     replaces  the  number on the top of the stack with its scale fac‐
57             tor.
58
59       [ ... ]
60             puts the bracketed ascii string onto the top of the stack.
61
62       <x  >x  =x
63             The top two elements of the stack are popped and compared.   Reg‐
64             ister x is executed if they obey the stated relation.
65
66       v     replaces  the  top  element on the stack by its square root.  Any
67             existing fractional part of the argument is taken  into  account,
68             but otherwise the scale factor is ignored.
69
70       !     interprets the rest of the line as a UNIX command.
71
72       c     All values on the stack are popped.
73
74       i     The top value on the stack is popped and used as the number radix
75             for further input.  I pushes the input base on  the  top  of  the
76             stack.
77
78       o     The top value on the stack is popped and used as the number radix
79             for further output.
80
81       O     pushes the output base on the top of the stack.
82
83       k     the top of the stack is popped, and that value is used as a  non-
84             negative  scale  factor:  the  appropriate  number  of places are
85             printed on output, and maintained  during  multiplication,  divi‐
86             sion, and exponentiation.  The interaction of scale factor, input
87             base, and output base will  be  reasonable  if  all  are  changed
88             together.
89
90       z     The stack level is pushed onto the stack.
91
92       Z     replaces the number on the top of the stack with its length.
93
94       ?     A  line of input is taken from the input source (usually the ter‐
95             minal) and executed.
96
97       ; :   are used by bc for array operations.
98
99       An example which prints the first ten values of n! is
100
101          [la1+dsa*pla10>y]sy
102          0sa1
103          lyx
104

SEE ALSO

106       bc(1), which is a preprocessor for dc providing infix notation and a C-
107       like  syntax  which  implements functions and reasonable control struc‐
108       tures for programs.
109

DIAGNOSTICS

111       `x is unimplemented' where x is an octal number.
112       `stack empty' for not enough elements on  the  stack  to  do  what  was
113       asked.
114       `Out of space' when the free list is exhausted (too many digits).
115       `Out of headers' for too many numbers being kept around.
116       `Out of pushdown' for too many items on the stack.
117       `Nesting Depth' for too many levels of nested execution.
118
119
120
1217th Edition                     April 29, 1985                           DC(1)
Impressum