COHERENT manpages

This page displays the COHERENT manpage for dc [Desk calculator].

List of available manpages
Index


dc -- Command

Desk calculator
dc [file]

dc  is an  arbitrary  precision desk  calculator. It  simulates a  stacking
calculator  with ancillary  registers.  Input  must  be entered  in reverse
Polish notation.  dc maintains the expected number of decimal places during
addition,  subtraction,  and  multiplication, 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 addition  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 indicates; any fractional part of the exponent is ignored.

dc recognizes the following commands and constructions:

number
     Stack the value of number. A  number is a string of symbols taken from
     the digits  `0' through `9',  and the capital letters  `A' through `F'
     (usual  hexadecimal notation),  with  an optional  decimal point.   An
     underscore `_'  as a prefix indicates 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 exponentiation(^).  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    Clear the stack.

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

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

i    Remove the  top of the stack  and use its integer  part as the assumed
     input base  (default, ten).  The  new input base must  be greater than
     one and less than 17.

I    Stack the current assumed input base.

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

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

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    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    Stack the current assumed output base.

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

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

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    Replace the top of the stack by its square root.

x    Remove the  top of the  stack, interpret it  as a string  containing a
     sequence of dc commands, and execute it.

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

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


The following example program  prints the first 20 Fibbonacci numbers.  The
character l is printed in boldface to help you tell from a numeric one.

    1sa1sb1sc
    [lalbdsa+psblc1+dsc21<y]sy
    lyx

See Also

bc,
commands

Notes

For most  purposes, the in-fix notation  of bc is more  convenient than the
Polish notation of dc.