3 cfa37a7b 2004-04-10 devnull dc \- desk calculator
4 cfa37a7b 2004-04-10 devnull .SH SYNOPSIS
9 cfa37a7b 2004-04-10 devnull .SH DESCRIPTION
11 cfa37a7b 2004-04-10 devnull is an arbitrary precision desk calculator.
12 cfa37a7b 2004-04-10 devnull Ordinarily it operates on decimal integers,
13 cfa37a7b 2004-04-10 devnull but one may specify an input base, output base,
14 cfa37a7b 2004-04-10 devnull and a number of fractional digits to be maintained.
15 cfa37a7b 2004-04-10 devnull The overall structure of
18 cfa37a7b 2004-04-10 devnull a stacking (reverse Polish) calculator.
19 cfa37a7b 2004-04-10 devnull If an argument is given,
20 cfa37a7b 2004-04-10 devnull input is taken from that file until its end,
21 cfa37a7b 2004-04-10 devnull then from the standard input.
22 cfa37a7b 2004-04-10 devnull The following constructions are recognized:
25 cfa37a7b 2004-04-10 devnull The value of the number is pushed on the stack.
26 cfa37a7b 2004-04-10 devnull A number is an unbroken string of the digits
27 cfa37a7b 2004-04-10 devnull .B 0-9A-F
29 cfa37a7b 2004-04-10 devnull .BR 0-9a-f .
30 cfa37a7b 2004-04-10 devnull A hexadecimal number beginning with a lower case
31 cfa37a7b 2004-04-10 devnull letter must be preceded by a zero to distinguish it
32 cfa37a7b 2004-04-10 devnull from the command associated with the letter.
33 cfa37a7b 2004-04-10 devnull It may be preceded by an underscore
35 cfa37a7b 2004-04-10 devnull to input a
36 cfa37a7b 2004-04-10 devnull negative number.
37 cfa37a7b 2004-04-10 devnull Numbers may contain decimal points.
40 cfa37a7b 2004-04-10 devnull + - / * % ^
49 cfa37a7b 2004-04-10 devnull remainder
51 cfa37a7b 2004-04-10 devnull or exponentiate
53 cfa37a7b 2004-04-10 devnull the top two values on the stack.
54 cfa37a7b 2004-04-10 devnull The two entries are popped off the stack;
55 cfa37a7b 2004-04-10 devnull the result is pushed on the stack in their place.
56 cfa37a7b 2004-04-10 devnull Any fractional part of an exponent is ignored.
63 cfa37a7b 2004-04-10 devnull Pop the top of the stack and store into
64 cfa37a7b 2004-04-10 devnull a register named
68 cfa37a7b 2004-04-10 devnull may be any character.
69 cfa37a7b 2004-04-10 devnull Under operation
73 cfa37a7b 2004-04-10 devnull is treated as a stack and the value is pushed on it.
80 cfa37a7b 2004-04-10 devnull Push the value in register
82 cfa37a7b 2004-04-10 devnull onto the stack.
83 cfa37a7b 2004-04-10 devnull The register
85 cfa37a7b 2004-04-10 devnull is not altered.
86 cfa37a7b 2004-04-10 devnull All registers start with zero value.
87 cfa37a7b 2004-04-10 devnull Under operation
91 cfa37a7b 2004-04-10 devnull is treated as a stack and its top value is popped onto the main stack.
94 cfa37a7b 2004-04-10 devnull Duplicate the
95 cfa37a7b 2004-04-10 devnull top value on the stack.
98 cfa37a7b 2004-04-10 devnull Print the top value on the stack.
99 cfa37a7b 2004-04-10 devnull The top value remains unchanged.
101 cfa37a7b 2004-04-10 devnull interprets the top of the stack as an
104 cfa37a7b 2004-04-10 devnull removes it, and prints it.
107 cfa37a7b 2004-04-10 devnull Print the values on the stack.
114 cfa37a7b 2004-04-10 devnull Exit the program.
115 cfa37a7b 2004-04-10 devnull If executing a string, the recursion level is
116 cfa37a7b 2004-04-10 devnull popped by two.
117 cfa37a7b 2004-04-10 devnull Under operation
119 cfa37a7b 2004-04-10 devnull the top value on the stack is popped and the string execution level is popped
120 cfa37a7b 2004-04-10 devnull by that value.
123 cfa37a7b 2004-04-10 devnull Treat the top element of the stack as a character string
124 cfa37a7b 2004-04-10 devnull and execute it as a string of
126 cfa37a7b 2004-04-10 devnull commands.
129 cfa37a7b 2004-04-10 devnull Replace the number on the top of the stack with its scale factor.
131 cfa37a7b 2004-04-10 devnull .B "[ ... ]"
132 cfa37a7b 2004-04-10 devnull Put the bracketed
134 cfa37a7b 2004-04-10 devnull string on the top of the stack.
143 cfa37a7b 2004-04-10 devnull Pop and compare the
144 cfa37a7b 2004-04-10 devnull top two elements of the stack.
145 cfa37a7b 2004-04-10 devnull Register
147 cfa37a7b 2004-04-10 devnull is executed if they obey the stated
148 cfa37a7b 2004-04-10 devnull relation.
151 cfa37a7b 2004-04-10 devnull Replace the top element on the stack by its square root.
152 cfa37a7b 2004-04-10 devnull Any existing fractional part of the argument is taken
153 cfa37a7b 2004-04-10 devnull into account, but otherwise the scale factor is ignored.
156 cfa37a7b 2004-04-10 devnull Interpret the rest of the line as a shell command.
159 cfa37a7b 2004-04-10 devnull Clear the stack.
162 cfa37a7b 2004-04-10 devnull The top value on the stack is popped and used as the
163 cfa37a7b 2004-04-10 devnull number base for further input.
166 cfa37a7b 2004-04-10 devnull Push the input base on the top of the stack.
169 cfa37a7b 2004-04-10 devnull The top value on the stack is popped and used as the
170 cfa37a7b 2004-04-10 devnull number base for further output.
171 cfa37a7b 2004-04-10 devnull In bases larger than 10, each `digit' prints as a group of decimal digits.
174 cfa37a7b 2004-04-10 devnull Push the output base on the top of the stack.
177 cfa37a7b 2004-04-10 devnull Pop the top of the stack, and use that value as
178 cfa37a7b 2004-04-10 devnull a non-negative scale factor:
179 cfa37a7b 2004-04-10 devnull the appropriate number of places
180 cfa37a7b 2004-04-10 devnull are printed on output,
181 cfa37a7b 2004-04-10 devnull and maintained during multiplication, division, and exponentiation.
182 cfa37a7b 2004-04-10 devnull The interaction of scale factor,
183 cfa37a7b 2004-04-10 devnull input base, and output base will be reasonable if all are changed
184 cfa37a7b 2004-04-10 devnull together.
187 cfa37a7b 2004-04-10 devnull Push the stack level onto the stack.
190 cfa37a7b 2004-04-10 devnull Replace the number on the top of the stack with its length.
193 cfa37a7b 2004-04-10 devnull A line of input is taken from the input source (usually the terminal)
194 cfa37a7b 2004-04-10 devnull and executed.
196 cfa37a7b 2004-04-10 devnull .B "; :"
199 cfa37a7b 2004-04-10 devnull for array operations.
201 cfa37a7b 2004-04-10 devnull The scale factor set by
203 cfa37a7b 2004-04-10 devnull determines how many digits are kept to the right of
204 cfa37a7b 2004-04-10 devnull the decimal point.
207 cfa37a7b 2004-04-10 devnull is the current scale factor,
209 cfa37a7b 2004-04-10 devnull is the scale of the first operand,
211 cfa37a7b 2004-04-10 devnull is the scale of the second,
214 cfa37a7b 2004-04-10 devnull is the (integer) second operand,
215 cfa37a7b 2004-04-10 devnull results are truncated to the following scales.
218 cfa37a7b 2004-04-10 devnull \fL+\fR,\fL-\fR max(\fIsa,sb\fR)
219 cfa37a7b 2004-04-10 devnull \fL*\fR min(\fIsa\fR+\fIsb \fR, max\fR(\fIs,sa,sb\fR))
220 cfa37a7b 2004-04-10 devnull \fL/\fI s
221 cfa37a7b 2004-04-10 devnull \fL%\fR so that dividend = divisor*quotient + remainder; remainder has sign of dividend
222 cfa37a7b 2004-04-10 devnull \fL^\fR min(\fIsa\fR\(mu|\fIb\fR|, max(\fIs,sa\fR))
223 cfa37a7b 2004-04-10 devnull \fLv\fR max(\fIs,sa\fR)
225 cfa37a7b 2004-04-10 devnull .SH EXAMPLES
227 c8b6342d 2005-01-13 devnull Print the first ten values of
231 cfa37a7b 2004-04-10 devnull [la1+dsa*pla10>y]sy
235 cfa37a7b 2004-04-10 devnull .SH SOURCE
236 c3674de4 2005-01-11 devnull .B \*9/src/cmd/dc.c
237 cfa37a7b 2004-04-10 devnull .SH "SEE ALSO"
238 cfa37a7b 2004-04-10 devnull .IR bc (1),
239 cfa37a7b 2004-04-10 devnull .IR hoc (1)
240 cfa37a7b 2004-04-10 devnull .SH DIAGNOSTICS
242 cfa37a7b 2004-04-10 devnull .LR "is unimplemented" ,
245 cfa37a7b 2004-04-10 devnull is an octal number: an internal error.
247 cfa37a7b 2004-04-10 devnull `Out of headers'
248 cfa37a7b 2004-04-10 devnull for too many numbers being kept around.
250 cfa37a7b 2004-04-10 devnull `Nesting depth'
251 cfa37a7b 2004-04-10 devnull for too many levels of nested execution.
252 cfa37a7b 2004-04-10 devnull .SH BUGS
253 cfa37a7b 2004-04-10 devnull When the input base exceeds 16,
254 cfa37a7b 2004-04-10 devnull there is no notation for digits greater than
257 cfa37a7b 2004-04-10 devnull Past its time.