

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.

cc    Clear the stack.

dd    Duplicate the top of the  stack (so that it occupies the top
     two positions of the stack).

ff     Print the  contents  of the  stack  and the  values of  all
     registers.

ii    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.

II    Stack the current assumed input base.

kk    Remove the top of the stack and put it in the internal scale
     factor register.

KK    Put  the value of  the internal scale register  (which the k
     command sets) on the top of the stack.

ll _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.

oo    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.

OO    Stack the current assumed output base.

pp    Print the top of the stack.  The value remains on the stack.

qq    Quit the program; control returns to the shell sh.

ss _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.

vv    Replace the top of the stack by its square root.

xx    Remove the  top of the stack, interpret it  as a string con-
     taining a sequence of dc commands, and execute it.

XX    Replace the top of the  stack by its scale factor (i.e., the
     number of decimal places it has).

zz    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 11 and ll are printed in boldface to help you
tell them apart.


        11sa11sb11sc
        [llallbdsa+psbllc11+dsc211<y]sy
        llyx


***** 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


