NAME
bc - arbitrary-precision arithmetic languageSYNOPSIS
bc [ -c ] [ -l ] [ -s ] [ file ... ]DESCRIPTION
Bc is an interactive processor for a language that resembles C but 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. The -l argument stands for the name of an arbitrary precision math library. The -s argument suppresses the automatic display of calculation results; all output is via the print command. The following syntax for bc programs is like that of C; L means letter a-z, E means expression, S means statement.- Lexical
comments are
enclosed in /* */
newlines end
statements
- Names
- simple variables: L
- Other operands
- arbitrarily long numbers with optional sign and decimal point.
- (E)
- sqrt(E)
- length(E)
- number of significant decimal digits
- scale(E)
- number of digits right of decimal point
- L(E,...,E)
- function call
- Operators
+ - * / %
^ (% is remainder; ^ is power)
++
--
- == <= >= != < >
- = += -= *= /= %= ^=
- Statements
- Function definitions
- Functions in
- -l math library
- s(x)
- sine
- c(x)
- cosine
- e(x)
- exponential
- l(x)
- log
- a(x)
- arctangent
- j(n, x)
- Bessel function
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)