Difference between revisions of "Bc"
From Christoph's Personal Wiki
(Created page with "'''bc''' is an arbitrary precision calculator language found on most Linux distributions. <code>bc</code> is a language that supports arbitrary precision numbers with interac...") |
(→External links) |
||
Line 38: | Line 38: | ||
==External links== | ==External links== | ||
* [http://phodd.net/gnu-bc/bcfaq.html GNU bc FAQ] | * [http://phodd.net/gnu-bc/bcfaq.html GNU bc FAQ] | ||
+ | * [https://www.wolframalpha.com/input/?i=cube+root+of+74088 Cube root of 74088] — by Wolfram Alpha | ||
[[Category:Linux Command Line Tools]] | [[Category:Linux Command Line Tools]] |
Revision as of 23:41, 10 September 2021
bc is an arbitrary precision calculator language found on most Linux distributions.
bc
is a language that supports arbitrary precision numbers with interactive execution of statements. There are some similarities in the syntax to the C programming language. A standard mathematics library is available by command-line option. If requested, the math library is defined before processing any files. bc
starts by processing code from all the files listed on the command line in the order listed. After all files have been processed, bc
reads from the standard input. All code is executed as it is read. (If a file contains a command to halt the processor, bc
will never read from the standard input.)
Examples
$ echo "111111111 * 111111111" | bc # => 12345678987654321 $ echo "sqrt(25)" | bc -qi # => 5 $ let x=3*4-6; echo $x # => 6 $ echo $[ (10 + 5) / 2] # => 7 $ echo "(10+5)/2" | bc -l # => 7.50000000000000000000
- Convert 10MB to KB from within bash by running the following:
$ expr $((size_in_MB << 10)) $ # E.g., $ expr $((10MB << 10)) # => 10240
- Cube roots:
# NOTE: # n√x = x(1/n) = e(ln x)/n # x^y=e^(y * ln(x)) # ~or~ # echo "e(y*l(x))" | bc -l # echo 'e(l({number})/3)' | bc -l $ echo 'e(l(74088)/3)' | bc -l 41.99999999999999999967 => 42 $ echo 74088 | awk '{ print $1^(1/3) }' 42
See also
External links
- GNU bc FAQ
- Cube root of 74088 — by Wolfram Alpha