bc

man gnu https://www.gnu.org/software/bc/manual/html_mono/bc.html
man posix https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
source (C) https://github.com/fivepiece/gnu-bc/
faq http://phodd.net/gnu-bc/bcfaq.html
tutorial https://org.coloradomesa.edu/~mapierce2/bc/
wiki https://en.wikipedia.org/wiki/Bc_%28programming_language%29

Language

  • Runs interactively (REPL) if you just run it bare "bc"
  • default scale=0, aka integer division
  • in POSIX mode, functions and variables can only be 1 character long
  • undefined variables return 0
  • if/while/for

Functions & Variables

define foo(x) {
  print "this is 2 to the power of "; x*1; 2^x
  print "\n"
}
fn returns
length(n) length in digits of n, including decimals
s(n) sine
random() returns a random positive? integer
read() reads value from stdin, returns value read
print "foo" ala Python 2
last last numer output
scale number of decimals (default 0)
obase "output base" (default 10)
ibase "input base"

Flags

-q –quiet suppreses welcome message
-l –mathlib enables trigonometric functions, sets scale=20

Articles

Videos

Libraries


Created: 2024-04-12

Updated: 2024-11-16

Back