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