Anonymous user
Category:Dc: Difference between revisions
Expand the quick reference to cover OpenBSD dc.
No edit summary |
(Expand the quick reference to cover OpenBSD dc.) |
||
Line 4:
}}dc is the unix desktop calculator. It uses a reverse polish notation and is turing complete.
== Quick reference ==
Commands in
number : push a number (0-9A-F digits, _ negative, . radix point)
+ - / * % ^ : arithmetic operations: add sub div mul mod exp▼
lx Lx : copy | pop the register x to main stack.▼
d : duplicate top of the stack
▲ p : print top of the stack
P : pop and print String▼
f : show stack
<x >x =x : compare top 2 values: if true, then execute register x
!>x !<x !=x : (example: 5 2 <A executes register A if 2 < 5)
! : shell command
n Q : break n execution levels
i : set input radix from top of stack
I :
o : set output radix from top of stack
O :
k : set scale factor
K : get current scale factor
Z : count all decimal digits in number, or characters in string
Y : debug information
▲ a ;r : retrieve r[b]
Extensions in both [[GNU dc]] and [[OpenBSD dc]]
n : print value without a newline
~ : divmod: division and remainder
r : reverse (swap) the top two elements▼
Extension in [[GNU dc]]
▲ n : print value without a new line
▲ ~ : arithmetic - divmod
| : arithmetic - modular exponentiation
▲ r : swap the top two elements
Extensions in [[OpenBSD dc]]
▲ a : asciify
n J : break n execution levels, then jump to next M
<xey >xey : comparisons with an else branch: if true,
=xey !<xey : then execute register x
!>xey !=xey : else execute register y
a b G : equality: push 1 if b == a, else push 0
a b ( : less than: push 1 if b < a, else push 0
|