Name
dc
Synopsis
dc [file]An interactive desk calculator program that performs
arbitrary-precision integer arithmetic (input may be taken from a
file). Normally you don’t run dc directly, since it’s invoked by
bc (see bc). dc provides a variety of one-character
commands and operators that perform arithmetic; dc works like a Reverse Polish
calculator; therefore, operators and commands follow the numbers
they affect. Operators include + - / * %
^ (as in C, although ^ means exponentiation).
GNU/Linux and Mac OS X use the GNU version of dc that accepts a number of options and has additional commands; see dc(1) for the details. Some simple commands follow.
|
|
Print current result. |
|
|
Quit dc. |
|
|
Clear all values on the stack. |
|
|
Take square root. |
|
|
Change input base; similar to
bc’s |
|
|
Change output base; similar to
bc’s |
|
|
Set scale factor (number of
digits after decimal); similar to bc’s |
|
|
Remainder of line is a Unix command. |
Examples
$dc3 2 ^ pEvaluate 3 squared, then print result 98 * pCurrent value (9) times 8, then print result 7247 - pSubtract 47 from 72, then print result 25v pSquare root of 25, then print result 52 o pDisplay current result in base 2 101
Note: spaces are not needed except between numbers.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access