Dc (computer program)
Dc ( an acronym for desk calculator ) is a computer program for the Unix Unix derivatives. It uses the principle of reverse Polish notation, is one of the oldest Unix tools - even older than the programming language C. In practice bc dc is mostly preferred because users have problems with the reversed Polish notation. The bc program builds on dc.
Note: the p at the end of the input is in print and gives the result, specifically the last element of the stack, from. In the examples, the result is also listed in the last row. All spaces and lines with the exception of these, which stand between digits are optional. The syntax may seem a bit random and differs fundamentally from the one that would, for example, type into a calculator. The reason is that dc working stack -based. The first example would be translated verbally " move ( push) the two elements six and eight on the stack, remove ( pop) it with the multiplication operator, they multiply and write the result back on the stack, then enter the contents of the stack on the screen. "
Multiplication: Calculated 6 * 8
6 8 * p 48 Several arithmetic combined: Calculated ( 12 3 ^ 4) / 11-22:
12 3 4 ^ 11/22 - p -14 register: Besides stacks can also register, so to speak, second-order stacks, are used. With s name> Registers> (eg sc for the tab with the name c ) elements are pushed out with l name> Registers> from it. The first example with registers instead of stack:
6 sc 8 lc * p 48 The following example computes (1 3) * 2 with the aid of a register (m):
[1 2 * ] sm 3 ln x p X performs the calculation on the stack.
It can be performed with dc macros:
Dc -e ' [ [ Give a value in meters to or press 0 to quit ] psj ] sh [q ] sz [ lhx? d0 = z10k39.370079 * .5 0 k12 ~ 1/rn [ feet] Pn [ inches] P10Pdx ] dx ' This is no longer the dc- own shell is used but the macro with the -e switch ( for execute, execute dt ) at dc passed. The script expects the unit to meters in feet and inches.