|
|
1.1 root 1: .TH BC 1
2: .SH NAME
3: bc \- arbitrary-precision arithmetic language
4: .SH SYNOPSIS
5: .B bc
6: [
7: .B -c
8: ]
9: [
10: .B -l
11: ]
12: [
13: .I file ...
14: ]
15: .SH DESCRIPTION
16: .I Bc
17: is an interactive processor for a language that resembles
18: C but provides arithmetic on numbers of arbitrary length with up
19: to 100 digits right of the decimal point.
20: It takes input from any files given, then reads
21: the standard input.
22: The
23: .B -l
24: argument stands for the name
25: of an arbitrary precision math library.
26: The following syntax for
27: .I bc
28: programs is like that of C;
29: .I L
30: means letter
31: .BR a - z ,
32: .I E
33: means expression,
34: .I S
35: means statement.
36: .TF length(E)
37: .TP
38: Lexical
39: .RS
40: .HP
41: comments are enclosed in
42: .B /* */
43: .HP
44: newlines end statements
45: .RE
46: .TP
47: Names
48: .IP
49: simple variables:
50: .I L
51: .br
52: array elements:
53: .IB L [ E ]
54: .br
55: The words
56: .BR ibase ,
57: .BR obase ,
58: and
59: .B scale
60: .TP
61: Other operands
62: .IP
63: arbitrarily long numbers with optional sign and decimal point.
64: .RS
65: .TP
66: .BI ( E )
67: .TP
68: .BI sqrt( E )
69: .TP
70: .BI length( E )
71: number of significant decimal digits
72: .TP
73: .BI scale( E )
74: number of digits right of decimal point
75: .TP
76: .IB L ( E , ... ,\fIE\fP)
77: function call
78: .RE
79: .TP
80: Operators
81: .RS
82: .HP
83: .B "+ - * / % ^\ "
84: .RB ( %
85: is remainder;
86: .B ^
87: is power)
88: .HP
89: .B "++ --\ "
90: .TP
91: .B "== <= >= != < >"
92: .TP
93: .B "= += -= *= /= %= ^="
94: .RE
95: .TP
96: Statements
97: .RS
98: .br
99: .I E
100: .br
101: .B {
102: .I S
103: .B ;
104: \&...
105: .B ;
106: .I S
107: .B }
108: .br
109: .B "print"
110: .I E
111: .br
112: .B "if ("
113: .I E
114: .B )
115: .I S
116: .br
117: .B "while ("
118: .I E
119: .B )
120: .I S
121: .br
122: .B "for ("
123: .I E
124: .B ;
125: .I E
126: .B ;
127: .I E
128: .B ")"
129: .I S
130: .br
131: null statement
132: .br
133: .B break
134: .br
135: .B quit
136: .br
137: \fL"\fRtext\fL"\fR
138: .RE
139: .TP
140: Function definitions
141: .RS
142: .br
143: .B define
144: .I L
145: .B (
146: .I L
147: .B ,
148: \&...
149: .B ,
150: .I L
151: .B ){
152: .PD0
153: .br
154: .B auto
155: .I L
156: .B ,
157: \&...
158: .B ,
159: .I L
160: .br
161: .I S
162: .B ;
163: \&...
164: .B ;
165: .I S
166: .br
167: .B return
168: .I E
169: .LP
170: .B }
171: .RE
172: .TP
173: Functions in
174: .B -l
175: math library
176: .RS
177: .TP
178: .BI s( x )
179: sine
180: .TP
181: .BI c( x )
182: cosine
183: .TP
184: .BI e( x )
185: exponential
186: .TP
187: .BI l( x )
188: log
189: .TP
190: .BI a( x )
191: arctangent
192: .TP
193: .BI j( "n, x" )
194: Bessel function
195: .RE
196: .PP
197: .DT
198: All function arguments are passed by value.
199: .PD
200: .PP
201: The value of an expression at the top level is printed
202: unless the main operator is an assignment.
203: Text in quotes, which may include newlines, is also printed.
204: Either semicolons or newlines may separate statements.
205: Assignment to
206: .B scale
207: influences the number of digits to be retained on arithmetic
208: operations in the manner of
209: .IR dc (1).
210: Assignments to
211: .B ibase
212: or
213: .B obase
214: set the input and output number radix respectively.
215: .PP
216: The same letter may be used as an array, a function,
217: and a simple variable simultaneously.
218: All variables are global to the program.
219: Automatic variables are pushed down during function calls.
220: In a declaration of an array as a function argument
221: or automatic variable
222: empty square brackets must follow the array name.
223: .PP
224: .I Bc
225: is actually a preprocessor for
226: .IR dc (1),
227: which it invokes automatically, unless the
228: .B -c
229: (compile only)
230: option is present.
231: In this case the
232: .I dc
233: input is sent to the standard output instead.
234: .SH EXAMPLE
235: Define a function to compute an approximate value of
236: the exponential.
237: Use it to print 10 values.
238: (The exponential function in the library gives better answers.)
239: .PP
240: .EX
241: scale = 20
242: define e(x) {
243: auto a, b, c, i, s
244: a = 1
245: b = 1
246: s = 1
247: for(i=1; 1; i++) {
248: a *= x
249: b *= i
250: c = a/b
251: if(c == 0) return s
252: s += c
253: }
254: }
255: for(i=1; i<=10; i++) print e(i)
256: .EE
257: .SH FILES
258: .B /sys/lib/bclib
259: mathematical library
260: .SH SOURCE
261: .B /sys/src/cmd/bc.y
262: .SH "SEE ALSO"
263: .IR dc (1),
264: .IR hoc (1)
265: .SH BUGS
266: No
267: .LR && ,
268: .LR || ,
269: or
270: .L !
271: operators.
272: .br
273: A
274: .L for
275: statement must have all three
276: .LR E s.
277: .br
278: A
279: .L quit
280: is interpreted when read, not when executed.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.