Forrest logo
tool overview
On this page you find all important commands for the CLI tool dc. If the command you are looking for is missing please ask our AI.

dc

dc stands for Desk Calculator, and it is a command line tool for performing arithmetic calculations primarily involving arbitrary-precision decimal numbers. It is often used as a reverse-polish notation (RPN) calculator.

With dc, you can perform mathematical operations like addition, subtraction, multiplication, division, exponentiation, square roots, trigonometric functions, and much more. It supports floating-point calculations and can handle very large numbers with high precision.

The syntax for dc is a bit different from the typical arithmetic expressions you might be used to. Instead of writing expressions like 1 + 2, you would enter them in postfix notation like this: 1 2 +. The operands are typed in first, followed by the operator.

One of the notable features of dc is its ability to chain multiple operations in a single line. For example, you can calculate the sum of squares of a list of numbers easily with just one line of input.

dc is a versatile tool for performing calculations in scripts or on the command line without the need for a separate calculator application. It is simple and efficient, making it popular among Unix-like operating systems and scripting enthusiasts.

List of commands for dc:

  • dc:tldr:2a542 dc: Set number of decimal places to 7 (7 k), calculate 5 divided by -3 (5 _3 /) and [p]rint.
    $ dc --expression='7 k 5 _3 / p'
    try on your machine
    explain this command
  • dc:tldr:2c292 dc: Calculate the golden ratio, phi: set number of decimal places to 100 (100 k), square root of 5 (5 v) plus 1 (1 +), divided by 2 (2 /), and [p]rint result.
    $ dc --expression='100 k 5 v 1 + 2 / p'
    try on your machine
    explain this command
  • dc:tldr:3212f dc: Start an interactive session.
    $ dc
    try on your machine
    explain this command
  • dc:tldr:61f90 dc: Calculate an expression with the specified scale.
    $ dc --expression='${10} k ${5 3 -} p'
    try on your machine
    explain this command
  • dc:tldr:87c7c dc: Execute a script.
    $ dc ${path-to-script-dc}
    try on your machine
    explain this command
tool overview