|
Packit |
70b277 |
\input texinfo @c -*-texinfo-*-
|
|
Packit |
70b277 |
@c %**start of header
|
|
Packit |
70b277 |
@setfilename dc.info
|
|
Packit |
70b277 |
@settitle dc, an arbitrary precision calculator
|
|
Packit |
70b277 |
@c %**end of header
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@include texi-ver.incl
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@c smallbook
|
|
Packit |
70b277 |
@c tex
|
|
Packit |
70b277 |
@c \overfullrule=0pt
|
|
Packit |
70b277 |
@c end tex
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@c Combine indices.
|
|
Packit |
70b277 |
@synindex cp fn
|
|
Packit |
70b277 |
@syncodeindex vr fn
|
|
Packit |
70b277 |
@syncodeindex ky fn
|
|
Packit |
70b277 |
@syncodeindex pg fn
|
|
Packit |
70b277 |
@syncodeindex tp fn
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@direntry
|
|
Packit |
70b277 |
* dc: (dc). Arbitrary precision RPN ``Desktop Calculator''.
|
|
Packit |
70b277 |
@end direntry
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@copying
|
|
Packit |
70b277 |
This manual documents version @value{DC_VERSION} of
|
|
Packit |
70b277 |
@sc{gnu} @command{dc}, an arbitrary precision calculator.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
Copyright (C) 1984, 1994, 1997, 1998, 2000, 2005, 2006, 2008, 2013, 2016
|
|
Packit |
70b277 |
Free Software Foundation, Inc.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@quotation
|
|
Packit |
70b277 |
Permission is granted to copy, distribute and/or modify this document
|
|
Packit |
70b277 |
under the terms of the @sc{gnu} Free Documentation License,
|
|
Packit |
70b277 |
Version 1.2 or any later version published by the Free Software Foundation;
|
|
Packit |
70b277 |
with no Invariant Sections, with no Front-Cover Texts,
|
|
Packit |
70b277 |
and with no Back-Cover Texts.
|
|
Packit |
70b277 |
A copy of the license can be found at
|
|
Packit |
70b277 |
@url{http://www.gnu.org/licenses/fdl.html} .
|
|
Packit |
70b277 |
@end quotation
|
|
Packit |
70b277 |
@end copying
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@setchapternewpage off
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@titlepage
|
|
Packit |
70b277 |
@title @sc{gnu} @code{dc}
|
|
Packit |
70b277 |
@subtitle an arbitrary precision calculator
|
|
Packit |
70b277 |
@subtitle version @value{DC_VERSION}
|
|
Packit |
70b277 |
@author by Ken Pizzini
|
|
Packit |
70b277 |
@author original manual by Richard Stallman
|
|
Packit |
70b277 |
@page
|
|
Packit |
70b277 |
@vskip 0pt plus 1filll
|
|
Packit |
70b277 |
@insertcopying
|
|
Packit |
70b277 |
@end titlepage
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@ifnottex
|
|
Packit |
70b277 |
@node Top
|
|
Packit |
70b277 |
@top GNU dc
|
|
Packit |
70b277 |
@insertcopying
|
|
Packit |
70b277 |
@end ifnottex
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@menu
|
|
Packit |
70b277 |
* Introduction:: Introduction
|
|
Packit |
70b277 |
* Invocation:: Invocation
|
|
Packit |
70b277 |
* Printing Commands:: Printing Commands
|
|
Packit |
70b277 |
* Arithmetic:: Arithmetic
|
|
Packit |
70b277 |
* Stack Control:: Stack Control
|
|
Packit |
70b277 |
* Registers:: Registers
|
|
Packit |
70b277 |
* Parameters:: Parameters
|
|
Packit |
70b277 |
* Strings:: Strings
|
|
Packit |
70b277 |
* Status Inquiry:: Status Inquiry
|
|
Packit |
70b277 |
* Miscellaneous:: Other commands
|
|
Packit |
70b277 |
* Reporting bugs:: Reporting bugs
|
|
Packit |
70b277 |
@end menu
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Introduction, Invocation, Top, Top
|
|
Packit |
70b277 |
@comment node-name, next, previous, up
|
|
Packit |
70b277 |
@chapter Introduction
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@command{dc} is a reverse-polish desk calculator
|
|
Packit |
70b277 |
which supports unlimited precision arithmetic.
|
|
Packit |
70b277 |
It also allows you to define and call macros.
|
|
Packit |
70b277 |
Normally @command{dc} reads from the standard input;
|
|
Packit |
70b277 |
if any command arguments are given to it, they are filenames,
|
|
Packit |
70b277 |
and @command{dc} reads and executes the contents of the files
|
|
Packit |
70b277 |
instead of reading from standard input.
|
|
Packit |
70b277 |
All normal output is to standard output;
|
|
Packit |
70b277 |
all error messages are written to standard error.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
To exit, use @samp{q}.
|
|
Packit |
70b277 |
@kbd{C-c}
|
|
Packit |
70b277 |
(or whatever other keystroke your system uses to generate a @code{SIGINT})
|
|
Packit |
70b277 |
does not exit;
|
|
Packit |
70b277 |
it is used to abort macros that are looping, etc.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
A reverse-polish calculator stores numbers on a stack.
|
|
Packit |
70b277 |
Entering a number pushes it on the stack.
|
|
Packit |
70b277 |
Arithmetic operations pop arguments off the stack and push the results.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
To enter a number in @command{dc}, type the digits (using upper
|
|
Packit |
70b277 |
case letters @code{A} through @code{F} as "digits" when working
|
|
Packit |
70b277 |
with input bases greater than ten),
|
|
Packit |
70b277 |
with an optional decimal point.
|
|
Packit |
70b277 |
Exponential notation is not supported.
|
|
Packit |
70b277 |
To enter a negative number, begin the number with @samp{_}.
|
|
Packit |
70b277 |
@samp{-} cannot be used for this, as it is a binary operator
|
|
Packit |
70b277 |
for subtraction instead.
|
|
Packit |
70b277 |
To enter two numbers in succession,
|
|
Packit |
70b277 |
separate them with spaces or newlines;
|
|
Packit |
70b277 |
these have no meaning as commands.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Invocation, Printing Commands, Introduction, Top
|
|
Packit |
70b277 |
@chapter Invocation
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@command{dc} may be invoked with the following command-line options:
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item -e @var{expr}
|
|
Packit |
70b277 |
@item --expression=@var{expr}
|
|
Packit |
70b277 |
Evaluate @var{expr} as @command{dc} commands.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item -f @var{file}
|
|
Packit |
70b277 |
@item --file=@var{file}
|
|
Packit |
70b277 |
Read and evaluate @command{dc} commands from @var{file}.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item -h
|
|
Packit |
70b277 |
@item --help
|
|
Packit |
70b277 |
Print a usage message summarizing the command-line options, then exit.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item -V
|
|
Packit |
70b277 |
@item --version
|
|
Packit |
70b277 |
Print the version information for this program, then exit.
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
If any command-line parameters remain after processing the options,
|
|
Packit |
70b277 |
these parameters are interpreted as additional @var{file}s whose
|
|
Packit |
70b277 |
contents are read and evaluated.
|
|
Packit |
70b277 |
A file name of @code{-} refers to the standard input stream.
|
|
Packit |
70b277 |
If no @code{-e} option was specified, and no files were specified,
|
|
Packit |
70b277 |
then the standard input will be read for commands to evaluate.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Printing Commands, Arithmetic, Invocation, Top
|
|
Packit |
70b277 |
@chapter Printing Commands
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
@item p
|
|
Packit |
70b277 |
Prints the value on the top of the stack,
|
|
Packit |
70b277 |
without altering the stack.
|
|
Packit |
70b277 |
A newline is printed after the value.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item n
|
|
Packit |
70b277 |
Prints the value on the top of the stack, popping it off,
|
|
Packit |
70b277 |
and does not print a newline after.
|
|
Packit |
70b277 |
(This command is a @sc{gnu} extension.)
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item P
|
|
Packit |
70b277 |
Pops off the value on top of the stack.
|
|
Packit |
70b277 |
If it it a string, it is simply printed without a trailing newline.
|
|
Packit |
70b277 |
Otherwise it is a number, and the integer portion of its absolute
|
|
Packit |
70b277 |
value is printed out as a "base (UCHAR_MAX+1)" byte stream.
|
|
Packit |
70b277 |
Assuming that (UCHAR_MAX+1) is 256
|
|
Packit |
70b277 |
(as it is on most machines with 8-bit bytes),
|
|
Packit |
70b277 |
the sequence
|
|
Packit |
70b277 |
@code{KSK0k1/ _1Ss[ls*]Sxd0>x
|
|
Packit |
70b277 |
[256~Ssd0
|
|
Packit |
70b277 |
sx[q]Sq[Lsd0>qaPlxx]dsxx
|
|
Packit |
70b277 |
sx0sqLqsxLxLK+k}
|
|
Packit |
70b277 |
could also accomplish this function.
|
|
Packit |
70b277 |
(Much of the complexity of the above native-dc code is due
|
|
Packit |
70b277 |
to the ~ computing the characters backwards,
|
|
Packit |
70b277 |
and the desire to ensure that all registers wind up back
|
|
Packit |
70b277 |
in their original states.)
|
|
Packit |
70b277 |
(Details of the behavior with a number are a @sc{gnu} extension.
|
|
Packit |
70b277 |
Traditional @command{dc} happened to "support" similar functionality
|
|
Packit |
70b277 |
for a limited range of inputs as an accidental side-effect of its
|
|
Packit |
70b277 |
internal representation of numbers.)
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item f
|
|
Packit |
70b277 |
Prints the entire contents of the stack
|
|
Packit |
70b277 |
@c and the contents of all of the registers,
|
|
Packit |
70b277 |
without altering anything.
|
|
Packit |
70b277 |
This is a good command to use if you are lost or want
|
|
Packit |
70b277 |
to figure out what the effect of some command has been.
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
All numeric output is split to fit within 70 columns, by default.
|
|
Packit |
70b277 |
When a number is broken up in this way, the split is indicated
|
|
Packit |
70b277 |
by a "\" at the end of the to-be-continued output lines.
|
|
Packit |
70b277 |
The column width at which output is split can be overridden
|
|
Packit |
70b277 |
by setting the @var{DC_LINE_LENGTH} environment variable to
|
|
Packit |
70b277 |
the desired width.
|
|
Packit |
70b277 |
A @var{DC_LINE_LENGTH} of 0 (zero) disables the line-split
|
|
Packit |
70b277 |
feature altogether.
|
|
Packit |
70b277 |
Invalid values of @var{DC_LINE_LENGTH} are silently ignored.
|
|
Packit |
70b277 |
(The @var{DC_LINE_LENGTH} variable is a @sc{gnu} extension.)
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Arithmetic, Stack Control, Printing Commands, Top
|
|
Packit |
70b277 |
@chapter Arithmetic
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
@item +
|
|
Packit |
70b277 |
Pops two values off the stack, adds them, and pushes the result.
|
|
Packit |
70b277 |
The precision of the result is determined only
|
|
Packit |
70b277 |
by the values of the arguments, and is enough to be exact.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item -
|
|
Packit |
70b277 |
Pops two values, subtracts the first one popped
|
|
Packit |
70b277 |
from the second one popped, and pushes the result.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item *
|
|
Packit |
70b277 |
Pops two values, multiplies them, and pushes the result.
|
|
Packit |
70b277 |
The number of fraction digits in the result is the largest of
|
|
Packit |
70b277 |
the precision value,
|
|
Packit |
70b277 |
the number of fraction digits in the multiplier,
|
|
Packit |
70b277 |
or the number of fraction digits in the multiplicand;
|
|
Packit |
70b277 |
but in no event exceeding the number of digits required for
|
|
Packit |
70b277 |
an exact result.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item /
|
|
Packit |
70b277 |
Pops two values, divides the second one popped
|
|
Packit |
70b277 |
from the first one popped, and pushes the result.
|
|
Packit |
70b277 |
The number of fraction digits is specified by the precision value.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item %
|
|
Packit |
70b277 |
Pops two values,
|
|
Packit |
70b277 |
computes the remainder of the division that
|
|
Packit |
70b277 |
the @samp{/} command would do,
|
|
Packit |
70b277 |
and pushes that.
|
|
Packit |
70b277 |
The value computed is the same as that computed by
|
|
Packit |
70b277 |
the sequence @code{Sd dld/ Ld*-} .
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item ~
|
|
Packit |
70b277 |
Pops two values,
|
|
Packit |
70b277 |
divides the second one popped from the first one popped.
|
|
Packit |
70b277 |
The quotient is pushed first, and the remainder is pushed next.
|
|
Packit |
70b277 |
The number of fraction digits used in the division
|
|
Packit |
70b277 |
is specified by the precision value.
|
|
Packit |
70b277 |
(The sequence @code{SdSn lnld/ LnLd%} could also accomplish
|
|
Packit |
70b277 |
this function, with slightly different error checking.)
|
|
Packit |
70b277 |
(This command is a @sc{gnu} extension.)
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item ^
|
|
Packit |
70b277 |
Pops two values and exponentiates,
|
|
Packit |
70b277 |
using the first value popped as the exponent
|
|
Packit |
70b277 |
and the second popped as the base.
|
|
Packit |
70b277 |
The fraction part of the exponent is ignored.
|
|
Packit |
70b277 |
The precision value specifies the number of fraction
|
|
Packit |
70b277 |
digits in the result.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item |
|
|
Packit |
70b277 |
Pops three values and computes a modular exponentiation.
|
|
Packit |
70b277 |
The first value popped is used as the reduction modulus;
|
|
Packit |
70b277 |
this value must be a non-zero number,
|
|
Packit |
70b277 |
and the result may not be accurate if the modulus
|
|
Packit |
70b277 |
is not an integer.
|
|
Packit |
70b277 |
The second popped is used as the exponent;
|
|
Packit |
70b277 |
this value must be a non-negative number,
|
|
Packit |
70b277 |
and any fractional part of this exponent will be ignored.
|
|
Packit |
70b277 |
The third value popped is the base which gets exponentiated,
|
|
Packit |
70b277 |
which should be an integer.
|
|
Packit |
70b277 |
For small integers this is like the sequence @code{Sm^Lm%},
|
|
Packit |
70b277 |
but, unlike @code{^},
|
|
Packit |
70b277 |
this command will work with arbitrarily large exponents.
|
|
Packit |
70b277 |
(This command is a @sc{gnu} extension.)
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item v
|
|
Packit |
70b277 |
Pops one value, computes its square root, and pushes that.
|
|
Packit |
70b277 |
The maximum of the precision value and the precision of the argument
|
|
Packit |
70b277 |
is used to determine the number of fraction digits in the result.
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
Most arithmetic operations are affected by the @emph{precision value},
|
|
Packit |
70b277 |
which you can set with the @samp{k} command.
|
|
Packit |
70b277 |
The default precision value is zero,
|
|
Packit |
70b277 |
which means that all arithmetic except for
|
|
Packit |
70b277 |
addition and subtraction produces integer results.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Stack Control, Registers, Arithmetic, Top
|
|
Packit |
70b277 |
@chapter Stack Control
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
@item c
|
|
Packit |
70b277 |
Clears the stack, rendering it empty.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item d
|
|
Packit |
70b277 |
Duplicates the value on the top of the stack,
|
|
Packit |
70b277 |
pushing another copy of it.
|
|
Packit |
70b277 |
Thus, @samp{4d*p} computes 4 squared and prints it.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item r
|
|
Packit |
70b277 |
Reverses the order of (swaps) the top two values on the stack.
|
|
Packit |
70b277 |
(This can also be accomplished with the sequence @code{SaSbLaLb}.)
|
|
Packit |
70b277 |
(This command is a @sc{gnu} extension.)
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item R
|
|
Packit |
70b277 |
Pops the top-of-stack as an integer @var{n}.
|
|
Packit |
70b277 |
Cyclically rotates the top @var{n} items on the updated stack.
|
|
Packit |
70b277 |
If @var{n} is positive,
|
|
Packit |
70b277 |
then the rotation direction will make the topmost
|
|
Packit |
70b277 |
element the second-from top;
|
|
Packit |
70b277 |
if @var{n} is negative,
|
|
Packit |
70b277 |
then the rotation will make the topmost element the
|
|
Packit |
70b277 |
@var{n}-th element from the top.
|
|
Packit |
70b277 |
If the stack depth is less than @var{n}
|
|
Packit |
70b277 |
then the entire stack is rotated (in the appropriate direction),
|
|
Packit |
70b277 |
without any error being reported.
|
|
Packit |
70b277 |
(This command is a @sc{gnu} extension.)
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Registers, Parameters, Stack Control, Top
|
|
Packit |
70b277 |
@chapter Registers
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@command{dc} provides at least 256 memory registers@footnote{The
|
|
Packit |
70b277 |
exact number of registers provided by @command{dc} depends
|
|
Packit |
70b277 |
on the range of an @code{unsigned char} in the C compiler
|
|
Packit |
70b277 |
used to create the @command{dc} executable.},
|
|
Packit |
70b277 |
each named by a single character.
|
|
Packit |
70b277 |
You can store a number in a register and retrieve it later.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
@item s@var{r}
|
|
Packit |
70b277 |
Pop the value off the top of the stack and
|
|
Packit |
70b277 |
store it into register @var{r}.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item l@var{r}
|
|
Packit |
70b277 |
Copy the value in register @var{r},
|
|
Packit |
70b277 |
and push it onto the stack.
|
|
Packit |
70b277 |
The value @code{0} is retrieved if the
|
|
Packit |
70b277 |
register is uninitialized or its stack has become empty.
|
|
Packit |
70b277 |
This does not alter the contents of @var{r}.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
Each register also contains its own stack.
|
|
Packit |
70b277 |
The current register value is the top of the register's stack.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item S@var{r}
|
|
Packit |
70b277 |
Pop the value off the top of the (main) stack and
|
|
Packit |
70b277 |
push it onto the stack of register @var{r}.
|
|
Packit |
70b277 |
The previous value of the register becomes inaccessible.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item L@var{r}
|
|
Packit |
70b277 |
Pop the value off the top of register @var{r}'s stack
|
|
Packit |
70b277 |
and push it onto the main stack.
|
|
Packit |
70b277 |
The previous value in register @var{r}'s stack, if any,
|
|
Packit |
70b277 |
is now accessible via the @samp{l@var{r}} command.
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
@c
|
|
Packit |
70b277 |
@c The @samp{f} command prints a list of all registers that have contents
|
|
Packit |
70b277 |
@c stored in them, together with their contents.
|
|
Packit |
70b277 |
@c Only the current contents of each register (the top of its stack)
|
|
Packit |
70b277 |
@c is printed.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Parameters, Strings, Registers, Top
|
|
Packit |
70b277 |
@chapter Parameters
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@command{dc} has three parameters that control its operation:
|
|
Packit |
70b277 |
the precision, the input radix, and the output radix.
|
|
Packit |
70b277 |
The precision specifies the number of fraction digits
|
|
Packit |
70b277 |
to keep in the result of most arithmetic operations.
|
|
Packit |
70b277 |
The input radix controls the interpretation of numbers typed in;
|
|
Packit |
70b277 |
@emph{all} numbers typed in use this radix.
|
|
Packit |
70b277 |
The output radix is used for printing numbers.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
The input and output radices are separate parameters;
|
|
Packit |
70b277 |
you can make them unequal, which can be useful or confusing.
|
|
Packit |
70b277 |
The input radix must be between 2 and 16 inclusive.
|
|
Packit |
70b277 |
The output radix must be at least 2.
|
|
Packit |
70b277 |
The precision must be zero or greater.
|
|
Packit |
70b277 |
The precision is always measured in decimal digits,
|
|
Packit |
70b277 |
regardless of the current input or output radix.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
@item i
|
|
Packit |
70b277 |
Pops the value off the top of the stack
|
|
Packit |
70b277 |
and uses it to set the input radix.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item o
|
|
Packit |
70b277 |
Pops the value off the top of the stack
|
|
Packit |
70b277 |
and uses it to set the output radix.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item k
|
|
Packit |
70b277 |
Pops the value off the top of the stack
|
|
Packit |
70b277 |
and uses it to set the precision.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item I
|
|
Packit |
70b277 |
Pushes the current input radix on the stack.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item O
|
|
Packit |
70b277 |
Pushes the current output radix on the stack.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item K
|
|
Packit |
70b277 |
Pushes the current precision on the stack.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Strings, Status Inquiry, Parameters, Top
|
|
Packit |
70b277 |
@chapter Strings
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@command{dc} has a limited ability
|
|
Packit |
70b277 |
to operate on strings as well as on numbers;
|
|
Packit |
70b277 |
the only things you can do with strings are print them
|
|
Packit |
70b277 |
and execute them as macros
|
|
Packit |
70b277 |
(which means that the contents of the string are processed
|
|
Packit |
70b277 |
as @command{dc} commands).
|
|
Packit |
70b277 |
Both registers and the stack can hold strings,
|
|
Packit |
70b277 |
and @command{dc} always knows whether any given object is
|
|
Packit |
70b277 |
a string or a number.
|
|
Packit |
70b277 |
Some commands such as arithmetic operations demand numbers
|
|
Packit |
70b277 |
as arguments and print errors if given strings.
|
|
Packit |
70b277 |
Other commands can accept either a number or a string;
|
|
Packit |
70b277 |
for example, the @samp{p} command can accept either and prints the object
|
|
Packit |
70b277 |
according to its type.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
@item [@var{characters}]
|
|
Packit |
70b277 |
Makes a string containing @var{characters} and pushes it on the stack.
|
|
Packit |
70b277 |
For example, @samp{[foo]P} prints the characters @samp{foo}
|
|
Packit |
70b277 |
(with no newline).
|
|
Packit |
70b277 |
Note that all square brackets (@samp{[}s and @samp{]}s) must be balanced;
|
|
Packit |
70b277 |
there is no mechanism provided for handling unbalanced square brackets.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item a
|
|
Packit |
70b277 |
The mnemonic for this is somewhat erroneous: asciify.
|
|
Packit |
70b277 |
The top-of-stack is popped.
|
|
Packit |
70b277 |
If it was a number, then the low-order byte of this number
|
|
Packit |
70b277 |
is converted into a 1-character string
|
|
Packit |
70b277 |
and pushed onto the stack.
|
|
Packit |
70b277 |
Otherwise the top-of-stack was a string,
|
|
Packit |
70b277 |
and the first character of that string is pushed back.
|
|
Packit |
70b277 |
(This command is a @sc{gnu} extension.)
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item x
|
|
Packit |
70b277 |
Pops a value off the stack and executes it as a macro.
|
|
Packit |
70b277 |
Normally it should be a string;
|
|
Packit |
70b277 |
if it is a number, it is simply pushed back onto the stack.
|
|
Packit |
70b277 |
For example, @samp{[1p]x} executes the macro @samp{1p},
|
|
Packit |
70b277 |
which pushes 1 on the stack and prints @samp{1} on a separate line.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
Macros are most often stored in registers;
|
|
Packit |
70b277 |
@samp{[1p]sa} stores a macro to print @samp{1} into register @samp{a},
|
|
Packit |
70b277 |
and @samp{lax} invokes the macro.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item >@var{r}
|
|
Packit |
70b277 |
Pops two values off the stack and compares them
|
|
Packit |
70b277 |
assuming they are numbers,
|
|
Packit |
70b277 |
executing the contents of register @var{r} as a macro
|
|
Packit |
70b277 |
if the original top-of-stack is greater.
|
|
Packit |
70b277 |
Thus, @samp{1 2>a} will invoke register @samp{a}'s contents
|
|
Packit |
70b277 |
and @samp{2 1>a} will not.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item !>@var{r}
|
|
Packit |
70b277 |
Similar but invokes the macro if the original top-of-stack is not greater
|
|
Packit |
70b277 |
(is less than or equal to) what was the second-to-top.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item <@var{r}
|
|
Packit |
70b277 |
Similar but invokes the macro if the original top-of-stack is less.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item !<@var{r}
|
|
Packit |
70b277 |
Similar but invokes the macro if the original top-of-stack is not less
|
|
Packit |
70b277 |
(is greater than or equal to) what was the second-to-top.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item =@var{r}
|
|
Packit |
70b277 |
Similar but invokes the macro if the two numbers popped are equal.
|
|
Packit |
70b277 |
@c This can also be validly used to compare two strings for equality.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item !=@var{r}
|
|
Packit |
70b277 |
Similar but invokes the macro if the two numbers popped are not equal.
|
|
Packit |
70b277 |
@c This can also be validly used to compare two strings for equality.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item ?
|
|
Packit |
70b277 |
Reads a line from the terminal and executes it.
|
|
Packit |
70b277 |
This command allows a macro to request input from the user.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item q
|
|
Packit |
70b277 |
During the execution of a macro,
|
|
Packit |
70b277 |
this command exits from the macro and also from the macro which invoked it.
|
|
Packit |
70b277 |
If called from the top level,
|
|
Packit |
70b277 |
or from a macro which was called directly from the top level,
|
|
Packit |
70b277 |
the @samp{q} command will cause @command{dc} to exit.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item Q
|
|
Packit |
70b277 |
Pops a value off the stack and uses it as a count
|
|
Packit |
70b277 |
of levels of macro execution to be exited.
|
|
Packit |
70b277 |
Thus, @samp{3Q} exits three levels.
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Status Inquiry, Miscellaneous, Strings, Top
|
|
Packit |
70b277 |
@chapter Status Inquiry
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
@item Z
|
|
Packit |
70b277 |
Pops a value off the stack,
|
|
Packit |
70b277 |
calculates the number of decimal digits it has
|
|
Packit |
70b277 |
(or number of characters, if it is a string)
|
|
Packit |
70b277 |
and pushes that number.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
Note that the digit count for a number does
|
|
Packit |
70b277 |
@emph{not} include any leading zeros,
|
|
Packit |
70b277 |
even if those appear to the right of the radix point.
|
|
Packit |
70b277 |
This may seem a bit strange at first,
|
|
Packit |
70b277 |
but it is compatible with historical implementations of @command{dc},
|
|
Packit |
70b277 |
and can be argued to be useful for computing the magnitude of a value:
|
|
Packit |
70b277 |
@code{dSaXLaZ-} will compute the power-of-ten multiplier
|
|
Packit |
70b277 |
which would be needed to shift the decimal point
|
|
Packit |
70b277 |
to be immediately before the leftmost non-zero digit.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item X
|
|
Packit |
70b277 |
Pops a value off the stack,
|
|
Packit |
70b277 |
calculates the number of fraction digits it has,
|
|
Packit |
70b277 |
and pushes that number.
|
|
Packit |
70b277 |
For a string, the value pushed is
|
|
Packit |
70b277 |
@c -1.
|
|
Packit |
70b277 |
0.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item z
|
|
Packit |
70b277 |
Pushes the current stack depth:
|
|
Packit |
70b277 |
the number of objects on the stack
|
|
Packit |
70b277 |
before the execution of the @samp{z} command.
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Miscellaneous, Reporting bugs, Status Inquiry, Top
|
|
Packit |
70b277 |
@chapter Miscellaneous
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@table @samp
|
|
Packit |
70b277 |
@item !
|
|
Packit |
70b277 |
Will run the rest of the line as a system command.
|
|
Packit |
70b277 |
Note that parsing of the !<, !=, and !> commands take precedence,
|
|
Packit |
70b277 |
so if you want to run a command starting with <, =, or > you will
|
|
Packit |
70b277 |
need to add a space after the !.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item #
|
|
Packit |
70b277 |
Will interpret the rest of the line as a comment.
|
|
Packit |
70b277 |
(This command is a @sc{gnu} extension.)
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item :@var{r}
|
|
Packit |
70b277 |
Will pop the top two values off of the stack.
|
|
Packit |
70b277 |
The old second-to-top value will be stored in the array @var{r},
|
|
Packit |
70b277 |
indexed by the old top-of-stack value.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@item ;@var{r}
|
|
Packit |
70b277 |
Pops the top-of-stack and uses it as an index into
|
|
Packit |
70b277 |
the array @var{r}.
|
|
Packit |
70b277 |
The selected value is then pushed onto the stack.
|
|
Packit |
70b277 |
@end table
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
Note that each stacked instance of a register has its own
|
|
Packit |
70b277 |
array associated with it.
|
|
Packit |
70b277 |
Thus @samp{1 @var{0:a} 0S@var{a} 2 @var{0:a} L@var{a} @var{0;a}p}
|
|
Packit |
70b277 |
will print 1, because the 2 was stored in an instance of @var{0:a}
|
|
Packit |
70b277 |
that was later popped.
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
@node Reporting bugs, , Miscellaneous, Top
|
|
Packit |
70b277 |
@chapter Reporting bugs
|
|
Packit |
70b277 |
|
|
Packit |
70b277 |
Email bug reports to @email{bug-dc@@gnu.org}.
|
|
Packit |
70b277 |
@contents
|
|
Packit |
70b277 |
@bye
|