Basic Operations
To multiply four and five in dc (note that most of the whitespace is optional):
4 5 * pNotes: 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" |dcThis 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 / pBy adjusting the precision with 'k', arbitrary number of decimal places can be produced. This command sequence outputs '.66666'.
5 k 2 3 / pTo 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 - pTo 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:
“Justice begins with the recognition of the necessity of sharing. The oldest law is that which regulates it, and this is still the most important law today and, as such, has remained the basic concern of all movements which have at heart the community of human activities and of human existence in general.”
—Elias Canetti (b. 1905)
“There is a patent office at the seat of government of the universe, whose managers are as much interested in the dispersion of seeds as anybody at Washington can be, and their operations are infinitely more extensive and regular.”
—Henry David Thoreau (18171862)