|
|
1.1 root 1: .\" @(#)dc.1 6.1 (Berkeley) 4/29/85
2: .\"
3: .TH DC 1 "April 29, 1985"
4: .AT 3
5: .SH NAME
6: dc \- desk calculator
7: .SH SYNOPSIS
8: .B dc
9: [ file ]
10: .SH DESCRIPTION
11: .I Dc
12: is an arbitrary precision arithmetic package.
13: Ordinarily it operates on decimal integers,
14: but one may specify an input base, output base,
15: and a number of fractional digits to be maintained.
16: The overall structure of
17: .I dc
18: is
19: a stacking (reverse Polish) calculator.
20: If an argument is given,
21: input is taken from that file until its end,
22: then from the standard input.
23: The following constructions are recognized:
24: .HP 6
25: number
26: .br
27: The value of the number is pushed on the stack.
28: A number is an unbroken string of the digits 0-9.
29: It may be preceded by an underscore _ to input a
30: negative number.
31: Numbers may contain decimal points.
32: .HP 6
33: + \- / * % ^
34: .br
35: The
36: top two values on the stack are added
37: (+),
38: subtracted
39: (\-),
40: multiplied (*),
41: divided (/),
42: remaindered (%),
43: or exponentiated (^).
44: The two entries are popped off the stack;
45: the result is pushed on the stack in their place.
46: Any fractional part of an exponent is ignored.
47: .TP
48: .BI s x
49: The
50: top of the stack is popped and stored into
51: a register named
52: .I x,
53: where
54: .I x
55: may be any character.
56: If
57: the
58: .B s
59: is capitalized,
60: .I x
61: is treated as a stack and the value is pushed on it.
62: .TP
63: .BI l x
64: The
65: value in register
66: .I x
67: is pushed on the stack.
68: The register
69: .I x
70: is not altered.
71: All registers start with zero value.
72: If the
73: .B l
74: is capitalized,
75: register
76: .I x
77: is treated as a stack and its top value is popped onto the main stack.
78: .TP
79: .B d
80: The
81: top value on the stack is duplicated.
82: .TP
83: .B p
84: The top value on the stack is printed.
85: The top value remains unchanged.
86: .B P
87: interprets the top of the stack as an ascii string,
88: removes it, and prints it.
89: .TP
90: .B f
91: All values on the stack and in registers are printed.
92: .TP
93: .B q
94: exits the program.
95: If executing a string, the recursion level is
96: popped by two.
97: If
98: .B q
99: is capitalized,
100: the top value on the stack is popped and the string execution level is popped
101: by that value.
102: .TP
103: .B x
104: treats the top element of the stack as a character string
105: and executes it as a string of dc commands.
106: .TP
107: .B X
108: replaces the number on the top of the stack with its scale factor.
109: .TP
110: .B "[ ... ]"
111: puts the bracketed ascii string onto the top of the stack.
112: .HP 6
113: .I "<x >x =x"
114: .br
115: The
116: top two elements of the stack are popped and compared.
117: Register
118: .I x
119: is executed if they obey the stated
120: relation.
121: .TP
122: .B v
123: replaces the top element on the stack by its square root.
124: Any existing fractional part of the argument is taken
125: into account, but otherwise the scale factor is ignored.
126: .TP
127: .B !
128: interprets the rest of the line as a UNIX command.
129: .TP
130: .B c
131: All values on the stack are popped.
132: .TP
133: .B i
134: The top value on the stack is popped and used as the
135: number radix for further input.
136: .B I
137: pushes the input base on the top of the stack.
138: .TP
139: .B o
140: The top value on the stack is popped and used as the
141: number radix for further output.
142: .TP
143: .SM
144: .B O
145: pushes the output base on the top of the stack.
146: .TP
147: .B k
148: the top of the stack is popped, and that value is used as
149: a non-negative scale factor:
150: the appropriate number of places
151: are printed on output,
152: and maintained during multiplication, division, and exponentiation.
153: The interaction of scale factor,
154: input base, and output base will be reasonable if all are changed
155: together.
156: .TP
157: .B z
158: The stack level is pushed onto the stack.
159: .TP
160: .SM
161: .B Z
162: replaces the number on the top of the stack with its length.
163: .TP
164: .B ?
165: A line of input is taken from the input source (usually the terminal)
166: and executed.
167: .TP
168: .B "; :"
169: are used by
170: .I bc
171: for array operations.
172: .PP
173: An example which prints the first ten values of n! is
174: .nf
175: .PP
176: .in +3
177: [la1+dsa*pla10>y]sy
178: .br
179: 0sa1
180: .br
181: lyx
182: .fi
183: .SH "SEE ALSO"
184: bc(1),
185: which is a preprocessor for
186: .I dc
187: providing infix notation and a C-like syntax
188: which implements functions and reasonable control
189: structures for programs.
190: .SH DIAGNOSTICS
191: `x is unimplemented' where x is an octal number.
192: .br
193: `stack empty' for not enough elements on the stack to do what was asked.
194: .br
195: `Out of space' when the free list is exhausted (too many digits).
196: .br
197: `Out of headers' for too many numbers being kept around.
198: .br
199: `Out of pushdown' for too many items on the stack.
200: .br
201: `Nesting Depth' for too many levels of nested execution.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.