Linux command
dc 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Start interactive
dc
Evaluate expression
echo "[5 3 + p]" | dc
Multiply two numbers
echo "[4 7 * p]" | dc
Calculate with decimal
echo "[10 k 22 7 / p]" | dc
Execute from file
dc [script.dc]
Store and recall
echo "[5 sa la 3 + p]" | dc
Calculate factorial
echo "[5 [d 1 - d 1 <f *] d sf x p]" | dc
说明
dc is an arbitrary precision desk calculator using reverse Polish notation (RPN). Numbers and operators are entered sequentially, with operators acting on values in a stack. It supports arithmetic, comparisons, and programmable macros. Basic operations push numbers onto the stack and apply operators: 5 3 + pushes 5 and 3, then adds them. The p command prints the top of stack. The k command sets decimal precision for division and other operations. dc provides registers (a-z) for storing values, conditional execution, loops through macros, and string manipulation. Despite its terse syntax, it can implement complex algorithms including recursion.
参数
- -e _EXPR_, --expression _EXPR_
- Evaluate expression from command line.
- -f _FILE_, --file _FILE_
- Read commands from file.
- -h, --help
- Display help information.
- -V, --version
- Display version information.
FAQ
What is the dc command used for?
dc is an arbitrary precision desk calculator using reverse Polish notation (RPN). Numbers and operators are entered sequentially, with operators acting on values in a stack. It supports arithmetic, comparisons, and programmable macros. Basic operations push numbers onto the stack and apply operators: 5 3 + pushes 5 and 3, then adds them. The p command prints the top of stack. The k command sets decimal precision for division and other operations. dc provides registers (a-z) for storing values, conditional execution, loops through macros, and string manipulation. Despite its terse syntax, it can implement complex algorithms including recursion.
How do I run a basic dc example?
Run `dc` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -e _EXPR_, --expression _EXPR_ do in dc?
Evaluate expression from command line.