File:  [MW Coherent from dump] / coherent / a / usr / man / COHERENT / bc
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



bc                           Command                           bc




Interactive calculator with arbitrary precision

bbcc [ -ll ] [ _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  bbcc 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:

iiff, ffoorr, ddoo, wwhhiillee
     Test conditions and define loops, with syntax identical to C




COHERENT Lexicon                                           Page 1




bc                           Command                           bc



bbrreeaakk, ccoonnttiinnuuee
     Alter control flow within for and while loops.

qquuiitt Tell bc to exit immediately

ddeeffiinnee _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.

aauuttoo _v_a_r, ..., _v_a_r
     Define variables  that are local to  a function, rather than
     having global scope.

rreettuurrnn (_v_a_l_u_e)
     Return a value from a function.

ssccaallee (_v_a_l_u_e)
     Return  the number  of digits  to the  right of  the decimal
     point in value.

ssqqrrtt (_v_a_l_u_e)
     Return the square root of value

lleennggtthh (_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:


     aattaann(_z) Arctangent of _z
     ccooss(_z)  Cosine of _z
     eexxpp(_z)  Exponential function of _z
     jj(_n,_z)  _nth order Bessel function of _z
     llnn(_z)   Natural logarithm of _z
     ppii      Value of pi to 100 digits
     ssiinn(_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 *****

/uussrr/lliibb/lliibb.bb -- 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



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.