[Top] | [Contents] | [Index] | [ ? ] |
1. Introduction | ||
2. Invocation | ||
3. Printing Commands | ||
4. Arithmetic | ||
5. Stack Control | ||
6. Registers | ||
7. Parameters | ||
8. Strings | ||
9. Status Inquiry | ||
10. Miscellaneous | Other commands | |
11. Reporting bugs |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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
instead of reading from standard input.
All normal output is to standard output;
all error messages are written to standard error.
To exit, use `q'. C-c does not exit; it is used to abort macros that are looping, etc. (Currently this is not true; 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 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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dc
may be invoked with the following command-line options:
dc
commands.
dc
commands from file.
If any command-line parameters remain after processing the options,
these parameters are interpreted as additional files whose
contents are read and evaluated.
A file name of -
refers to the standard input stream.
If no -e
option was specified, and no files were specified,
then the standard input will be read for commands to evaluate.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
KSK0k1/ _1Ss[ls*]Sxd0>x
[256~Ssd0<x]dsxx
sx[q]Sq[Lsd0>qaPlxx]dsxx
sx0sqLqsxLxLK+k
could also accomplish this function.
(Much of the complexity of the above native-dc code is due
to the ~ computing the characters backwards,
and the desire to ensure that all registers wind up back
in their original states.)
(Details of the behavior with a number are a GNU extension.)
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sd dld/ Ld*-
.
SdSn lnld/ LnLd%
could also accomplish
this function, with slightly different error checking.)
(This command is a GNU extension.)
Sm^Lm%
,
but, unlike ^
,
this command will work with arbritrarily large exponents.
(This command is a GNU extension.)
Most arithmetic operations are affected by the precision value, which you can set with the `k' command. The default precision value is zero, which means that all arithmetic except for addition and subtraction produces integer results.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SaSbLaLb
.)
(This command is a GNU extension.)
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dc
provides at least 256 memory registers(1),
each named by a single character.
You can store a number in a register and retrieve it later.
Each register also contains its own stack. The current register value is the top of the register's stack.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dc
has three parameters that control its operation:
the precision, the input radix, and the output radix.
The precision specifies the number of fraction digits
to keep in the result of most arithmetic operations.
The input radix controls the interpretation of numbers typed in;
all numbers typed in use this radix.
The output radix is used for printing numbers.
The input and output radices are separate parameters; you can make them unequal, which can be useful or confusing. The input radix must be between 2 and 16 inclusive. The output radix must be at least 2. The precision must be zero or greater. The precision is always measured in decimal digits, regardless of the current input or output radix.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dc
has a limited ability
to operate on strings as well as on numbers;
the only things you can do with strings are print them
and execute them as macros
(which means that the contents of the string are processed
as dc
commands).
Both registers and the stack can hold strings,
and dc
always knows whether any given object is
a string or a number.
Some commands such as arithmetic operations demand numbers
as arguments and print errors if given strings.
Other commands can accept either a number or a string;
for example, the `p' command can accept either and prints the object
according to its type.
Macros are most often stored in registers; `[1p]sa' stores a macro to print `1' into register `a', and `lax' invokes the macro.
dc
to exit.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Note that each stacked instance of a register has its own array associated 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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Email bug reports to bug-dc@gnu.org.
[Top] | [Contents] | [Index] | [ ? ] |
The
exact number of registers provided by dc
depends
on the range of an unsigned char
in the C compiler
used to create the dc
executable.
[Top] | [Contents] | [Index] | [ ? ] |
1. Introduction
2. Invocation
3. Printing Commands
4. Arithmetic
5. Stack Control
6. Registers
7. Parameters
8. Strings
9. Status Inquiry
10. Miscellaneous
11. Reporting bugs
[Top] | [Contents] | [Index] | [ ? ] |
1. Introduction
2. Invocation
3. Printing Commands
4. Arithmetic
5. Stack Control
6. Registers
7. Parameters
8. Strings
9. Status Inquiry
10. Miscellaneous
11. Reporting bugs
[Top] | [Contents] | [Index] | [ ? ] |
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ < ] | Back | previous section in reading order | 1.2.2 |
[ > ] | Forward | next section in reading order | 1.2.4 |
[ << ] | FastBack | beginning of this chapter or previous chapter | 1 |
[ Up ] | Up | up section | 1.2 |
[ >> ] | FastForward | next chapter | 2 |
[Top] | Top | cover (top) of document | |
[Contents] | Contents | table of contents | |
[Index] | Index | concept index | |
[ ? ] | About | this page |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure: