Dc (computer Program) - Basic Operations

Basic Operations

To multiply four and five in dc (note that most of the whitespace is optional):

4 5 * p

Notes: save it in a file, such as cal.txt, and run the command: dc cal.txt, you will see the result. Click "q" can exist from dc. You can also get the result by below command:

echo "4 5 * p" |dc

This translates into "push four and five onto the stack, then, with the multiplication operator, pop two elements from the stack, multiply them and push the result back on the stack." Then the 'p' command is used to examine (print out to the screen) the top element on the stack.

The arithmetic precision is changed with the command 'k', which sets the number of fractional digits (the number of digits following the point) to be used for arithmetic operations. Since the default precision is zero, this sequence of commands produces '0' as a result:

2 3 / p

By adjusting the precision with 'k', arbitrary number of decimal places can be produced. This command sequence outputs '.66666'.

5 k 2 3 / p

To evaluate : ('v' computes the square root of the top of the stack and '_' is used to input a negative number):

12 _3 4 ^ + 11 / v 22 - p

To swap the top two elements of the stack, use the 'r' command. To duplicate the top element, use the 'd' command.

Read more about this topic:  Dc (computer Program)

Famous quotes containing the words basic and/or operations:

    Surrealism is not a school of poetry but a movement of liberation.... A way of rediscovering the language of innocence, a renewal of the primordial pact, poetry is the basic text, the foundation of the human order. Surrealism is revolutionary because it is a return to the beginning of all beginnings.
    Octavio Paz (b. 1914)

    A sociosphere of contact, control, persuasion and dissuasion, of exhibitions of inhibitions in massive or homeopathic doses...: this is obscenity. All structures turned inside out and exhibited, all operations rendered visible. In America this goes all the way from the bewildering network of aerial telephone and electric wires ... to the concrete multiplication of all the bodily functions in the home, the litany of ingredients on the tiniest can of food, the exhibition of income or IQ.
    Jean Baudrillard (b. 1929)