1.\" Copyright (c) 1990 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)dc.1 6.2 (Berkeley) 06/24/90 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.Tw Fl 32.Tp 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.Tp Li \&+ \&\- \&/ \&* \&% \&^ 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.Tc Ic s 52.Ar x 53.Cx 54The 55top of the stack is popped and stored into 56a register named 57.Ar x , 58where 59.Ar x 60may be any character. 61If 62the 63.Ar s 64is capitalized, 65.Ar x 66is treated as a stack and the value is pushed on it. 67.Tc Ic l 68.Ar x 69.Cx 70The 71value in register 72.Ar x 73is pushed on the stack. 74The register 75.Ar x 76is not altered. 77All registers start with zero value. 78If the 79.Ar l 80is capitalized, 81register 82.Ar x 83is treated as a stack and its top value is popped onto the main stack. 84.Tp Ic d 85The 86top value on the stack is duplicated. 87.Tp Ic p 88The top value on the stack is printed. 89The top value remains unchanged. 90.Ar P 91interprets the top of the stack as an ascii string, 92removes it, and prints it. 93.Tp Ic f 94All values on the stack and in registers are printed. 95.Tp Ic q 96exits the program. 97If executing a string, the recursion level is 98popped by two. 99If 100.Ar q 101is capitalized, 102the top value on the stack is popped and the string execution level is popped 103by that value. 104.Tp Ic x 105treats the top element of the stack as a character string 106and executes it as a string of dc commands. 107.Tp Ic X 108replaces the number on the top of the stack with its scale factor. 109.Tp Op \&... 110puts the bracketed ascii string onto the top of the stack. 111.Tp Va \&<x \&>x \&=x 112The 113top two elements of the stack are popped and compared. 114Register 115.Ar x 116is executed if they obey the stated 117relation. 118.Tp Ic v 119replaces the top element on the stack by its square root. 120Any existing fractional part of the argument is taken 121into account, but otherwise the scale factor is ignored. 122.Tp Ic \&! 123interprets the rest of the line as a UNIX command. 124.Tp Ic c 125All values on the stack are popped. 126.Tp Ic i 127The top value on the stack is popped and used as the 128number radix for further input. 129.Ic I 130pushes the input base on the top of the stack. 131.Tp Ic o 132The top value on the stack is popped and used as the 133number radix for further output. 134.Tp Ic O 135pushes the output base on the top of the stack. 136.Tp Ic k 137the top of the stack is popped, and that value is used as 138a non-negative scale factor: 139the appropriate number of places 140are printed on output, 141and maintained during multiplication, division, and exponentiation. 142The interaction of scale factor, 143input base, and output base will be reasonable if all are changed 144together. 145.Tp Ic z 146The stack level is pushed onto the stack. 147.Tp Ic Z 148replaces the number on the top of the stack with its length. 149.Tp Ic \&? 150A line of input is taken from the input source (usually the terminal) 151and executed. 152.Tp Ic \&; \&: 153are used by 154.Ar bc 155for array operations. 156.Tp 157.Pp 158An example which prints the first ten values of 159.Ic n\&! : 160.Pp 161.Df I 162.Cx Op Li la1+dsa*pla10>y 163.Cx sy 164.Cx 165.De 166.Ds I 167.Li 0sa1 168.De 169.Ds I 170.Li lyx 171.De 172.Sh SEE ALSO 173.Xr bc 1 , 174which is a preprocessor for 175.Nm dc 176providing infix notation and a C- like syntax 177which implements functions and reasonable control 178structures for programs. 179.Sh HISTORY 180.Nm Dc 181appeared in Version 6 AT&T Unix. 182.Sh DIAGNOSTICS 183.Tp Ar 184.\" .Tw x\ is\ unimplemented 185.Tp Li x is unimplemented 186where x is an octal number. 187.Tp Li stack empty 188for not enough elements on the stack to do what was asked. 189.Tp Li Out of space 190when the free list is exhausted (too many digits). 191.Tp Li Out of headers 192for too many numbers being kept around. 193.Tp Li Out of pushdown 194for too many items on the stack. 195.Tp Li Nesting Depth 196for too many levels of nested execution. 197.Tp 198