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