|
|
coherent
dc Command dc
Desk calculator
dc [_f_i_l_e]
dc is an arbitrary precision desk calculator. It simulates a
stacking calculator with ancillary registers. Input must be en-
tered in reverse Polish notation. dc maintains the expected num-
ber of decimal places during addition, subtraction, and multi-
plication, but the user must make an explicit request to maintain
any places at all during division.
dc reads input from file if specified, and then from the standard
input. dc accepts an arbitrary number of commands per line;
moreover, spaces need not be left between them.
The scale factor of a number is the number of places to the right
of its decimal point. The scale factor register controls decimal
places in calculations. The scale factor does not affect addi-
tion or subtraction. It affects multiplication only if the sum
of the scale factors of the two operands is greater than it. The
result of every division command has as many decimal places as it
specifies. It affects exponentiation in that multiplication is
performed as many times as the integer part of the exponent in-
dicates; any fractional part of the exponent is ignored.
dc recognizes the following commands and constructions:
_n_u_m_b_e_r
Stack the value of number. A number is a string of symbols
taken from the digits `0' through `9', and the capital let-
ters `A' through `F' (usual hexadecimal notation), with an
optional decimal point. An underscore `_' as a prefix in-
dicates a negative number. The letters retain values ten
through 15, respectively, regardless of the base chosen by
the user.
+ - / * % ^
The arithmetic operations: addition(+), subtraction(-),
division(/), multiplication(*), remainder(%), and exponen-
tiation(^). dc pops the two top stack elements, performs
the desired operation by calling the multiprecision routine
desired (see multiprecision arithmetic), and stacks the
result.
cc Clear the stack.
dd Duplicate the top of the stack (so that it occupies the top
two positions of the stack).
ff Print the contents of the stack and the values of all
registers.
ii Remove the top of the stack and use its integer part as the
assumed input base (default, ten). The new input base must
COHERENT Lexicon Page 1
dc Command dc
be greater than one and less than 17.
II Stack the current assumed input base.
kk Remove the top of the stack and put it in the internal scale
factor register.
KK Put the value of the internal scale register (which the k
command sets) on the top of the stack.
ll _x Load the value of register x to the top of the stack. The
value of register x is unaltered. x may be any character.
oo Remove the top of the stack and use its integer part as the
assumed output base (default, ten). The specified base may
be any positive integer.
OO Stack the current assumed output base.
pp Print the top of the stack. The value remains on the stack.
qq Quit the program; control returns to the shell sh.
ss _x Remove the top of the stack and store it in register x. The
previous contents of x are overwritten. x may be any
character.
vv Replace the top of the stack by its square root.
xx Remove the top of the stack, interpret it as a string con-
taining a sequence of dc commands, and execute it.
XX Replace the top of the stack by its scale factor (i.e., the
number of decimal places it has).
zz Place the number of occupied levels of the stack on top of
the stack.
[...]
Place the bracketed character string on top of the stack.
The string may be executed subsequently with the x command.
<_x >_x =_x !<_x !>_x !=_x
Remove the top two elements of the stack and compare them.
If there is no `!' sign before the relation, execute
register x if the two elements obey the relation. If a `!'
sign is present, execute register x if the elements do not
obey the relation.
! Interpret the rest of the line as a command to the shell sh.
Control returns to dc after command execution terminates.
***** Example *****
COHERENT Lexicon Page 2
dc Command dc
The following example program prints the first 20 Fibbonacci num-
bers. The characters 11 and ll are printed in boldface to help you
tell them apart.
11sa11sb11sc
[llallbdsa+psbllc11+dsc211<y]sy
llyx
***** See Also *****
bc, commands
***** Diagnostics *****
dc produces one of the following error messages should a problem
occur:
Stack empty Not enough stack elements to perform as requested
Out of pushdownNo more room on the stack
Nesting depth Too many nested execution levels
Out of space Too many digits demanded
Out of headers Too many numbers being stored
***** Notes *****
For most purposes the infix notation of bc is more convenient
than the Polish notation of dc.
COHERENT Lexicon Page 3
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.