Category:Dc: Difference between revisions

From Rosetta Code
Content added Content deleted
(dc commands)
mNo edit summary
 
(10 intermediate revisions by 4 users not shown)
Line 1: 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
It uses a reverse polish notation and is turing complete.
number : push a number

+ - / * % ^ : arithmetic operations
;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 [[AT&T dc]]
number : push a number (0-9A-F digits, _ negative, . radix point)
[...] : push a string
+ - * / % ^ : arithmetic operations: add sub mul div mod pow
v : square root
c : clear stack
d : duplicate top of the stack
d : duplicate top of the stack
p : print top of the stack
P : pop and print String
f : show stack
f : show stack
q : exit (drop execution stack by 2)
p : print value with a newline, leave it on the stack
Q : drop execution stack by top of the stack number
P : print string, or print number as ASCII string
x : execute dc commands on top of the stack
sx : store to register x
X : replace top of stack by its scale factor.
lx : load from register x
[...] : string notation
Sx : push to register x
<x >x =x : compare 2 elements at top of the stack, and execute register x
Lx : pop register x
v : square root
1 2 :x : store x[2] = 1 (x is register)
2 ;x : retrieve x[2]
<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
c : clear
q : quit, or break 2 execution levels
3 Q : break 3 execution levels
i : set input radix from top of stack
i : set input radix from top of stack
I : push input base on the top of the stack.
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 : push output base on the top of the stack.
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
z : get the current stack level.
x : execute a string of dc commands
Z : get the character length of element at top of stack
X : count decimal digits after decimal point
? : read input and execute.
z : count elements on the stack
Z : count all decimal digits in number, or characters in string
? : read and execute one line of input
Y : debug information
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
a : print ASCII character
n : print value without a newline
~ : divmod: division and remainder
r : reverse (swap) the top two elements
# : comment


Extension in [[GNU dc]]
n : print value without a new line
| : arithmetic - modular exponentiation
| : 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
X : pushes the number of fractional digits
M : mark for the J command
# : comment
R : pop 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

Latest revision as of 15:08, 21 November 2014

Language
Dc
This programming language may be used to instruct a computer to perform a task.
Execution method: Interpreted
Type checking: Dynamic
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using Dc.

dc is the unix desktop calculator.
It uses a reverse polish notation and is turing complete.

See also
  • bc - basic calculator


Quick reference

Commands in AT&T dc

number      : push a number (0-9A-F digits, _ negative, . radix point)
[...]       : push a string
+ - * / % ^ : arithmetic operations: add sub mul div mod pow
v           : square root
c           : clear stack
d           : duplicate top of the 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
1 2 :x      : store x[2] = 1 (x is register)
2 ;x        : retrieve x[2]
<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
q           : quit, or break 2 execution levels
3 Q         : break 3 execution levels
i           : set input radix from top of stack
I           : get current input base, push it on stack
o           : set output radix from top of stack
O           : get current output base, push it on stack
k           : set 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
?           : read and execute one line of input
Y           : debug information

Extensions in both GNU dc and OpenBSD dc

a           : print ASCII character
n           : print value without a newline
~           : divmod: division and remainder
r           : reverse (swap) the top two elements
#           : comment

Extension in GNU dc

|           : arithmetic - modular exponentiation

Extensions in OpenBSD dc

3 J         : break 3 execution levels, then jump to next M
M           : mark for the J command
R           : pop 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

Subcategories

This category has the following 3 subcategories, out of 3 total.

Pages in category "Dc"

The following 90 pages are in this category, out of 90 total.