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:
“When you realize how hard it is to know the truth about yourself, you understand that even the most exhaustive and well-meaning autobiography, determined to tell the truth, represents, at best, a guess. There have been times in my life when I felt incredibly happy. Life was full. I seemed productive. Then I thought,Am I really happy or am I merely masking a deep depression with frantic activity? If I dont know such basic things about myself, who does?”
—Phyllis Rose (b. 1942)
“You cant have operations without screams. Pain and the knifetheyre inseparable.”
—Jean Scott Rogers. Robert Day. Mr. Blount (Frank Pettingell)