BC(1plan9)
๐ bc โ arbitrary-precision arithmetic language ๐
okay so hi bestie, welcome to the bc page from the Plan 9 manual, section 1 (that's the 1plan9 situation up top in BC(1plan9) โ yes it's the header, we're not copying it, we're vibing with it ๐ซถ). it's giving calculator but make it a whole programming language. no cap.
โจ NAME โจ
bc โ arbitrary-precision arithmetic language. that's it. short. iconic. ate.
๐ธ SYNOPSIS ๐ธ
bc [ -c ] [ -l ] [ -s ] [ file ... ]
๐ซถ DESCRIPTION ๐ซถ
okay so Bc is an interactive processor for a language that resembles C, but the plot twist is that it provides arithmetic on numbers of arbitrary length with up to 100 digits right of the decimal point. ๐
it takes input from any files given, then reads the standard input.
here's the flag situation, bestie:
-lโ stands for the name of an arbitrary precision math library.-sโ suppresses the automatic display of calculation results; all output is via theprintcommand.-cโ compile only, and we'll get to that in a sec (spoiler: it's the preprocessor tea โ).
the following syntax for bc programs is like that of C; L means letter a-z, E means expression, S means statement. literally the alphabet soup of math, and you're the main character.
๐ Lexical
- comments are enclosed in
/* */ - newlines end statements
๐ท๏ธ Names
- simple variables:
L - array elements:
L[E] - The words
ibase,obase, andscale
๐งฎ Other operands
- arbitrarily long numbers with optional sign and decimal point.
(E)sqrt(E)length(E)โ number of significant decimal digitsscale(E)โ number of digits right of decimal pointL(E,...,E)โ function call
โ Operators
+ - * / % ^(that's%is remainder;^is power, no cap)++ --== <= >= != < >= += -= *= /= %= ^=
๐ Statements
E{ S ; ... ; S }print Eif ( E ) Swhile ( E ) Sfor ( E ; E ; E ) S- null statement
breakquit"text"
๐ Function definitions
define L ( L , ... , L ){
auto L , ... , L
S ; ... ; S
return E
}
๐ง Functions in -l math library
s(x)โ sinec(x)โ cosinee(x)โ exponentiall(x)โ loga(x)โ arctangentj(n, x)โ Bessel function
All function arguments are passed by value. periodt. ๐
The value of an expression at the top level is printed unless the main operator is an assignment or the -s command line argument is given. Text in quotes, which may include newlines, is always printed. Either semicolons or newlines may separate statements. Assignment to scale influences the number of digits to be retained on arithmetic operations in the manner of dc(1). Assignments to ibase or obase set the input and output number radix respectively. ๐ฆ
The same letter may be used as an array, a function, and a simple variable simultaneously. All variables are global to the program. Automatic variables are pushed down during function calls. In a declaration of an array as a function argument or automatic variable empty square brackets must follow the array name.
ngl, that "same letter for everything at once" thing is highkey unhinged and I respect it so much.
Bc is actually a preprocessor for dc(1), which it invokes automatically, unless the -c (compile only) option is present. In this case the dc input is sent to the standard output instead.
๐ EXAMPLE ๐
Define a function to compute an approximate value of the exponential. Use it to print 10 values. (The exponential function in the library gives better answers.)
scale = 20
define e(x) {
auto a, b, c, i, s
a = 1
b = 1
s = 1
for(i=1; 1; i++) {
a *= x
b *= i
c = a/b
if(c == 0) return s
s += c
}
}
for(i=1; i<=10; i++) print e(i)
๐ FILES ๐
/lib/bclibโ mathematical library
๐ SOURCE ๐
/src/cmd/bc.y
๐ SEE ALSO ๐
๐ BUGS ๐
bestie. sit down. ๐
- No or operators.
- A statement must have all three
- A is interpreted when read, not when executed.
yeah. "A statement must have all three" and then it just... stops. the manpage said "all three" and left us on read. no further details, we simply do not know what the three are. ๐ iconic behavior honestly.
okay and that's the whole page, fr fr ๐ the footer at the bottom of this manual is just BC(1plan9) all over again โ same source, Plan 9 manual, section 1 โ with no date in sight, because who needs dates when you have arbitrary precision. go forth and compute, you gorgeous genius, you. ๐๐โจ
๐ฆ where this page comes from
- debian bookworm: 9base 1:6-13 ยท Lucent
- debian trixie: 9base 1:6-14 ยท Lucent
- ubuntu jammy: 9base 1:6-11 ยท Lucent
- ubuntu noble: 9base 1:6-14 ยท Lucent
- ubuntu questing: 9base 1:6-15
- ubuntu resolute: 9base 1:6-15build1 ยท Lucent
- ubuntu stonking: 9base 1:6-15build1 ยท Lucent
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms