Dc calculator in linux

Source: Internet
Author: User
In linux, the dc calculator dc adopts the inverse Polish expression, and the calculation process is manual maintenance of the stack. The reverse Polish style looks awkward, but it runs very efficiently. Nothing is messy, and the script positive question and negative sign are directly used in the dc to represent rather than-, because-is a binary operation... in linux, the dc calculator dc adopts the inverse Polish expression, and the calculation process is manual maintenance of the stack. The reverse Polish style looks awkward, but it runs very efficiently. If you don't talk about things in a mess, you can directly enter the script positive question and negative sign in dc and use _ to represent rather than-, because-is a binary operator "minus sign" printing class Command: p: print the top element of the stack and wrap the line n: print the top element of the stack and bring it to the stack. do not wrap the line P: putchar (int (top element of the stack) % 256) and roll the top of the stack, do not wrap f: print all values in the stack from the top of the stack to the bottom of the stack. each line of arithmetic operator: +: displays w1 and w2, and presses w2 + w1 on the stack. Precision for the result value of precision-: in turn the w1 and w2 pop up, the w2-w1 pressure stack *: in turn the w1 and w2 pop up, the w2 * w1 pressure stack. Accuracy is the result value accuracy and precision is more accurate/: in turn, w1 and w2 are displayed, and w2/w1 is pressed to the stack. Precision for precision %: pop up w1 and w2, w2-w2/w1 * w1 pressure stack ~: Press w1 and w2 in sequence, press w2/w1 and w2 % w1 in sequence, and press w1 and w2 in sequence, and press w2 ^ (int) w1) in sequence. Accuracy: w2 accuracy and precision are more accurate |: in turn, w1 w2 and w3 are displayed, and w3 ^ (int) w2) (mod w1) is pressed to the stack. W1 w3 must be an integer v: w1 is displayed, and sqrt (v) is pressed to the stack. Precision for precision stack operation: c: clear stack d: Copy Top stack elements and press stack r: switch top stack two elements XXX register operation: dc provides at least 256 registers, it must be 256 characters long. Generally, 'A'... 'Z' is used. 123ABC is not enough! @ #, Use \ x00 .. \ xff apart from the main stack, each register is an independent stack. The value at the top of the register stack is called the value of this register sr: the top element w1 of the main stack is displayed. if the r stack is empty, press w1 to the r stack. otherwise, change the top element of the r stack to w1lr. press the value of the r register to the Sr of the master stack. the top element w1 of the master stack is displayed and pushed to the r stack Lr: pop up the r stack top element w1 and press it into the main stack parameters: dc has three parameters: input-in-system output and precision ). Precision is always seen in decimal notation. I: pop up the top w1 of the stack and use it as the input hexadecimal o: pop up the top w1 of the stack and use it as the output hexadecimal k: pop up the top w1 of the stack and use it as the precisionI: input to pressure stack O: output to pressure stack K: precision pressure stack string: The dc Register can store strings, the string can be printed or executed as a dc command [characters]: the string characters is pressed to the stack. Characters can contain any character. except [], it must match a by two. if w1 on the top of the stack is a number, change the top of the stack to (char) (int) (w1) % 256). Otherwise, the first letter of w1 is entered into the stack x: If w1 is a number at the top of the stack, nothing will be done; otherwise, it will pop up and run w1 as a command to the dc for execution> r: in turn, w1 and w2 are displayed. if w1> w2, execute the commands in the r register!> R: w1 and w2 are displayed in sequence. if w1 <= w2, execute the commands in the r register. = W2: execute the commands in the r register = r: w1 and w2 are displayed in sequence. If w1 = w2, execute the commands in the r register! = R: w1 and w2 are displayed in sequence. if w1! = W2 is used to execute the commands in the r register? : Read a command from the standard input and hand it to the dc to execute q: terminate the call of the current dc and the current dc dcQ: The top w1 of the stack is displayed, and the w1 layer dc is terminated. If w1 is greater than the current number of dc layers, an error is reported. Therefore, Q does not cause the master dc to exit from the status query: Z: Top of the stack w1 is displayed, and the w1 length is pressed to the stack X: Top of the stack w1 is displayed, if w1 is a number, press w1 decimal places to the stack; otherwise, press 0 to the stack z: Press the current stack depth to the stack Other :! : Yes! The subsequent part is handed to sh for execution as a command. If the command starts with '> ''=', it must be in! Add a space #: add the part after # as the comment: r: in turn, w1 and w2, r [w1] = w2; r: The top w1 of the stack is displayed, the true essence of r [w1] pressure stack is the process control through x and opr. let's see it again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.