1BC(1)                       General Commands Manual                      BC(1)
2
3
4

NAME

6       bc - arbitrary-precision arithmetic language
7

SYNOPSIS

9       bc [ -c ] [ -l ] [ file ... ]
10

DESCRIPTION

12       Bc  is  an  interactive  processor for a language which resembles C but
13       provides unlimited precision arithmetic.  It takes input from any files
14       given,  then  reads the standard input.  The -l argument stands for the
15       name of an arbitrary precision math library.  The syntax  for  bc  pro‐
16       grams  is  as  follows; L means letter a-z, E means expression, S means
17       statement.
18
19       Comments
20             are enclosed in /* and */.
21
22       Names
23             simple variables: L
24             array elements: L [ E ]
25             The words `ibase', `obase', and `scale'
26
27       Other operands
28             arbitrarily long numbers with optional sign and decimal point.
29             ( E )
30             sqrt ( E )
31             length ( E )   number of significant decimal digits
32             scale ( E )    number of digits right of decimal point
33             L ( E , ... , E )
34
35       Operators
36             +  -  *  /  %  ^ (% is remainder; ^ is power)
37             ++   --         (prefix and postfix; apply to names)
38             ==  <=  >=  !=  <  >
39             =  +=  -=  *=  /=  %=  ^=
40
41       Statements
42             E
43             { S ; ... ; S }
44             if ( E ) S
45             while ( E ) S
46             for ( E ; E ; E ) S
47             null statement
48             break
49             quit
50
51       Function definitions
52             define L ( L ,..., L ) {
53                  auto L, ... , L
54                  S; ... S
55                  return ( E )
56             }
57
58       Functions in -l math library
59             s(x) sine
60             c(x) cosine
61             e(x) exponential
62             l(x) log
63             a(x) arctangent
64             j(n,x)    Bessel function
65
66       All function arguments are passed by value.
67
68       The value of a statement that is an expression is  printed  unless  the
69       main operator is an assignment.  Either semicolons or newlines may sep‐
70       arate statements.  Assignment to scale influences the number of  digits
71       to  be  retained  on  arithmetic  operations  in  the  manner of dc(1).
72       Assignments to ibase or obase set the input  and  output  number  radix
73       respectively.
74
75       The same letter may be used as an array, a function, and a simple vari‐
76       able simultaneously.  All variables are global to the program.   `Auto'
77       variables  are pushed down during function calls.  When using arrays as
78       function arguments or defining them as automatic variables empty square
79       brackets must follow the array name.
80
81       For example
82
83       scale = 20
84       define e(x){
85            auto a, b, c, i, s
86            a = 1
87            b = 1
88            s = 1
89            for(i=1; 1==1; i++){
90                 a = a*x
91                 b = b*i
92                 c = a/b
93                 if(c == 0) return(s)
94                 s = s+c
95            }
96       }
97
98       defines  a  function to compute an approximate value of the exponential
99       function and
100
101            for(i=1; i<=10; i++) e(i)
102
103       prints approximate values of the exponential function of the first  ten
104       integers.
105
106       Bc  is  actually  a  preprocessor for dc(1), which it invokes automati‐
107       cally, unless the -c (compile only) option is present.   In  this  case
108       the dc input is sent to the standard output instead.
109

FILES

111       /usr/share/misc/lib.b mathematical library
112       dc(1)                 desk calculator proper
113

SEE ALSO

115       dc(1)
116       L. L. Cherry and R. Morris, BC - An arbitrary precision desk-calculator
117       language
118

BUGS

120       No &&, ||, or ! operators.
121       For statement must have all three E's.
122       Quit is interpreted when read, not when executed.
123
124
125
1267th Edition                    October 21, 1996                          BC(1)
Impressum