\input texinfo @c -*-texinfo-*- @c %**start of header @setfilename dc.info @settitle dc, an arbitrary precision calculator @c %**end of header @c This file has the new style title page commands. @c Run `makeinfo' rather than `texinfo-format-buffer'. @c smallbook @c tex @c \overfullrule=0pt @c end tex @c Combine indices. @synindex cp fn @syncodeindex vr fn @syncodeindex ky fn @syncodeindex pg fn @syncodeindex tp fn @ifinfo @direntry * dc: (dc). Arbritrary precision RPN ``Desktop Calculator''. @end direntry This file documents @sc{dc}, an arbitrary precision calculator. Published by the Free Software Foundation, Inc. 59 Temple Place, Suite 330 Boston, MA 02111 USA Copyright (C) 1984, 1994, 1997, 1998, 2000 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. @ignore Permission is granted to process this file through TeX and print the results, provided the printed document carries copying permission notice identical to this one except for the removal of this paragraph (this paragraph not being relevant to the printed manual). @end ignore Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation. @end ifinfo @setchapternewpage off @titlepage @title dc, an arbitrary precision calculator @author by Ken Pizzini @author original manual by Richard Stallman @page @vskip 0pt plus 1filll Copyright @copyright{} 1994, 1997, 1998 Free Software Foundation, Inc. @sp 2 Published by the Free Software Foundation, @* 59 Temple Place, Suite 330 @* Boston, MA 02111 USA Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation. @end titlepage @page @node Top, Introduction, (dir), (dir) @menu * Introduction:: Introduction * Invocation:: Invocation * Printing Commands:: Printing Commands * Arithmetic:: Arithmetic * Stack Control:: Stack Control * Registers:: Registers * Parameters:: Parameters * Strings:: Strings * Status Inquiry:: Status Inquiry * Miscellaneous:: Other commands * Reporting bugs:: Reporting bugs @end menu @node Introduction, Invocation, Top, Top @comment node-name, next, previous, up @chapter Introduction @sc{dc} is a reverse-polish desk calculator which supports unlimited precision arithmetic. It also allows you to define and call macros. Normally @sc{dc} reads from the standard input; if any command arguments are given to it, they are filenames, and @sc{dc} reads and executes the contents of the files instead of reading from standard input. All normal output is to standard output; all error messages are written to standard error. To exit, use @samp{q}. @kbd{C-c} does not exit; it is used to abort macros that are looping, etc. (Currently this is not true; @kbd{C-c} does exit.) 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. To enter a number in @sc{dc}, type the digits, with an optional decimal point. Exponential notation is not supported. To enter a negative number, begin the number with @samp{_}. @samp{-} 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. @node Invocation, Printing Commands, Introduction, Top @chapter Invocation @sc{dc} may be invoked with the following command-line options: @table @samp @item -e @var{expr} @item --expression=@var{expr} Evaluate @var{expr} as @sc{dc} commands. @item -f @var{file} @item --file=@var{file} Read and evaluate @sc{dc} commands from @var{file}. @item -h @item --help Print a usage message summarizing the command-line options, then exit. @item -V @item --version Print the version information for this program, then exit. @end table If any command-line parameters remain after processing the options, these parameters are interpreted as additional @var{file}s whose contents are read and evaluated. A file name of @code{-} refers to the standard input stream. If no @code{-e} option was specified, and no files were specified, then the standard input will be read for commands to evaluate. @node Printing Commands, Arithmetic, Invocation, Top @chapter Printing Commands @table @samp @item p Prints the value on the top of the stack, without altering the stack. A newline is printed after the value. @item n Prints the value on the top of the stack, popping it off, and does not print a newline after. (This command is a GNU extension.) @item 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 @code{KSK 0k1/ [_1*]sx d0>x [256~aPd0@var{r} Pops two values off the stack and compares them assuming they are numbers, executing the contents of register @var{r} as a macro if the original top-of-stack is greater. Thus, @samp{1 2>a} will invoke register @samp{a}'s contents and @samp{2 1>a} will not. @item !>@var{r} Similar but invokes the macro if the original top-of-stack is not greater (is less than or equal to) what was the second-to-top. @item <@var{r} Similar but invokes the macro if the original top-of-stack is less. @item !<@var{r} Similar but invokes the macro if the original top-of-stack is not less (is greater than or equal to) what was the second-to-top. @item =@var{r} Similar but invokes the macro if the two numbers popped are equal. @c This can also be validly used to compare two strings for equality. @item !=@var{r} Similar but invokes the macro if the two numbers popped are not equal. @c This can also be validly used to compare two strings for equality. @item ? Reads a line from the terminal and executes it. This command allows a macro to request input from the user. @item q During the execution of a macro, this command exits from the 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 @samp{q} command will cause @sc{dc} to exit. @item Q Pops a value off the stack and uses it as a count of levels of macro execution to be exited. Thus, @samp{3Q} exits three levels. @end table @node Status Inquiry, Miscellaneous, Strings, Top @chapter Status Inquiry @table @samp @item 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. @item 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 @c -1. 0. @item z Pushes the current stack depth: the number of objects on the stack before the execution of the @samp{z} command. @end table @node Miscellaneous, Reporting bugs, Status Inquiry, Top @chapter Miscellaneous @table @samp @item ! Will run the rest of the line as a system command. Note that parsing of the !<, !=, and !> commands take precidence, so if you want to run a command starting with <, =, or > you will need to add a space after the !. @item # Will interpret the rest of the line as a comment. (This command is a GNU extension.) @item :@var{r} Will pop the top two values off of the stack. The old second-to-top value will be stored in the array @var{r}, indexed by the old top-of-stack value. @item ;@var{r} Pops the top-of-stack and uses it as an index into the array @var{r}. The selected value is then pushed onto the stack. @end table Note that each stacked instance of a register has its own array associated with it. Thus @samp{1 @var{0:a} 0S@var{a} 2 @var{0:a} L@var{a} @var{0;a}p} will print 1, because the 2 was stored in an instance of @var{0:a} that was later popped. @node Reporting bugs, , Miscellaneous, Top @chapter Reporting bugs Email bug reports to @email{bug-dc@@gnu.org}. @contents @bye