unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Page:
Section:
Apropos / Subsearch:
optional field

DC(1)                       General Commands Manual                      DC(1)



NAME
       dc - desk calculator

SYNOPSIS
       dc [ filename ]

DESCRIPTION
       dc  is  an arbitrary precision arithmetic package.  Ordinarily it oper-
       ates on decimal integers, but an input base, output base, and a  number
       of  fractional  digits  to  be maintained may be specified. The overall
       structure of dc is a stacking (reverse Polish) calculator.  If an argu-
       ment  is  given,  input is taken from that file until its end, and then
       from the standard input.

       Note: bc(1) is a preprocessor for dc that provides infix (normal arith-
       metic)  notation, a C-like syntax for functions, and reasonable control
       structures for programs.

       The following input constructs are recognized:

   Commands
       number    Push a number onto the stack.  A number is an unbroken string
                 of  the  digits 0-9.  It may be preceded by an underscore `_'
                 to input a negative number, and may contain decimal points.

       +  - /  *  %  ^
                 The top two values on the stack are:  added  (+),  subtracted
                 (-),  multiplied  (*), divided (/), remaindered (%), or expo-
                 nentiated (^).  The two entries are popped off the stack  and
                 the  result is pushed in their place.  Any fractional part of
                 an exponent is ignored.

       sx        Pop the top of the stack and store into a register  named  x,
                 where x is any character.

       Sx        Treat x as a stack and push the value onto it.

       lx        Push  the value in register x onto the stack.  The register x
                 is not altered.  All registers start with zero value.

       Lx        Treat register x as a stack, and pop its top value  onto  the
                 main stack.

       d         Duplicate the top value on the stack.

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

       P         Interpret the top of the stack as an ASCII string, remove and
                 print it.

       f         Print all values on the stack and in registers.

       q         Exit  the  program.  If executing a string, pop the recursion
                 level by two.

       Q         Pop the top value on the stack, and pop the string  execution
                 level by that value.

       x         Treat  the top element of the stack as a character string and
                 execute it as a string of dc commands.

       X         Replace the number on the top of the  stack  with  its  scale
                 factor.

       [...]     Put the bracketed ASCII string onto the top of the stack.

       <&lt;x  >&gt;x  =x
                 Pop  and compare top two elements of the stack.  Execute reg-
                 ister x if they obey the stated relation.

       v         Replace the top element on the stack by its square root.  Any
                 existing  fractional  part  of  the  argument  is  taken into
                 account, but otherwise the scale factor is ignored.

       !         Interpret the rest of the line as a command.

       c         Clear all values on the stack.

       i         Pop the top value on the stack and  use  that  value  as  the
                 input radix.

       I         Push the input base on the top of the stack.

       o         Pop the top value on the stack and use as the output radix.

       O         Push the output base on the top of the stack.

       k         The  top  of the stack is popped, and that value is used as a
                 non-negative scale factor: the appropriate number  of  places
                 are  printed on output, and maintained during multiplication,
                 division, and exponentiation.  The interaction of scale  fac-
                 tor,  input  base,  and output base will be reasonable if all
                 are changed together.

       z         Push the stack level onto the stack.

       Z         Replace the number on the top of the stack with its length.

       ?         Take a line of input from the input source (usually the  ter-
                 minal) and execute it.

       ; :       Used by bc for array operations.

EXAMPLE
       Print the first ten values of n!
              [la1+dsa*pla10>&gt;y]sy
              0sa1
              lyx

SEE ALSO
       bc(1)

DIAGNOSTICS
       x is unimplemented     Where x is an octal number.
       stack empty            For  not enough elements on the stack to do what
                              was asked.
       Out of space           When the free list is exhausted (too  many  dig-
                              its).
       Out of headers         For too many numbers being kept around.
       Out of pushdown        For too many items on the stack.
       Nesting Depth          For too many levels of nested execution.

BUGS
       Base conversions on fractions are truncated to the number of fractional
       digits of the input value.  The values are not rounded.



                               23 September 1987                         DC(1)