

bc                           Command                           bc




Interactive calculator with arbitrary precision

bbcc [ -ll ] [ _f_i_l_e ... ]

bc is  a language that  performs calculations on  numbers with an
arbitrary number  of digits.  bc is most commonly  used as an in-
teractive calculator, where the user types arithmetic expressions
in a syntax reminiscent of C.   If bc is invoked with no file ar-
guments on  its command line,  it reads the  standard input.  For
example:


     _I_n_p_u_t        _O_u_t_p_u_t
     bc
     (1000+23)*42 42966
     k = 2^10
     16 * k       16384
     2 ^ 100      1267650600228229401496703205376


bc may also be invoked with one or more file arguments.  After bc
reads each  file, it reads  the standard input.   This provides a
convenient way to access  programs in files.  A library of mathe-
matical functions is available, obtained by using the -l option.

The following  summarizes briefly the facilities  provided by bc.
More information  is available in the tutorial to  bbcc that is in-
cluded with this manual.

Comments  are  enclosed between  the  delimiters  `/*' and  `*/'.
Names of variables or functions must begin with a lower-case let-
ter, and  may have  any number  of subsequent letters  or digits.
Names  may not  begin with an  upper-case letter  because numbers
with a base greater than ten may need need upper-case letters for
their notation.   The three built-in variables  obase, ibase, and
scale represent  the number  base for printing  numbers (default,
ten), the number base for reading numbers (default, ten), and the
number of digits after the decimal (radix) point (default, zero),
respectively.  Variables  may be simple variables  or arrays, and
need not be  pre-declared, with the exception of variables inter-
nal to functions.   Some examples of variables and array elements
are x25, array[10], and number.

Numbers are any string of digits, and may have one decimal point.
Digits are taken from the  ordinary digits (0-9) and then the up-
per-case letters (A-F), in that order.

Certain names  are reserved for use as key  words.  The key words
recognized by bc include the following:

iiff, ffoorr, ddoo, wwhhiillee
     Test conditions and define loops, with syntax identical to C




COHERENT Lexicon                                           Page 1




bc                           Command                           bc



bbrreeaakk, ccoonnttiinnuuee
     Alter control flow within for and while loops.

qquuiitt Tell bc to exit immediately

ddeeffiinnee _f_u_n_c_t_i_o_n (_a_r_g, ..., _a_r_g)
     Define a bc function by a compound statement, as in C.

aauuttoo _v_a_r, ..., _v_a_r
     Define variables  that are local to  a function, rather than
     having global scope.

rreettuurrnn (_v_a_l_u_e)
     Return a value from a function.

ssccaallee (_v_a_l_u_e)
     Return  the number  of digits  to the  right of  the decimal
     point in value.

ssqqrrtt (_v_a_l_u_e)
     Return the square root of value

lleennggtthh (_v_a_l_u_e)
     Return the number of decimal digits in value.

The following operators are recognized:


     +            -* / % ^ ++
     --           =+= -= *= /= %=
     ^=           ==!= < <= > >=


These operators are similar to  those in C, with the exception of
^ and ^=, which are exponentiation operators.  Expressions can be
grouped  with parentheses.  Statements  are separated  with semi-
colons or newlines, and may be made into compound statements with
braces.  bc prints the value  of any statement that is an expres-
sion but is not an assignment.

As in  the editor ed,  an `!' at  the beginning of  a line causes
that line to be sent as a command to the COHERENT shell sh.

The built-in mathematics library contains the following functions
and variables:


     aattaann(_z) Arctangent of _z
     ccooss(_z)  Cosine of _z
     eexxpp(_z)  Exponential function of _z
     jj(_n,_z)  _nth order Bessel function of _z
     llnn(_z)   Natural logarithm of _z
     ppii      Value of pi to 100 digits
     ssiinn(_z)  Sine of _z



COHERENT Lexicon                                           Page 2




bc                           Command                           bc




***** Examples *****

The first  example calculates the  factorial of its  positive in-
teger argument by recursion.


/*
 * Factorial function implemented by recursion.
 */
define fact(n) {
        if (n <= 1) return (n);
        return (n * fact(n-1));
}


The second example  also calculates the factorial of its positive
integer argument, this time by iteration.


/*
 * Factorial function implemented by iteration.
 */
define fact(n) {
        auto result;

        result = 1;
        for (i=1; i<=n; i++) result *= i;
        return (result);
}


***** Files *****

/uussrr/lliibb/lliibb.bb -- Source code for the library

***** See Also *****

commands, conv, dc, multi-precision arithmetic
_b_c _D_e_s_k _C_a_l_c_u_l_a_t_o_r _L_a_n_g_u_a_g_e, tutorial

***** Notes *****

Line numbers do not accompany error messages in source files.













COHERENT Lexicon                                           Page 3


