bbcc -- Command

Interactive calculator with arbitrary precision
bbcc [ -ll ] [ _f_i_l_e ... ]

bbcc is  a language that  performs calculations on numbers  with an arbitrary
number of  digits.  bbcc is most commonly used  as an interactive calculator,
where the  user types arithmetic expressions in a  syntax reminiscent of C.
If you invoke  bbcc with no _f_i_l_e argument, it  reads the standard input.  For
example:

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

You can  invoke bbcc with  one or more  _f_i_l_e arguments.  After  bbcc reads each
_f_i_l_e, it reads the standard input.   This provides a convenient way to read
programs  that  are  stored  in  files.   COHERENT includes  a  library  of
mathematical functions for bbcc; to use it, invoke bbcc with its option -ll.

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

The  delimiters `/*'  and  `*/' enclose  comments.  Names  of variables  or
functions consist of a lower-case  letter followed by any number of letters
or digits.   (Names cannot begin with an  upper-case letter because numbers
with  a  base  greater than  ten  may  need  upper-case  letters for  their
notation.) The three  built-in variables oobbaassee, iibbaassee, and ssccaallee represent,
respectively,  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).   Variables may be simple
variables or  arrays, and need  not be pre-declared, with  the exception of
variables  internal to  functions.  Some  examples  of variables  and array
elements are xx2255, aarrrraayy[1100], and nnuummbbeerr.

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

Certain names are reserved for use  as key words.  The key words recognized
by bbcc 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

bbrreeaakk, ccoonnttiinnuuee
     Alter control flow within ffoorr and wwhhiillee loops.

qquuiitt Tell bbcc 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 bbcc 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
     _v_a_l_u_e.

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

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

bbcc recognizes the following operators:

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

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 semicolons or newlines, and may
be grouped with braces into compound statements.

bbcc prints  the value of any  statement that is an expression  but is not an
assignment.

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

The library  lliibb.bb holds code written in bbcc  for the following mathematical
variables and functions:

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

If you  invoke bbcc  with its option  -ll, it reads  lliibb.bb and thus  makes the
above functions and constants available to you.

_E_x_a_m_p_l_e_s
The first example calculates the factorial of its positive integer 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);
}

_F_i_l_e_s
/uussrr/lliibb/lliibb.bb -- Source code for the library

_S_e_e _A_l_s_o
ccoommmmaannddss, ccoonnvv, ddcc, mmuullttii-pprreecciissiioonn aarriitthhmmeettiicc
_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

_N_o_t_e_s
Line numbers do not accompany error messages in source files.

bbcc performs integer  calculations with arbitrary precision, limited only by
the memory available.  However, the results of some calculations on numbers
with fractional parts depends on  the specified ssccaallee; see the tutorial for
details.
