tldr/pages/common/dc.md

25 lines
678 B
Markdown
Raw Normal View History

2017-12-15 17:51:17 +00:00
# dc
> An arbitrary precision calculator. Uses reverse polish notation (RPN).
2021-04-17 16:15:37 +01:00
> More information: <https://www.gnu.org/software/bc/manual/dc-1.05/>.
2017-12-15 17:51:17 +00:00
- Run calculator in interactive mode:
`dc`
2017-12-15 22:12:48 +00:00
- Execute dc script in file:
`dc -f {{file}}`
- Calculate 4 times 5 [4 5 *], subtract 17 [17 -], and [p]rint the output (using echo):
2017-12-15 17:51:17 +00:00
`echo "4 5 * 17 - p"| dc`
2017-12-16 20:18:43 +00:00
- Set number of decimal places to 7 [7 k], calculate 5 divided by -3 [5 _3 /] and [p]rint (using dc -e):
2017-12-15 17:51:17 +00:00
2017-12-15 22:12:48 +00:00
`dc -e "7 k 5 _3 / p"`
2017-12-15 17:51:17 +00:00
2017-12-17 21:47:56 +00:00
- Calculate the golden ratio, phi: Set number of decimal places to 100 [100 k], square root of 5 [5 v] plus 1 [1 +], divided by 2 [2 /], and [p]rint result:
2017-12-15 17:51:17 +00:00
2017-12-15 22:12:48 +00:00
`dc -e "100 k 5 v 1 + 2 / p"`