Category:Dc: Difference between revisions

m
no edit summary
(array correction & mine also has ~; GNU extension?)
mNo edit summary
 
(9 intermediate revisions by 3 users not shown)
Line 1:
{{language
{{language}}dc is the unix desktop calculator. It uses a reverse polish notation and is turing complete.
|exec=interpreted
|checking=dynamic
|hopl id=1957
}}
{{language programming paradigm|concatenative}}
[[Category:Utility]]
 
[[wp:dc (computer program)|dc]] is the unix '''d'''esktop '''c'''alculator. <br>
Commands in POSIX dc
{{language}}dc is the unix desktop calculator. It uses a reverse polish notation and is turing complete.
number : push a number
 
+ - / * % ^ : arithmetic operations: add sub div mul mod exp
;See also
sx Sx : pop the stack and save or push it to register x
* [[:Category:Bc|bc]] - '''b'''asic '''c'''alculator
lx Lx : copy | pop the register x to main stack.
 
 
== Quick reference ==
Commands in POSIX[[AT&T dc]]
number : push a number (0-9A-F digits, _ negative, . radix point)
number[...] : push a numberstring
+ - / * / % ^ : arithmetic operations: add sub div mul div mod exppow
av : asciifysquare root
pc : print top of theclear stack
d : duplicate top of the stack
p : print top of the stack
P : pop and print String
f : show stack
qp : exitprint (dropvalue executionwith stacka bynewline, 2)leave it on the stack
QP : dropprint executionstring, stackor byprint topnumber ofas theASCII stack numberstring
x sx : executestore dcto commandsregister on top of the stackx
X lx : replace top of stack byload itsfrom scaleregister factor.x
[...]Sx : stringpush to register notationx
<xLx >x =x : compare 2 elements at top of the stack, and: executepop register x
v1 2 :x : store x[2] := 1 (x squareis rootregister)
a2 ;rx : retrieve rx[b2]
<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
cq : clearquit, or break 2 execution levels
3 Q : break 3 execution levels
i : set input radix from top of stack
I : pushget current input base, onpush theit top of theon stack.
o : set output radix from top of stack
O : pushget current output base, onpush theit top of theon stack.
k : set scale factor
K : get current scale factor
zx : getexecute thea currentstring stackof level.dc commands
ZX : getcount thedecimal characterdigits lengthafter ofdecimal element at top of stackpoint
?z : readcount inputelements andon execute.the stack
Z : count all decimal digits in number, or characters in string
P? : popread and printexecute Stringone line of input
Y : debug information
a b :r : store r[b] = a (r is register)
a ;r : retrieve r[b]
 
Extensions in both [[GNU dc]] and [[OpenBSD dc]]
GNU Extensions
na : print value without a newASCII linecharacter
n : print value without a newline
~ : divmod: division and remainder
r : reverse (swap) the top two elements
~# : arithmetic - divmodcomment
 
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
3 J : break 3 execution levels, then jump to next M
!>r !<r !=r : execute contents of register x based on comparison
XM : pushesmark for the number of fractionalJ digitscommand
#R : commentpop and discard top of the stack
<xey >xey : comparisons with an else branch: if true,
=xey !<xey : then execute register x
!>xey !=xey : else execute register y
1 2 G : equality: push 1 if 2 == 1, else push 0
1 2 ( : less than: push 1 if 2 < 1, else push 0
3 N : boolean not: push 1 if 3 == 0, else push 0
Anonymous user