1*61961Sbostic.\" Copyright (c) 1990, 1993 2*61961Sbostic.\" The Regents of the University of California. All rights reserved. 319399Smckusick.\" 448238Sbostic.\" %sccs.include.proprietary.roff% 543681Scael.\" 6*61961Sbostic.\" @(#)dc.1 8.1 (Berkeley) 06/06/93 748238Sbostic.\" 843681Scael.Dd 943681Scael.Dt DC 1 1043681Scael.Os ATT 7th 1143681Scael.Sh NAME 1250817Scael.Nm \&dc 1343681Scael.Nd desk calculator 1443681Scael.Sh SYNOPSIS 1550817Scael.Nm \&dc 1643681Scael.Op file 1743681Scael.Sh DESCRIPTION 1850817Scael.Nm \&Dc 1919399Smckusickis an arbitrary precision arithmetic package. 2019399SmckusickOrdinarily it operates on decimal integers, 2119399Smckusickbut one may specify an input base, output base, 2219399Smckusickand a number of fractional digits to be maintained. 2319399SmckusickThe overall structure of 2450817Scael.Nm \&dc 2519399Smckusickis 2619399Smckusicka stacking (reverse Polish) calculator. 2719399SmckusickIf an argument is given, 2819399Smckusickinput is taken from that file until its end, 2919399Smckusickthen from the standard input. 3019399SmckusickThe following constructions are recognized: 3150817Scael.Bl -tag -width flag 3250817Scael.It Va number 3319399SmckusickThe value of the number is pushed on the stack. 3419399SmckusickA number is an unbroken string of the digits 0-9. 3519399SmckusickIt may be preceded by an underscore _ to input a 3619399Smckusicknegative number. 3719399SmckusickNumbers may contain decimal points. 3850817Scael.It Cm "\&+ \&\- \&/ \&* \&% \&^" 3919399SmckusickThe 4019399Smckusicktop two values on the stack are added 4119399Smckusick(+), 4219399Smckusicksubtracted 4319399Smckusick(\-), 4419399Smckusickmultiplied (*), 4519399Smckusickdivided (/), 4619399Smckusickremaindered (%), 4719399Smckusickor exponentiated (^). 4819399SmckusickThe two entries are popped off the stack; 4919399Smckusickthe result is pushed on the stack in their place. 5019399SmckusickAny fractional part of an exponent is ignored. 5150817Scael.It Ic s Ns Ar x 5219399SmckusickThe 5319399Smckusicktop of the stack is popped and stored into 5419399Smckusicka register named 5543681Scael.Ar x , 5619399Smckusickwhere 5743681Scael.Ar x 5819399Smckusickmay be any character. 5919399SmckusickIf 6019399Smckusickthe 6143681Scael.Ar s 6219399Smckusickis capitalized, 6343681Scael.Ar x 6419399Smckusickis treated as a stack and the value is pushed on it. 6550817Scael.It Ic l Ns Ar x 6619399SmckusickThe 6719399Smckusickvalue in register 6843681Scael.Ar x 6919399Smckusickis pushed on the stack. 7019399SmckusickThe register 7143681Scael.Ar x 7219399Smckusickis not altered. 7319399SmckusickAll registers start with zero value. 7419399SmckusickIf the 7543681Scael.Ar l 7619399Smckusickis capitalized, 7719399Smckusickregister 7843681Scael.Ar x 7919399Smckusickis treated as a stack and its top value is popped onto the main stack. 8050817Scael.It Ic d 8119399SmckusickThe 8219399Smckusicktop value on the stack is duplicated. 8350817Scael.It Ic p 8419399SmckusickThe top value on the stack is printed. 8519399SmckusickThe top value remains unchanged. 8643681Scael.Ar P 8719399Smckusickinterprets the top of the stack as an ascii string, 8819399Smckusickremoves it, and prints it. 8950817Scael.It Ic f 9019399SmckusickAll values on the stack and in registers are printed. 9150817Scael.It Ic q 9219399Smckusickexits the program. 9319399SmckusickIf executing a string, the recursion level is 9419399Smckusickpopped by two. 9519399SmckusickIf 9643681Scael.Ar q 9719399Smckusickis capitalized, 9819399Smckusickthe top value on the stack is popped and the string execution level is popped 9919399Smckusickby that value. 10050817Scael.It Ic x 10119399Smckusicktreats the top element of the stack as a character string 10250817Scaeland executes it as a string of 10350817Scael.Nm \&dc 10450817Scaelcommands. 10550817Scael.It Ic X 10619399Smckusickreplaces the number on the top of the stack with its scale factor. 10750817Scael.It Cm \&[ Ns ... Ns Cm \&] 10819399Smckusickputs the bracketed ascii string onto the top of the stack. 10950817Scael.It Xo 11050817Scael.Cm < Va x 11150817Scael.Cm > Va x 11250817Scael.Cm = Va x 11350817Scael.Xc 11419399SmckusickThe 11519399Smckusicktop two elements of the stack are popped and compared. 11619399SmckusickRegister 11743681Scael.Ar x 11819399Smckusickis executed if they obey the stated 11919399Smckusickrelation. 12050817Scael.It Ic v 12119399Smckusickreplaces the top element on the stack by its square root. 12219399SmckusickAny existing fractional part of the argument is taken 12319399Smckusickinto account, but otherwise the scale factor is ignored. 12450817Scael.It Ic \&! 12550817Scaelinterprets the rest of the line as a 12650817Scael.Ux 12750817Scaelcommand. 12850817Scael.It Ic c 12919399SmckusickAll values on the stack are popped. 13050817Scael.It Ic i 13119399SmckusickThe top value on the stack is popped and used as the 13219399Smckusicknumber radix for further input. 13343681Scael.Ic I 13419399Smckusickpushes the input base on the top of the stack. 13550817Scael.It Ic o 13619399SmckusickThe top value on the stack is popped and used as the 13719399Smckusicknumber radix for further output. 13850817Scael.It Ic O 13919399Smckusickpushes the output base on the top of the stack. 14050817Scael.It Ic k 14119399Smckusickthe top of the stack is popped, and that value is used as 14219399Smckusicka non-negative scale factor: 14319399Smckusickthe appropriate number of places 14419399Smckusickare printed on output, 14519399Smckusickand maintained during multiplication, division, and exponentiation. 14619399SmckusickThe interaction of scale factor, 14719399Smckusickinput base, and output base will be reasonable if all are changed 14819399Smckusicktogether. 14950817Scael.It Ic z 15019399SmckusickThe stack level is pushed onto the stack. 15150817Scael.It Ic Z 15219399Smckusickreplaces the number on the top of the stack with its length. 15350817Scael.It Ic \&? 15419399SmckusickA line of input is taken from the input source (usually the terminal) 15519399Smckusickand executed. 15650817Scael.It Ic \&; \&: 15743681Scaelare used by 15850817Scael.Xr \&bc 15919399Smckusickfor array operations. 16050817Scael.El 16143681Scael.Pp 16243681ScaelAn example which prints the first ten values of 16343681Scael.Ic n\&! : 16443681Scael.Pp 16550817Scael.Bd -literal -offset indent -compact 16650817Scael[la1+dsa*pla10>y]sy 16750817Scael0sa1 16850817Scaellyx 16950817Scael.Ed 17043681Scael.Sh SEE ALSO 17150817Scael.Xr \&bc 1 , 17219399Smckusickwhich is a preprocessor for 17350817Scael.Nm \&dc 17450817Scaelproviding infix notation and a C-like syntax 17519399Smckusickwhich implements functions and reasonable control 17619399Smckusickstructures for programs. 17743681Scael.Sh HISTORY 17850817ScaelThe 17950817Scael.Nm \&dc 18050817Scaelcommand appeared in 18150817Scael.At v6 . 18243681Scael.Sh DIAGNOSTICS 18350817Scael.Bl -tag -width flag 18450817Scael.It Li x is unimplemented 18543681Scaelwhere x is an octal number. 18650817Scael.It Li stack empty 18743681Scaelfor not enough elements on the stack to do what was asked. 18850817Scael.It Li Out of space 18943681Scaelwhen the free list is exhausted (too many digits). 19050817Scael.It Li Out of headers 19143681Scaelfor too many numbers being kept around. 19250817Scael.It Li Out of pushdown 19343681Scaelfor too many items on the stack. 19450817Scael.It Li Nesting Depth 19543681Scaelfor too many levels of nested execution. 19650817Scael.El 197