Hubbry Logo
search
logo

Dc (computer program)

logo
Community Hub0 Subscribers
Write something...
Be the first to start a discussion here.
Be the first to start a discussion here.
See all
Dc (computer program)

dc (desk calculator) is a cross-platform reverse-Polish calculator which supports arbitrary-precision arithmetic. It was written by Lorinda Cherry and Robert Morris at Bell Labs. It is one of the oldest Unix utilities, preceding even the invention of the C programming language. Like other utilities of that vintage, it has a powerful set of features but terse syntax. Traditionally, the bc calculator program (with infix notation) was implemented on top of dc, now the implementation of GNU dc bases on bc.

This article provides some examples in an attempt to give a general flavour of the language; for a complete list of commands and syntax, one should consult the man page for one's specific implementation.

dc is the oldest surviving Unix language program. When its home Bell Labs received a PDP-11, dc—written in B—was the first language to run on the new computer, even before an assembler. Ken Thompson has opined that dc was the very first program written on the machine.

To multiply four and five in dc (note that most of the whitespace is optional):

The results are also available from the commands:

or

This translates into "push four and five onto the stack, then, with the multiplication operator, pop two elements from the stack, multiply them and push the result onto the stack." Then the p command is used to examine (print out to the screen) the top element on the stack. The q command quits the invoked instance of dc. Note that numbers must be spaced from each other even as some operators need not be.

The arithmetic precision is changed with the command k, which sets the number of fractional digits (the number of digits following the point) to be used for arithmetic operations. Since the default precision is zero, this sequence of commands produces 0 as a result:

See all
User Avatar
No comments yet.