tldr/pages/common/bc.md

34 lines
750 B
Markdown
Raw Normal View History

2015-12-12 20:37:45 +00:00
# bc
2021-03-31 11:16:18 +01:00
> An arbitrary precision calculator language.
> See also: `dc`, `qalc`.
> More information: <https://manned.org/bc.1>.
2015-12-12 20:37:45 +00:00
2022-01-22 06:00:09 +00:00
- Start an interactive session:
2022-01-22 06:00:09 +00:00
`bc`
- Start an [i]nteractive session with the standard math [l]ibrary enabled:
2015-12-12 20:37:45 +00:00
`bc --interactive --mathlib`
2015-12-12 20:37:45 +00:00
2022-01-22 06:00:09 +00:00
- Calculate an expression:
2015-12-12 20:37:45 +00:00
2022-01-22 06:00:09 +00:00
`echo '{{5 / 3}}' | bc`
2015-12-12 20:37:45 +00:00
2022-01-22 06:00:09 +00:00
- Execute a script:
2015-12-12 20:37:45 +00:00
2022-01-22 06:00:09 +00:00
`bc {{path/to/script.bc}}`
- Calculate an expression with the specified scale:
`echo 'scale = {{10}}; {{5 / 3}}' | bc`
- Calculate a sine/cosine/arctangent/natural logarithm/exponential function using `mathlib`:
`echo '{{s|c|a|l|e}}({{1}})' | bc --mathlib`
- Execute an inline factorial script:
`echo "define factorial(n) { if (n <= 1) return 1; return n*factorial(n-1); }; factorial({{10}})" | bc`