.Dd Created:2025-10-15|Updated:2025-10-15| .de ocsi \\$* , .. .de oxr .ocsi .Xr \\$* .. .de oit .It \\$* .. .de obdi .Bl -dash -compact .oit \\$* .. .de obdl .Bd -literal -compact \\$* .. .de onote .Bl -hang -compact .oit \\$* .El .. .de ocomm .Bl -diag -compact .oit \\$* .El .. .de opsy .Pp .Sy - \\$* .. .de obc .Bl -column \\$* .. .de obc2 .obc opt desc .. .de obc3 .obc option arguments description .. .Dt DC oh .Os OpenBSD , linux | .Nm dc .Nd desk calculator - rpn .Sh DESCRIPTION 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. .Ss .Ss Example To get the result of 1 + 2: .obdl 1 2 + f 3 .Ed .Bl -enum -compact .oit 1 is pushed into the stack. .oit 2 is pushed into the stack. .oit + pops the top two values from the stack, adds them and the result is pushed into the stack. .oit f prints the complete stack. .El .Ss Another example To get the result of 2 * 3 + 4: .obdi one way to do it: .obdl 2 3 * 4 + f 10 .Ed .D1 + pops 4 and *, therefore * pops 2 and 3, multiplies them and 6 is sent into the stack resulting in 6 4 +. .oit another way to do it: .obdl 4 2 3 * + f 10 .Ed .D1 + pops * which pops 2 and 3 to get 6 which is pushed into the stack resulting in 4 6 +. .El .Ss Scripting dc can be called with file: .Li dc filename .Sh OPERATIONS The common operation are supported: + - * / ^. .obc2 .It % Ta | 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. .It ~ Ta | similar but returns the quotient and remainder: 8 4 ~ fc 0 2, 8 5 ~ fc 3 1 .It v Ta | pops the top value off the stack and calculates the square root. .El .Sh PRINTING .obc2 .It f Ta | prints stack. .It p Ta | prints value on top of the stack with newline. .It n Ta | prints value on top of the stack without newline. .El .Sh STACK .obc2 .It c Ta | clears the stack. .It r Ta | swap the top two values of the stack. .It d Ta | duplicates value on top of the stack. .El .Sh REGISTERS .obc2 .It sr Ta | pops the top value off the stack and stores it into the register r. (r can be any single character) .It Sr Ta | same as s but overwrites the original value of the register. .It lr Ta | loads a copy of the value of register r. .It Lr Ta | loads the value of register r removing it from the register. .El .Sh PARAMETERS .obc2 .It k Ta | pop the top value off the stack and use it as the precision parameter. .El .Sh STRINGS Strings can be stored as [string], this can be used to store strings or operations as macros which can be saved as a macro. .Ss Example .obdl [the string]p the string [2 2 +]Sa laxp 4 .Ed .Ss Macros Macros can be invoked based on conditions: .obc2 .It >r Ta | compare the top two values of the stack and runs r if the top value of the stack is greater. .It !>r Ta | similar but runs r if the top value is not greater. (less or equal) .It r, !r, b runs 1 2 !>b 1 2