_                    _
  ___ | |__   __ _ _______ | |_
 / _ \| '_ \ / _` |_  / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
 \___/|_| |_|\__,_/___\___/ \__|

dcdesk calculator - rpn

It's a stack calculator using Reverse Polish Notation. Values are pushed into a stack and operations pop values from the stack in reverse order.

To get the result of 1 + 2:

1 2 + f
3
  1. 1 is pushed into the stack.
  2. 2 is pushed into the stack.
  3. + pops the top two values from the stack, adds them and the result is pushed into the stack.
  4. f prints the complete stack.

To get the result of 2 * 3 + 4:

  • one way to do it:
    2 3 * 4 + f
    10
    + pops 4 and *, therefore * pops 2 and 3, multiplies them and 6 is sent into the stack resulting in 6 4 +.
  • another way to do it:
    4 2 3 * + f
    10
    + pops * which pops 2 and 3 to get 6 which is pushed into the stack resulting in 4 6 +.

dc can be called with file: dc filename

back to top

The common operation are supported: + - * / ^.

% | pops the top two values, divides the second popped value by the first one and pushes the remainder into the stack. Eg.: 8 4 % fc 0, 8 5 % fc 3.
~ | similar but returns the quotient and remainder: 8 4 ~ fc 0 2, 8 5 ~ fc 3 1
v | pops the top value off the stack and calculates the square root.

back to top

f | prints stack.
p | prints value on top of the stack with newline.
n | prints value on top of the stack without newline.

back to top

c | clears the stack.
r | swap the top two values of the stack.
d | duplicates value on top of the stack.

back to top

sr | pops the top value off the stack and stores it into the register r. (r can be any single character)
Sr | same as s but overwrites the original value of the register.
lr | loads a copy of the value of register r.
Lr | loads the value of register r removing it from the register.

back to top

k | pop the top value off the stack and use it as the precision parameter.

back to top

Strings can be stored as [string], this can be used to store strings or operations as macros which can be saved as a macro.

[the string]p
the string
[2 2 +]Sa
laxp
4

Macros can be invoked based on conditions:

>r | compare the top two values of the stack and runs r if the top value of the stack is greater.
!>r | similar but runs r if the top value is not greater. (less or equal)
<r | runs r if the top value is lower than the seconf value..
!<r | runs r if the top value is not lower than the second value. (greater or equal)
=r | runs r if the top two values of the stack are equal.
!=r | runs r if the top two values of the stack are not equal.

Considering the top two values 1 2, r could run with the following comparisons: >r, !<r, !=r. r will not run with the following comparisons: !>r, <r, =r.

[runs]Sa
[lap]Sb
1 2 >b
runs
1 2 !>b
1 2 <b
1 2 !<b
runs
1 2 =b
1 2 !=b
runs

back to top

- OpenBSD manpages: dc(1)

back to top

ohazot | about | ohazot.com <admin@ohazot.com>

OpenBSD , linux | Created:2025-10-15|Updated:2025-10-15|