Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

bc(1)

DC(1)                                BSD                                 DC(1)



NAME
     dc - desk calculator

SYNOPSIS
     dc [ file ]

DESCRIPTION
     dc is an arbitrary precision arithmetic package.  Ordinarily, it operates
     on decimal integers, but you can specify an input base, output base, and
     a number of fractional digits to be maintained.  bc(1) is the
     preprocessor to this package, providing infix notation, a C-like syntax
     that implements functions, and reasonable control structures for
     programs.  dc is, fundamentally, a stacking calculator.  If you specify
     an argument, dc takes input from that file until its end, and then takes
     it from the standard input.

OPERATORS
     number       The value of the number pushed on the stack.  A number is an
                  unbroken string of the digits 0-9.  Precede it by an
                  underscore (_) to signify a negative number.  A number can
                  also contain decimal points.

     + - / * % ^  Add (+), subtract (-), multiply (*), divide (/), remainder
                  (%), or exponentiate (^) the top two values on the stack.
                  Pop the two entries off the stack; push the result on the
                  stack in their place.  Ignore any fractional part of an
                  exponent.

     sx           Pop the top of the stack and store it in a register named x,
                  where x can be any character.  If you specify capital S,
                  treat x as a stack and push the value on it.

     lx           Push the value in x on the stack.  The register x remains
                  unchanged.  All registers start with zero value.  If you
                  specify capital L, treat 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.  Do not change the top
                  value.

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

     f            Print all values on the stack.

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

     Q            Pop the top value on the stack, and 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.

     <x   >x   =x Pop the top two elements of the stack and compare them.
                  Evaluate register x if the elements obey the stated
                  relation.

     v            Replace the top element on the stack by its square root.
                  Take any existing fractional part of the argument into
                  account, but otherwise ignore the scale factor.

     !            Interpret the rest of the line as a UNIX command.

     c            Pop all values on the stack.

     i            Pop the top value on the stack and use it as the number
                  radix for further input.  Push the input base on top of the
                  stack.

     o            Pop the top value on the stack and use it as the number
                  radix for further output.

     O            Push the output base on top of the stack.

     k            Pop the top of the stack and use that value as a non-
                  negative scale factor.  Print the appropriate number of
                  places output, and maintain them during multiplication,
                  division, and exponentiation.  The interaction of scale
                  factor, input base, and output base is 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
                  terminal) and execute it.

     ; :          Used by bc(1) for array operations.

EXAMPLE
     To print the first 10 values of n!, specify the following:

        [la1+dsa*pla10>y]sy
        0sa1
        lyx

DIAGNOSTICS
     "x is unimplemented"
                         Value of x is an octal number.
     "Stack empty"       There are not enough elements on the stack to do what
                         was asked.
     "Out of space"      The free list is exhausted (too many digits).
     "Out of headers"    Too many numbers are being retained.
     "Out of pushdown"   Too many items are on the stack.
     "Nesting Depth"     There are too many levels of nested execution.

SEE ALSO
     bc(1)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026