dc.1 (6274B)

1 .\" 2 .\" Sccsid @(#)dc.1 1.5 (gritter) 1/11/03 3 .\" Derived from dc(1), Unix 7th edition: 4 .\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 5 .\" 6 .\" Redistribution and use in source and binary forms, with or without 7 .\" modification, are permitted provided that the following conditions 8 .\" are met: 9 .\" Redistributions of source code and documentation must retain the 10 .\" above copyright notice, this list of conditions and the following 11 .\" disclaimer. 12 .\" Redistributions in binary form must reproduce the above copyright 13 .\" notice, this list of conditions and the following disclaimer in the 14 .\" documentation and/or other materials provided with the distribution. 15 .\" All advertising materials mentioning features or use of this software 16 .\" must display the following acknowledgement: 17 .\" This product includes software developed or owned by Caldera 18 .\" International, Inc. 19 .\" Neither the name of Caldera International, Inc. nor the names of 20 .\" other contributors may be used to endorse or promote products 21 .\" derived from this software without specific prior written permission. 22 .\" 23 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 24 .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 25 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 .\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 28 .\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 31 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 34 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 .TH DC 1 "1/11/03" "Heirloom Toolchest" "User Commands" 36 .SH NAME 37 dc \- desk calculator 38 .SH SYNOPSIS 39 \fBdc\fR [\fIfile\fR] 40 .SH DESCRIPTION 41 .I Dc 42 is an arbitrary precision arithmetic package. 43 Ordinarily it operates on decimal integers, 44 but one may specify an input base, output base, 45 and a number of fractional digits to be maintained. 46 The overall structure of 47 .I dc 48 is 49 a stacking (reverse Polish) calculator. 50 If an argument is given, 51 input is taken from that file until its end, 52 then from the standard input. 53 The following constructions are recognized: 54 .HP 6 55 number 56 .br 57 The value of the number is pushed on the stack. 58 A number is an unbroken string of the digits 0-9. 59 It may be preceded by an underscore _ to input a 60 negative number. 61 Numbers may contain decimal points. 62 .HP 6 63 + \- / * % ^ 64 .br 65 The 66 top two values on the stack are added 67 (+), 68 subtracted 69 (\-), 70 multiplied (*), 71 divided (/), 72 remaindered (%), 73 or exponentiated (^). 74 The two entries are popped off the stack; 75 the result is pushed on the stack in their place. 76 Any fractional part of an exponent is ignored. 77 .TP 78 .BI s x 79 The 80 top of the stack is popped and stored into 81 a register named 82 .I x, 83 where 84 .I x 85 may be any character. 86 If 87 the 88 .B s 89 is capitalized, 90 .I x 91 is treated as a stack and the value is pushed on it. 92 .TP 93 .BI l x 94 The 95 value in register 96 .I x 97 is pushed on the stack. 98 The register 99 .I x 100 is not altered. 101 All registers start with zero value. 102 If the 103 .B l 104 is capitalized, 105 register 106 .I x 107 is treated as a stack and its top value is popped onto the main stack. 108 .TP 109 .B d 110 The 111 top value on the stack is duplicated. 112 .TP 113 .B p 114 The top value on the stack is printed. 115 The top value remains unchanged. 116 .B P 117 interprets the top of the stack as an ascii string, 118 removes it, and prints it. 119 .TP 120 .B f 121 All values on the stack and in registers are printed. 122 .TP 123 .B q 124 exits the program. 125 If executing a string, the recursion level is 126 popped by two. 127 If 128 .B q 129 is capitalized, 130 the top value on the stack is popped and the string execution level is popped 131 by that value. 132 .TP 133 .B x 134 treats the top element of the stack as a character string 135 and executes it as a string of dc commands. 136 .TP 137 .B X 138 replaces the number on the top of the stack with its scale factor. 139 .TP 140 .B "[ ... ]" 141 puts the bracketed ascii string onto the top of the stack. 142 .HP 6 143 .I "<x >x =x" 144 .br 145 The 146 top two elements of the stack are popped and compared. 147 Register 148 .I x 149 is executed if they obey the stated 150 relation. 151 .TP 152 .B v 153 replaces the top element on the stack by its square root. 154 Any existing fractional part of the argument is taken 155 into account, but otherwise the scale factor is ignored. 156 .TP 157 .B ! 158 interprets the rest of the line as a UNIX command. 159 .TP 160 .B c 161 All values on the stack are popped. 162 .TP 163 .B i 164 The top value on the stack is popped and used as the 165 number radix for further input. 166 .B I 167 pushes the input base on the top of the stack. 168 .TP 169 .B o 170 The top value on the stack is popped and used as the 171 number radix for further output. 172 .TP 173 .SM 174 .B O 175 pushes the output base on the top of the stack. 176 .TP 177 .B k 178 the top of the stack is popped, and that value is used as 179 a non-negative scale factor: 180 the appropriate number of places 181 are printed on output, 182 and maintained during multiplication, division, and exponentiation. 183 The interaction of scale factor, 184 input base, and output base will be reasonable if all are changed 185 together. 186 .TP 187 .B z 188 The stack level is pushed onto the stack. 189 .TP 190 .SM 191 .B Z 192 replaces the number on the top of the stack with its length. 193 .TP 194 .B ? 195 A line of input is taken from the input source (usually the terminal) 196 and executed. 197 .TP 198 .B "; :" 199 are used by 200 .I bc 201 for array operations. 202 .PP 203 An example which prints the first ten values of n! is 204 .nf 205 .PP 206 .in +3 207 [la1+dsa*pla10>y]sy 208 .br 209 0sa1 210 .br 211 lyx 212 .fi 213 .SH "SEE ALSO" 214 bc(1), 215 which is a preprocessor for 216 .I dc 217 providing infix notation and a C-like syntax 218 which implements functions and reasonable control 219 structures for programs. 220 .SH DIAGNOSTICS 221 `x is unimplemented' where x is an octal number. 222 .br 223 `stack empty' for not enough elements on the stack to do what was asked. 224 .br 225 `Out of space' when the free list is exhausted (too many digits). 226 .br 227 `Out of headers' for too many numbers being kept around. 228 .br 229 `Out of pushdown' for too many items on the stack. 230 .br 231 `Nesting Depth' for too many levels of nested execution.