

DC (1)                      07/20/80                       DC (1)


NAME
   dc - desk calculator

SYNOPSIS
   dc [files ...]

DESCRIPTION
   DC  evaluates  integer  expressions from the source files, one
   expression per input line. If no input files are given, or the
   filename '-' is specified, dc reads from the standard input.
   
   Ordinarily  dc  operates   on   decimal   integer   arithmetic
   expressions, but the user may specify an input base and output
   base other than decimal.
   
   Expressions   may   be   simple   arithmetic   expressions  or
   replacement expressions. The values of simple expressions  are
   written   on   standard   output   when  they  are  evaluated.
   Replacement expressions are used to hold temporary values, and
   are not automatically printed.
   
   A simple expression is a normal  arithmetic  expression  using
   numbers,  variables, parentheses, and the following operators,
   listed in order of precedence:
        +  -          unary plus and negation operators.  These may  
                          only appear at the start of a simple
                          expression or after a "("
        
        **            exponentiation
        
        *   /   %     multiply, divide, modulo (remainder)
        
        +   -         add, subtract
        
        == !=         relations - equals, not equal to,
        >  >=         greater than, greater than or equal to,
        <  <=         less than, less than or equal to
                       (!=, ^=, ~= all treated as "not equal")
        
        !             unary logical not (also ~ and ^)
        
        |   &         logical or, and
        
   The logical operators !  |  &  and  the  relational  operators
   result in the values 1 for true and 0 for false.
   
   A replacement expression is:

                      name = simple expression

   where  'name' is a character string of (virtually) any length,
   starting with a letter and  consisting  of  only  letters  and
   digits.  (The  characters a-f should not be considered letters


                               -1-                               


DC (1)                      07/20/80                       DC (1)


   when   operating   in   hexadecimal   mode.)   Variables   are
   automatically  declared  when they first appear to the left of
   an "="  sign,  and  they  should  not  be  used  in  a  simple
   expression until they have been declared.
   
   Radix Control
        Radix control is available in 2 ways:
        1)  There  are  default  radix  values for both input and
        output which may be changed  by  setting  the  predefined
        variables   'ibase'  (input  base)  and  'obase'  (output
        base).  (Radix 10 is always used to evaluate and/or print
        radix-defining expressions.) For example,

                  ibase = 2
                  obase = 16

        would  accept  input  in  binary  and  print  results  in
        hexadecimal.
        
        2)   The  radix  of  individual numbers may be explicitly
        given  by  following  the  number  with   an   underscore
        character and then the desired radix. For example,

                                 100_16

        would specify the hex number 100 (256 in decimal).

EXAMPLES

                  10 + (-64 / 2**4)
   would print the answer "6"

                  temp = 101_2
                  temp == 5
   would print the answer "1" (true)
   
                  ibase = 16
                  obase = 2
                  1a + f
   would print the answer "101001"

                  ibase = 16
                  numa = 100_10
                  numb = 100
                  numa + numb
   would print the answer "356"

FILES
   None






                               -2-                               


DC (1)                      07/20/80                       DC (1)


SEE ALSO
   macro, the UNIX M4 macro package
   The UNIX tools dc and bc

DIAGNOSTICS
   arith evaluation stack overflow
      arithmetic  expressions  have  been  nested too deeply. The
      size of the stack is set by the MAXSTACK definition in  the
      source code.
      
   number error
      an  input  number  has  a  number/character bigger than the
      current radix

   expression error
      invalid arithmetic expression

AUTHOR
   Philip H. Scherrer (Stanford U.)

BUGS/DEFICIENCIES
   Dc only works with integers
   
   The maximum value allowed depends on the host machine  and  is
   the largest Fortran integer






























                               -3-                               

