don't open target for writing if we're just verifying the tapes
[unix-history] / usr / src / usr.bin / bc / bc.1
CommitLineData
7b4a7cb8 1.\" @(#)bc.1 6.2 (Berkeley) %G%
67aa4194 2.\"
db359672 3.TH BC 1 ""
67aa4194
KM
4.AT 3
5.SH NAME
7b4a7cb8 6bc \- arbitrary-precision arithmetic language and calculator
67aa4194
KM
7.SH SYNOPSIS
8.B bc
9[
10.B \-c
11] [
12.B \-l
13] [ file ... ]
14.SH DESCRIPTION
15.I Bc
16is an interactive processor for a language which resembles
17C but provides unlimited precision arithmetic.
18It takes input from any files given, then reads
19the standard input.
20The
21.B \-l
22argument stands for the name
23of an arbitrary precision math library.
24The syntax for
25.I bc
26programs is as follows;
27L means letter a-z,
28E means expression, S means statement.
29.HP 6
30Comments
31.br
32are enclosed in /* and */.
33.HP 6
34Names
35.br
36simple variables: L
37.br
38array elements: L [ E ]
39.br
40The words `ibase', `obase', and `scale'
41.HP 6
42Other operands
43.br
44arbitrarily long numbers with optional sign and decimal point.
45.br
46( E )
47.br
48sqrt ( E )
49.br
50length ( E ) number of significant decimal digits
51.br
52scale ( E ) number of digits right of decimal point
53.br
54L ( E , ... , E )
55.HP 6
56Operators
57.br
58+ \- * / % ^
59(% is remainder; ^ is power)
60.br
61++ \-\- (prefix and postfix; apply to names)
62.br
63== <= >= != < >
64.br
65= += \-= *= /= %= ^=
66.br
67.HP 6
68Statements
69.br
70E
71.br
72{ S ; ... ; S }
73.br
74if ( E ) S
75.br
76while ( E ) S
77.br
78for ( E ; E ; E ) S
79.br
80null statement
81.br
82break
83.br
84quit
85.HP 6
86Function definitions
87.br
88define L ( L ,..., L ) {
89.br
90 auto L, ... , L
91.br
92 S; ... S
93.br
94 return ( E )
95.br
96}
97.HP 6
98Functions in
99.B \-l
100math library
101.br
102s(x) sine
103.br
104c(x) cosine
105.br
106e(x) exponential
107.br
108l(x) log
109.br
110a(x) arctangent
111.br
112j(n,x) Bessel function
113.PP
114.DT
115All function arguments are passed by value.
116.PP
117The value of a statement that is an expression is printed
118unless the main operator is an assignment.
119Either semicolons or newlines may separate statements.
120Assignment to
121.I scale
122influences the number of digits to be retained on arithmetic
123operations in the manner of
124.IR dc (1).
125Assignments to
126.I ibase
127or
128.I obase
129set the input and output number radix respectively.
130.PP
131The same letter may be used as an array, a function,
132and a simple variable simultaneously.
133All variables are global to the program.
134`Auto' variables are pushed down during function calls.
135When using arrays as function arguments
136or defining them as automatic variables
137empty square brackets must follow the array name.
138.PP
139For example
140.PP
141.nf
142scale = 20
143define e(x){
144 auto a, b, c, i, s
145 a = 1
146 b = 1
147 s = 1
148 for(i=1; 1==1; i++){
149 a = a*x
150 b = b*i
151 c = a/b
152 if(c == 0) return(s)
153 s = s+c
154 }
155}
156.PP
157.fi
158defines a function to compute an approximate value of
159the exponential function and
160.PP
161.nf
162 for(i=1; i<=10; i++) e(i)
163.fi
164.PP
165prints approximate values of the exponential function of
166the first ten integers.
167.PP
168.I Bc
169is actually a preprocessor for
170.IR dc (1),
171which it invokes automatically, unless the
172.B \-c
173(compile only)
174option is present.
175In this case the
176.I dc
177input is sent to the standard output instead.
178.SH FILES
179.ta \w'/usr/lib/lib.b 'u
180/usr/lib/lib.b mathematical library
181.br
182dc(1) desk calculator proper
183.SH "SEE ALSO"
184dc(1)
185.br
186L. L. Cherry and R. Morris,
187.I
188BC \- An arbitrary precision desk-calculator language
189.SH BUGS
190No &&, \(or\|\(or, or ! operators.
191.br
192.I For
193statement must have all three E's.
194.br
195.I Quit
196is interpreted when read, not when executed.