Category:Dc: Difference between revisions
Content added Content deleted
No edit summary |
(Expand the quick reference to cover OpenBSD dc.) |
||
Line 4: | Line 4: | ||
}}dc is the unix desktop calculator. It uses a reverse polish notation and is turing complete. |
}}dc is the unix desktop calculator. It uses a reverse polish notation and is turing complete. |
||
== Quick reference == |
|||
Commands in |
Commands in [[AT&T dc]] |
||
number : push a number |
|||
number : push a number (0-9A-F digits, _ negative, . radix point) |
|||
⚫ | |||
[...] : push a string |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
d : duplicate top of the stack |
d : duplicate top of the stack |
||
⚫ | |||
⚫ | |||
f : show stack |
f : show stack |
||
p : print value with a newline, leave it on the stack |
|||
P : print string, or print number as ASCII string |
|||
sx : store to register x |
|||
lx : load from register x |
|||
Sx : push to register x |
|||
Lx : pop register x |
|||
a b :x : store x[b] = a (x is register) |
|||
⚫ | |||
<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 |
! : shell command |
||
q : quit, or break 2 execution levels |
|||
n Q : break n execution levels |
|||
i : set input radix from top of stack |
i : set input radix from top of stack |
||
I : |
I : get current input base, push it on stack |
||
o : set output radix from top of stack |
o : set output radix from top of stack |
||
O : |
O : get current output base, push it on stack |
||
k : set scale factor |
k : set scale factor |
||
K : get current scale factor |
K : get current scale factor |
||
x : execute a string of dc commands |
|||
X : count decimal digits after decimal point |
|||
z : count elements on the stack |
|||
Z : count all decimal digits in number, or characters in string |
|||
⚫ | |||
Y : debug information |
Y : debug information |
||
a b :r : store r[b] = a (r is register) |
|||
⚫ | |||
Extensions in both [[GNU dc]] and [[OpenBSD dc]] |
|||
GNU Extensions |
|||
⚫ | |||
n : print value without a newline |
|||
~ : divmod: division and remainder |
|||
⚫ | |||
⚫ | |||
Extension in [[GNU dc]] |
|||
⚫ | |||
⚫ | |||
| : arithmetic - modular exponentiation |
| : arithmetic - modular exponentiation |
||
⚫ | |||
Extensions in [[OpenBSD dc]] |
|||
⚫ | |||
n J : break n execution levels, then jump to next M |
|||
!>r !<r !=r : execute contents of register x based on comparison |
|||
M : mark for the J command |
|||
a N : boolean not: push 1 if a == 0, else push 0 |
|||
⚫ | |||
<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 |