Forrest logo
back to the dc tool

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

The command dc --expression='7 k 5 _3 / p' is using the dc utility to evaluate a Reverse Polish Notation (RPN) expression.

In RPN, mathematical operators are placed after their operands instead of between them like in traditional notation. Here's how the command breaks down:

  • dc is the command-line tool being used. It stands for "desk calculator" and is commonly found on Unix-like systems.
  • --expression='7 k 5 _3 / p' is an option passed to dc, specifying the RPN expression to be evaluated.

Let's break down the RPN expression itself:

  1. 7 is pushed onto the stack. The stack is a data structure used by dc to hold intermediate results during the evaluation of RPN expressions.
  2. k duplicates the top value of the stack. So now we have two 7s on the stack.
  3. 5 is pushed onto the stack.
  4. _3 pushes a negative value onto the stack (-3 in this case).
  5. / performs division. The top two values (5 and -3) are divided, resulting in -1.6666...
  6. p prints the top value of the stack. In this case, it will output -1.6666....

So, the command dc --expression='7 k 5 _3 / p' calculates the division of 5 by -3 and prints the result, which is approximately -1.6666.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the dc tool