DC(1) DC(1) NAME dc - an arbitrary precision calculator SYNOPSIS dc [-V] [--version] [-h] [--help] [-e scriptexpression] [--expression=scriptexpression] [-f scriptfile] [--file=scriptfile] [file ...] DESCRIPTION Dc is a reverse-polish desk calculator which supports unlimited preci- sion arithmetic. It also allows you to define and call macros. Nor- mally dc reads from the standard input; if any command arguments are given to it, they are filenames, and dc reads and executes the contents of the files before reading from standard input. All normal output is to standard output; all error output is to standard error. A reverse-polish calculator stores numbers on a stack. Entering a num- ber pushes it on the stack. Arithmetic operations pop arguments off the stack and push the results. To enter a number in dc, type the digits with an optional decimal point. Exponential notation is not supported. To enter a negative number, begin the number with ``_''. ``-'' cannot be used for this, as it is a binary operator for subtraction instead. To enter two numbers in succession, separate them with spaces or newlines. These have no meaning as commands. OPTIONS Dc may be invoked with the following command-line options: -V --version Print out the version of dc that is being run and a copyright notice, then exit. -h --help Print a usage message briefly summarizing these command-line options and the bug-reporting address, then exit. -e script --expression=script Add the commands in script to the set of commands to be run while processing the input. -f script-file --file=script-file Add the commands contained in the file script-file to the set of commands to be run while processing the input. If any command-line parameters remain after processing the above, these parameters are interpreted as the names of input files to be processed. A file name of - refers to the standard input stream. The standard input will processed if no file names are specified. Printing Commands p Prints the value on the top of the stack, without altering the stack. A newline is printed after the value. n Prints the value on the top of the stack, popping it off, and does not print a newline after. P Pops off the value on top of the stack. If it it a string, it is simply printed without a trailing newline. Otherwise it is a number, and the integer portion of its absolute value is printed out as a "base (UCHAR_MAX+1)" byte stream. Assuming that (UCHAR_MAX+1) is 256 (as it is on most machines with 8-bit bytes), the sequence KSK 0k1/ [_1*]sx d0>x [256~aPd0r Pops two values off the stack and compares them assuming they are numbers, executing the contents of register r as a macro if the original top-of-stack is greater. Thus, 1 2>a will invoke register a's contents and 2 1>a will not. !>r Similar but invokes the macro if the original top-of-stack is not greater than (less than or equal to) what was the second-to- top. commands take precedence, so if you want to run a command starting with <, =, or > you will need to add a space after the !. # Will interpret the rest of the line as a comment. :r Will pop the top two values off of the stack. The old second- to-top value will be stored in the array r, indexed by the old top-of-stack value. ;r Pops the top-of-stack and uses it as an index into the array r. The selected value is then pushed onto the stack. Note that each stacked instance of a register has its own array associ- ated with it. Thus 1 0:a 0Sa 2 0:a La 0;ap will print 1, because the 2 was stored in an instance of 0:a that was later popped. BUGS Email bug reports to bug-dc@gnu.org. GNU Project 1997-03-25 DC(1)