1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-08-04 03:35:41 +02:00

bc, dc: refresh page (#7670)

This commit is contained in:
Emily Grace Seville 2022-01-21 22:00:09 -08:00 committed by GitHub
parent 3e05eed5b0
commit 47445dd786
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 18 deletions

View file

@ -1,20 +1,29 @@
# bc
> An arbitrary precision calculator language.
> More information: <https://manned.org/bc>.
> See also: `dc`.
> More information: <https://manned.org/man/bc.1>.
- Start `bc` in interactive mode using the standard math library:
- Start an interactive session:
`bc -l`
`bc`
- Calculate the result of an expression:
- Start an interactive session with the standard math library enabled:
`bc <<< "(1 + 2) * 2 ^ 2"`
`bc --mathlib`
- Calculate the result of an expression and force the number of decimal places to 10:
- Calculate an expression:
`bc <<< "scale=10; 5 / 3"`
`echo '{{5 / 3}}' | bc`
- Calculate the result of an expression with sine and cosine using `mathlib`:
- Execute a script:
`bc -l <<< "s(1) + c(1)"`
`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`

View file

@ -1,24 +1,29 @@
# dc
> An arbitrary precision calculator. Uses reverse polish notation (RPN).
> See also: `bc`.
> More information: <https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html>.
- Run calculator in interactive mode:
- Start an interactive session:
`dc`
- Execute dc script in file:
- Execute a script:
`dc -f {{file}}`
`dc {{path/to/script.dc}}`
- Calculate 4 times 5 [4 5 *], subtract 17 [17 -], and [p]rint the output (using echo):
- Calculate an expression with the specified scale:
`echo "4 5 * 17 - p"| dc`
`dc --expression='{{10}} k {{5 3 /}} p'`
- Set number of decimal places to 7 [7 k], calculate 5 divided by -3 [5 _3 /] and [p]rint (using dc -e):
- Calculate 4 times 5 (4 5 *), subtract 17 (17 -), and [p]rint the output:
`dc -e "7 k 5 _3 / p"`
`dc --expression='4 5 * 17 - p'`
- 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:
- Set number of decimal places to 7 (7 k), calculate 5 divided by -3 (5 _3 /) and [p]rint:
`dc -e "100 k 5 v 1 + 2 / p"`
`dc --expression='7 k 5 _3 / p'`
- 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:
`dc --expression='100 k 5 v 1 + 2 / p'`

29
pages/osx/bc.md Normal file
View file

@ -0,0 +1,29 @@
# bc
> An arbitrary precision calculator language.
> See also: `dc`.
> More information: <https://manned.org/man/freebsd-13.0/bc.1>.
- Start an interactive session:
`bc`
- Start an interactive session with the standard math library enabled:
`bc --mathlib`
- Calculate an expression:
`bc --expression='{{5 / 3}}'`
- Execute a script:
`bc {{path/to/script.bc}}`
- Calculate an expression with the specified scale:
`bc --expression='scale = {{10}}; {{5 / 3}}'`
- Calculate a sine/cosine/arctangent/natural logarithm/exponential function using `mathlib`:
`bc --mathlib --expression='{{s|c|a|l|e}}({{1}})'`