3 058b0118 2005-01-03 devnull bc \- arbitrary-precision arithmetic language
4 058b0118 2005-01-03 devnull .SH SYNOPSIS
16 058b0118 2005-01-03 devnull .I file ...
18 058b0118 2005-01-03 devnull .SH DESCRIPTION
20 058b0118 2005-01-03 devnull is an interactive processor for a language that resembles
21 058b0118 2005-01-03 devnull C but provides arithmetic on numbers of arbitrary length with up
22 058b0118 2005-01-03 devnull to 100 digits right of the decimal point.
23 058b0118 2005-01-03 devnull It takes input from any files given, then reads
24 058b0118 2005-01-03 devnull the standard input.
27 058b0118 2005-01-03 devnull argument stands for the name
28 058b0118 2005-01-03 devnull of an arbitrary precision math library.
31 058b0118 2005-01-03 devnull argument suppresses the automatic display
32 058b0118 2005-01-03 devnull of calculation results; all output is via the
36 058b0118 2005-01-03 devnull The following syntax for
38 058b0118 2005-01-03 devnull programs is like that of C;
40 058b0118 2005-01-03 devnull means letter
41 058b0118 2005-01-03 devnull .BR a - z ,
43 058b0118 2005-01-03 devnull means expression,
45 058b0118 2005-01-03 devnull means statement.
46 058b0118 2005-01-03 devnull .TF length(E)
51 058b0118 2005-01-03 devnull comments are enclosed in
54 058b0118 2005-01-03 devnull newlines end statements
59 058b0118 2005-01-03 devnull simple variables:
62 058b0118 2005-01-03 devnull array elements:
63 058b0118 2005-01-03 devnull .IB L [ E ]
65 058b0118 2005-01-03 devnull The words
66 058b0118 2005-01-03 devnull .BR ibase ,
67 058b0118 2005-01-03 devnull .BR obase ,
71 058b0118 2005-01-03 devnull Other operands
73 058b0118 2005-01-03 devnull arbitrarily long numbers with optional sign and decimal point.
76 058b0118 2005-01-03 devnull .BI ( E )
78 058b0118 2005-01-03 devnull .BI sqrt( E )
80 058b0118 2005-01-03 devnull .BI length( E )
81 058b0118 2005-01-03 devnull number of significant decimal digits
83 058b0118 2005-01-03 devnull .BI scale( E )
84 058b0118 2005-01-03 devnull number of digits right of decimal point
86 058b0118 2005-01-03 devnull .IB L ( E , ... ,\fIE\fP)
87 058b0118 2005-01-03 devnull function call
90 058b0118 2005-01-03 devnull Operators
93 058b0118 2005-01-03 devnull .B "+ - * / % ^\ "
95 058b0118 2005-01-03 devnull is remainder;
97 058b0118 2005-01-03 devnull is power)
99 058b0118 2005-01-03 devnull .B "++ --\ "
101 058b0118 2005-01-03 devnull .B "== <= >= != < >"
103 058b0118 2005-01-03 devnull .B "= += -= *= /= %= ^="
106 058b0118 2005-01-03 devnull Statements
119 058b0118 2005-01-03 devnull .B "print"
122 058b0118 2005-01-03 devnull .B "if ("
127 058b0118 2005-01-03 devnull .B "while ("
132 058b0118 2005-01-03 devnull .B "for ("
141 058b0118 2005-01-03 devnull null statement
143 058b0118 2005-01-03 devnull .B break
147 058b0118 2005-01-03 devnull \fL"\fRtext\fL"\fR
150 058b0118 2005-01-03 devnull Function definitions
153 058b0118 2005-01-03 devnull .B define
177 058b0118 2005-01-03 devnull .B return
183 058b0118 2005-01-03 devnull Functions in
185 058b0118 2005-01-03 devnull math library
188 058b0118 2005-01-03 devnull .BI s( x )
191 058b0118 2005-01-03 devnull .BI c( x )
194 058b0118 2005-01-03 devnull .BI e( x )
195 058b0118 2005-01-03 devnull exponential
197 058b0118 2005-01-03 devnull .BI l( x )
200 058b0118 2005-01-03 devnull .BI a( x )
201 058b0118 2005-01-03 devnull arctangent
203 058b0118 2005-01-03 devnull .BI j( "n, x" )
204 058b0118 2005-01-03 devnull Bessel function
208 058b0118 2005-01-03 devnull All function arguments are passed by value.
211 058b0118 2005-01-03 devnull The value of an expression at the top level is printed
212 058b0118 2005-01-03 devnull unless the main operator is an assignment or the
214 058b0118 2005-01-03 devnull command line argument is given.
215 058b0118 2005-01-03 devnull Text in quotes, which may include newlines, is always printed.
216 058b0118 2005-01-03 devnull Either semicolons or newlines may separate statements.
217 058b0118 2005-01-03 devnull Assignment to
218 058b0118 2005-01-03 devnull .B scale
219 058b0118 2005-01-03 devnull influences the number of digits to be retained on arithmetic
220 058b0118 2005-01-03 devnull operations in the manner of
221 058b0118 2005-01-03 devnull .IR dc (1).
222 058b0118 2005-01-03 devnull Assignments to
223 058b0118 2005-01-03 devnull .B ibase
225 058b0118 2005-01-03 devnull .B obase
226 058b0118 2005-01-03 devnull set the input and output number radix respectively.
228 058b0118 2005-01-03 devnull The same letter may be used as an array, a function,
229 058b0118 2005-01-03 devnull and a simple variable simultaneously.
230 058b0118 2005-01-03 devnull All variables are global to the program.
231 058b0118 2005-01-03 devnull Automatic variables are pushed down during function calls.
232 058b0118 2005-01-03 devnull In a declaration of an array as a function argument
233 058b0118 2005-01-03 devnull or automatic variable
234 058b0118 2005-01-03 devnull empty square brackets must follow the array name.
237 058b0118 2005-01-03 devnull is actually a preprocessor for
238 058b0118 2005-01-03 devnull .IR dc (1),
239 058b0118 2005-01-03 devnull which it invokes automatically, unless the
241 058b0118 2005-01-03 devnull (compile only)
242 058b0118 2005-01-03 devnull option is present.
243 058b0118 2005-01-03 devnull In this case the
245 058b0118 2005-01-03 devnull input is sent to the standard output instead.
246 058b0118 2005-01-03 devnull .SH EXAMPLE
247 058b0118 2005-01-03 devnull Define a function to compute an approximate value of
248 058b0118 2005-01-03 devnull the exponential.
249 058b0118 2005-01-03 devnull Use it to print 10 values.
250 058b0118 2005-01-03 devnull (The exponential function in the library gives better answers.)
253 058b0118 2005-01-03 devnull scale = 20
254 058b0118 2005-01-03 devnull define e(x) {
255 058b0118 2005-01-03 devnull auto a, b, c, i, s
259 058b0118 2005-01-03 devnull for(i=1; 1; i++) {
263 058b0118 2005-01-03 devnull if(c == 0) return s
267 058b0118 2005-01-03 devnull for(i=1; i<=10; i++) print e(i)
269 058b0118 2005-01-03 devnull .SH FILES
270 c8b6342d 2005-01-13 devnull .B \*9/lib/bclib
271 058b0118 2005-01-03 devnull mathematical library
272 058b0118 2005-01-03 devnull .SH SOURCE
273 c3674de4 2005-01-11 devnull .B \*9/src/cmd/bc.y
274 058b0118 2005-01-03 devnull .SH "SEE ALSO"
275 058b0118 2005-01-03 devnull .IR dc (1),
276 058b0118 2005-01-03 devnull .IR hoc (1)
277 058b0118 2005-01-03 devnull .SH BUGS
279 058b0118 2005-01-03 devnull .LR && ,
280 058b0118 2005-01-03 devnull .LR || ,
283 058b0118 2005-01-03 devnull operators.
287 058b0118 2005-01-03 devnull statement must have all three
288 058b0118 2005-01-03 devnull .LR E s.
292 058b0118 2005-01-03 devnull is interpreted when read, not when executed.