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