bc
- "Basic Calculator"
- started as a frontend of
dc
- 1975-
- Authors:
- Robert Morris
- Lorinda Cherry
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 |
Videos
- Bc: Deep Dive Into The POSIX Calculator Language | Broodie Robertson https://www.youtube.com/watch?v=JascI_29sks
- Linux in the Shell Ep 25 - bc https://vimeo.com/101977655
Libraries
- gcd, fibo https://literateprograms.org/category_programming_language_bc.html
- official examples https://github.com/fivepiece/gnu-bc/tree/master/Examples
- resources http://www.phodd.net/gnu-bc/
- functions https://web.archive.org/web/20160304092132/http://x-bc.sourceforge.net/extensions_bc.html
- functions https://github.com/idealvin/bc
- constants https://web.archive.org/web/20160304081309/http://x-bc.sourceforge.net/scientific_constants_bc.html