2015-12-12 20:37:45 +00:00
|
|
|
# bc
|
|
|
|
|
2021-03-31 11:16:18 +01:00
|
|
|
> An arbitrary precision calculator language.
|
2024-07-26 19:53:43 +01:00
|
|
|
> See also: `dc`, `qalc`.
|
2024-06-13 09:30:46 +01:00
|
|
|
> 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:
|
2016-10-31 23:37:05 +00:00
|
|
|
|
2022-01-22 06:00:09 +00:00
|
|
|
`bc`
|
2016-10-31 23:37:05 +00:00
|
|
|
|
2024-07-26 19:53:43 +01:00
|
|
|
- Start an [i]nteractive session with the standard math [l]ibrary enabled:
|
2015-12-12 20:37:45 +00:00
|
|
|
|
2024-07-26 19:53:43 +01: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`
|
2024-07-26 19:53:43 +01:00
|
|
|
|
|
|
|
- Execute an inline factorial script:
|
|
|
|
|
|
|
|
`echo "define factorial(n) { if (n <= 1) return 1; return n*factorial(n-1); }; factorial({{10}})" | bc`
|