.\" .\" dc.1 - the *roff document processor source for the dc manual .\" .\" This file is part of GNU dc. .\" Copyright (C) 1994, 1997, 1998, 2000 Free Software Foundation, Inc. .\" .\" This program is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by .\" the Free Software Foundation; either version 2 of the License , or .\" (at your option) any later version. .\" .\" This program is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License .\" along with this program; see the file COPYING. If not, write to: .\" The Free Software Foundation, Inc. .\" 59 Temple Place, Suite 330 .\" Boston, MA 02111 USA .\" .\" $FreeBSD: src/contrib/bc/doc/dc.1,v 1.3.2.1 2001/03/04 09:34:56 kris Exp $ .\" $DragonFly: src/contrib/bc/doc/Attic/dc.1,v 1.2 2003/06/17 04:23:58 dillon Exp $ .\" .TH DC 1 "1997-03-25" "GNU Project" .ds dc \fIdc\fP .ds Dc \fIDc\fP .SH NAME dc \- an arbitrary precision calculator .SH SYNOPSIS dc [-V] [--version] [-h] [--help] [-e scriptexpression] [--expression=scriptexpression] [-f scriptfile] [--file=scriptfile] [file ...] .SH DESCRIPTION .PP \*(Dc is a reverse-polish desk calculator which supports unlimited precision arithmetic. It also allows you to define and call macros. Normally \*(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. .PP A reverse-polish calculator stores numbers on a stack. Entering a number pushes it on the stack. Arithmetic operations pop arguments off the stack and push the results. .PP To enter a number in .IR 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. .SH OPTIONS \*(Dc may be invoked with the following command-line options: .TP .B -V .TP .B --version Print out the version of \*(dc that is being run and a copyright notice, then exit. .TP .B -h .TP .B --help Print a usage message briefly summarizing these command-line options and the bug-reporting address, then exit. .TP .B -e \fIscript\fP .TP .BI --expression= script Add the commands in .I script to the set of commands to be run while processing the input. .TP .B -f \fIscript-file\fP .TP .BI --file= script-file Add the commands contained in the file .I script-file to the set of commands to be run while processing the input. .PP 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 .B - refers to the standard input stream. The standard input will processed if no file names are specified. .PD .SH Printing Commands .TP .B p Prints the value on the top of the stack, without altering the stack. A newline is printed after the value. .TP .B n Prints the value on the top of the stack, popping it off, and does not print a newline after. .TP .B 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 \fBKSK 0k1/ [_1*]sx d0>x [256~aPd0 r Pops two values off the stack and compares them assuming they are numbers, executing the contents of register .I r as a macro if the original top-of-stack is greater. Thus, .B 1 2>a will invoke register .BR a 's contents and .B 2 1>a will not. .TP .BI !> 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. .TP .BI < r Similar but invokes the macro if the original top-of-stack is less. .TP .BI !< r Similar but invokes the macro if the original top-of-stack is not less than (greater than or equal to) what was the second-to-top. .TP .BI = r Similar but invokes the macro if the two numbers popped are equal. .TP .BI != r Similar but invokes the macro if the two numbers popped are not equal. .ig This can also be validly used to compare two strings for equality. .. .TP .B ? Reads a line from the terminal and executes it. This command allows a macro to request input from the user. .TP .B q exits from a macro and also from the macro which invoked it. If called from the top level, or from a macro which was called directly from the top level, the .B q command will cause \*(dc to exit. .TP .B Q Pops a value off the stack and uses it as a count of levels of macro execution to be exited. Thus, .B 3Q exits three levels. The .B Q command will never cause \*(dc to exit. .SH Status Inquiry .TP .B Z Pops a value off the stack, calculates the number of digits it has (or number of characters, if it is a string) and pushes that number. .TP .B X Pops a value off the stack, calculates the number of fraction digits it has, and pushes that number. For a string, the value pushed is .\" -1. 0. .TP .B z Pushes the current stack depth: the number of objects on the stack before the execution of the .B z command. .SH Miscellaneous .TP .B ! Will run the rest of the line as a system command. Note that parsing of the !<, !=, and !> commands take precedence, so if you want to run a command starting with <, =, or > you will need to add a space after the !. .TP .B # Will interpret the rest of the line as a comment. .TP .BI : r Will pop the top two values off of the stack. The old second-to-top value will be stored in the array .IR r , indexed by the old top-of-stack value. .TP .BI ; r Pops the top-of-stack and uses it as an index into the array .IR r . The selected value is then pushed onto the stack. .P Note that each stacked instance of a register has its own array associated with it. Thus \fB1 0:a 0Sa 2 0:a La 0;ap\fP will print 1, because the 2 was stored in an instance of 0:a that was later popped. .SH BUGS .PP Email bug reports to .BR bug-dc@gnu.org .