Print this page
11622 clean up rarer mandoc lint warnings
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man1/bc.1
+++ new/usr/src/man/man1/bc.1
1 1 .\"
2 2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 3 .\" permission to reproduce portions of its copyrighted documentation.
4 4 .\" Original documentation from The Open Group can be obtained online at
5 5 .\" http://www.opengroup.org/bookstore/.
6 6 .\"
7 7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 8 .\" Group, have given us permission to reprint portions of their
9 9 .\" documentation.
10 10 .\"
11 11 .\" In the following statement, the phrase ``this text'' refers to portions
12 12 .\" of the system documentation.
13 13 .\"
14 14 .\" Portions of this text are reprinted and reproduced in electronic form
15 15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 16 .\" Standard for Information Technology -- Portable Operating System
17 17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 20 .\" between these versions and the original IEEE and The Open Group
21 21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 22 .\" document. The original Standard can be obtained online at
23 23 .\" http://www.opengroup.org/unix/online.html.
24 24 .\"
25 25 .\" This notice shall appear on any product containing this material.
26 26 .\"
27 27 .\" The contents of this file are subject to the terms of the
28 28 .\" Common Development and Distribution License (the "License").
29 29 .\" You may not use this file except in compliance with the License.
30 30 .\"
31 31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 32 .\" or http://www.opensolaris.org/os/licensing.
33 33 .\" See the License for the specific language governing permissions
34 34 .\" and limitations under the License.
35 35 .\"
36 36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 38 .\" If applicable, add the following below this CDDL HEADER, with the
39 39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
41 41 .\"
42 42 .\"
43 43 .\" Copyright 1989 AT&T
44 44 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
45 45 .\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
46 46 .\"
47 47 .TH BC 1 "Aug 29, 2003"
48 48 .SH NAME
49 49 bc \- arbitrary precision arithmetic language
50 50 .SH SYNOPSIS
51 -.LP
52 51 .nf
53 52 \fB/usr/bin/bc\fR [\fB-c\fR] [\fB-l\fR] [\fIfile\fR]...
54 53 .fi
55 54
56 55 .LP
57 56 .nf
58 57 \fB/usr/xpg6/bin/bc\fR [\fB-c\fR] [\fB-l\fR] [\fIfile\fR]...
59 58 .fi
60 59
61 60 .SH DESCRIPTION
62 -.sp
63 -.LP
64 61 The \fBbc\fR utility implements an arbitrary precision calculator. It takes
65 62 input from any files given, then reads from the standard input. If the standard
66 63 input and standard output to \fBbc\fR are attached to a terminal, the
67 64 invocation of \fBbc\fR is \fIinteractive\fR, causing behavioral constraints
68 65 described in the following sections. \fBbc\fR processes a language that
69 66 resembles C and is a preprocessor for the desk calculator program \fBdc\fR,
70 67 which it invokes automatically unless the \fB-c\fR option is specified. In this
71 68 case the \fBdc\fR input is sent to the standard output instead.
72 69 .SH USAGE
73 -.sp
74 -.LP
75 70 The syntax for \fBbc\fR programs is as follows:
76 71 .sp
77 72 .ne 2
78 73 .na
79 74 \fB\fIL\fR\fR
80 75 .ad
81 76 .RS 5n
82 77 Means a letter \fBa\fR\(mi\fBz\fR,
83 78 .RE
84 79
85 80 .sp
86 81 .ne 2
87 82 .na
88 83 \fB\fIE\fR\fR
89 84 .ad
90 85 .RS 5n
91 86 Means an expression: a (mathematical or logical) value, an operand that takes
92 87 a value, or a combination of operands and operators that evaluates to a value,
93 88 .RE
94 89
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
95 90 .sp
96 91 .ne 2
97 92 .na
98 93 \fB\fIS\fR\fR
99 94 .ad
100 95 .RS 5n
101 96 Means a statement.
102 97 .RE
103 98
104 99 .SS "Comments"
105 -.sp
106 -.LP
107 100 Enclosed in \fB/*\fR and \fB*/\fR.
108 101 .SS "Names (Operands)"
109 -.br
110 102 .in +2
111 103 Simple variables: \fIL\fR.
112 104 .in -2
113 105 .br
114 106 .in +2
115 107 Array elements: \fIL\fR [ \fIE\fR ] (up to \fBBC_DIM_MAX\fR dimensions).
116 108 .in -2
117 109 .br
118 110 .in +2
119 111 The words \fBibase\fR, \fBobase\fR (limited to \fBBC_BASE_MAX\fR), and
120 112 \fBscale\fR (limited to \fBBC_SCALE_MAX\fR).
121 113 .in -2
122 114 .SS "Other Operands"
123 -.sp
124 -.LP
125 115 Arbitrarily long numbers with optional sign and decimal point. Strings of fewer
126 116 than \fBBC_STRING_MAX\fR characters, between double quotes ("). \fB(\fR \fIE\fR
127 117 \fB)\fR
128 118 .sp
129 119 .ne 2
130 120 .na
131 121 \fB\fBsqrt ( \fR\fIE\fR\fB )\fR\fR
132 122 .ad
133 123 .RS 21n
134 124 Square root
135 125 .RE
136 126
137 127 .sp
138 128 .ne 2
139 129 .na
140 130 \fB\fBlength ( \fR\fIE\fR\fB )\fR\fR
141 131 .ad
142 132 .RS 21n
143 133 Number of significant decimal digits.
144 134 .RE
145 135
146 136 .sp
147 137 .ne 2
148 138 .na
149 139 \fB\fBscale ( \fR\fIE\fR\fB )\fR\fR
150 140 .ad
151 141 .RS 21n
152 142 Number of digits right of decimal point.
153 143 .RE
154 144
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
155 145 .sp
156 146 .ne 2
157 147 .na
158 148 \fB\fIL \fR\fB( \fR\fIE\fR , ... , \fIE\fR\fB )\fR\fR
159 149 .ad
160 150 .RS 21n
161 151
162 152 .RE
163 153
164 154 .SS "Operators"
165 -.sp
166 155 .ne 2
167 156 .na
168 157 \fB\fB+ \(mi * / % ^\fR\fR
169 158 .ad
170 159 .sp .6
171 160 .RS 4n
172 161 (\fB%\fR is remainder; \fB^\fR is power)
173 162 .RE
174 163
175 164 .sp
176 165 .ne 2
177 166 .na
178 167 \fB\fB++ \(mi\(mi \fR\fR
179 168 .ad
180 169 .sp .6
181 170 .RS 4n
182 171 (prefix and postfix; apply to names)
183 172 .RE
184 173
185 174 .sp
186 175 .ne 2
187 176 .na
188 177 \fB\fB== <= >= != < >\fR\fR
189 178 .ad
190 179 .sp .6
191 180 .RS 4n
192 181
193 182 .RE
194 183
195 184 .sp
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
196 185 .ne 2
197 186 .na
198 187 \fB\fB= =+ =\(mi =* =/ =% =^\fR\fR
199 188 .ad
200 189 .sp .6
201 190 .RS 4n
202 191
203 192 .RE
204 193
205 194 .SS "Statements"
206 -.br
207 195 .in +2
208 196 \fIE\fR
209 197 .in -2
210 198 .br
211 199 .in +2
212 200 \fB{\fR \fIS\fR \fB;\fR.\|.\|. \fB;\fR \fIS\fR \fB}\fR
213 201 .in -2
214 202 .br
215 203 .in +2
216 204 \fBif (\fR \fIE\fR \fB)\fR \fIS\fR
217 205 .in -2
218 206 .br
219 207 .in +2
220 208 \fBwhile (\fR \fIE\fR \fB)\fR \fIS\fR
221 209 .in -2
222 210 .br
223 211 .in +2
224 212 \fBfor (\fR \fIE\fR \fB;\fR \fIE\fR \fB;\fR \fIE\fR \fB)\fR \fIS\fR
225 213 .in -2
226 214 .br
227 215 .in +2
228 216 null statement
229 217 .in -2
230 218 .br
231 219 .in +2
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
232 220 \fBbreak\fR
233 221 .in -2
234 222 .br
235 223 .in +2
236 224 \fBquit\fR
237 225 .in -2
238 226 .sp
239 227 .LP
240 228 \&.string
241 229 .SS "Function Definitions"
242 -.br
243 230 .in +2
244 231 \fBdefine\fR \fIL\fR \fB(\fR \fIL\fR \fB,\fR.\|.\|.\|\fB,\fR \fIL\fR \fB) {\fR
245 232 .in -2
246 233 .br
247 234 .in +2
248 235 \fBauto\fR \fIL\fR \fB,\fR.\|.\|.\|\fB,\fR \fIL\fR
249 236 .in -2
250 237 .br
251 238 .in +2
252 239 \fIS\fR \fB;\fR.\|.\|.\| \fIS\fR
253 240 .in -2
254 241 .br
255 242 .in +2
256 243 \fBreturn (\fR \fIE\fR \fB)\fR
257 244 .in -2
258 245 .br
259 246 .in +2
260 247 \fB}\fR
261 248 .in -2
262 249 .SS "Functions in \fB-l\fR Math Library"
263 -.sp
264 250 .ne 2
265 251 .na
266 252 \fB\fBs(\fR\fIx\fR\fB)\fR\fR
267 253 .ad
268 254 .RS 10n
269 255 sine
270 256 .RE
271 257
272 258 .sp
273 259 .ne 2
274 260 .na
275 261 \fB\fBc(\fR\fIx\fR\fB)\fR\fR
276 262 .ad
277 263 .RS 10n
278 264 cosine
279 265 .RE
280 266
281 267 .sp
282 268 .ne 2
283 269 .na
284 270 \fB\fBe(\fR\fIx\fR\fB)\fR\fR
285 271 .ad
286 272 .RS 10n
287 273 exponential
288 274 .RE
289 275
290 276 .sp
291 277 .ne 2
292 278 .na
293 279 \fB\fBl(\fR\fIx\fR\fB)\fR\fR
294 280 .ad
295 281 .RS 10n
296 282 log
297 283 .RE
298 284
299 285 .sp
300 286 .ne 2
301 287 .na
302 288 \fB\fBa(\fR\fIx\fR\fB)\fR\fR
303 289 .ad
304 290 .RS 10n
305 291 arctangent
306 292 .RE
307 293
308 294 .sp
309 295 .ne 2
310 296 .na
311 297 \fB\fBj(\fR\fIn\fR\fB,\fR\fIx)\fR\fR
312 298 .ad
313 299 .RS 10n
314 300 Bessel function
315 301 .RE
316 302
317 303 .sp
318 304 .LP
319 305 All function arguments are passed by value.
320 306 .sp
321 307 .LP
322 308 The value of a statement that is an expression is printed unless the main
323 309 operator is an assignment. Either semicolons or new-lines may separate
324 310 statements. Assignment to \fBscale\fR influences the number of digits to be
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
325 311 retained on arithmetic operations in the manner of \fBdc\fR. Assignments to
326 312 \fBibase\fR or \fBobase\fR set the input and output number radix respectively.
327 313 .sp
328 314 .LP
329 315 The same letter may be used as an array, a function, and a simple variable
330 316 simultaneously. All variables are global to the program. \fBauto\fR variables
331 317 are stacked during function calls. When using arrays as function arguments or
332 318 defining them as automatic variables, empty square brackets must follow the
333 319 array name.
334 320 .SH OPTIONS
335 -.sp
336 -.LP
337 321 The following operands are supported:
338 322 .sp
339 323 .ne 2
340 324 .na
341 325 \fB\fB-c\fR\fR
342 326 .ad
343 327 .RS 6n
344 328 Compiles only. The output is \fBdc\fR commands that are sent to the standard
345 329 output.
346 330 .RE
347 331
348 332 .SS "/usr/bin/bc"
349 -.sp
350 333 .ne 2
351 334 .na
352 335 \fB\fB-l\fR\fR
353 336 .ad
354 337 .RS 6n
355 338 Defines the math functions and initializes \fBscale\fR to \fB20\fR, instead of
356 339 the default zero.
357 340 .RE
358 341
359 342 .SS "/usr/xpg6/bin/bc"
360 -.sp
361 343 .ne 2
362 344 .na
363 345 \fB\fB-l\fR\fR
364 346 .ad
365 347 .RS 6n
366 348 Defines the math functions and initializes \fBscale\fR to \fB20\fR, instead of
367 349 the default zero. All math results have the scale of \fB20\fR.
368 350 .RE
369 351
370 352 .SH OPERANDS
371 -.sp
372 -.LP
373 353 The following operands are supported:
374 354 .sp
375 355 .ne 2
376 356 .na
377 357 \fB\fIfile\fR\fR
378 358 .ad
379 359 .RS 8n
380 360 A pathname of a text file containing \fBbc\fR program statements. After all
381 361 cases of \fIfile\fR have been read, \fBbc\fR reads the standard input.
382 362 .RE
383 363
384 364 .SH EXAMPLES
385 -.LP
386 365 \fBExample 1 \fRSetting the precision of a variable
387 366 .sp
388 367 .LP
389 368 In the shell, the following assigns an approximation of the first ten digits of
390 369 \fBn\fR to the variable \fIx\fR:
391 370
392 371 .sp
393 372 .in +2
394 373 .nf
395 374 \fBx=$(printf "%s\en" 'scale = 10; 104348/33215' | bc)\fR
396 375 .fi
397 376 .in -2
398 377 .sp
399 378
400 379 .LP
401 380 \fBExample 2 \fRDefining a computing function
402 381 .sp
403 382 .LP
404 383 Defines a function to compute an approximate value of the exponential function:
405 384
406 385 .sp
407 386 .in +2
408 387 .nf
409 388 \fBscale = 20
410 389 define e(x){
411 390 auto a, b, c, i, s
412 391 a = 1
413 392 b = 1
414 393 s = 1
415 394 for(i=1; 1==1; i++){
416 395 a = a*x
417 396 b = b*i
418 397 c = a/b
419 398 if(c == 0) return(s)
420 399 s = s+c
421 400 }
422 401 }\fR
423 402 .fi
424 403 .in -2
425 404 .sp
426 405
427 406 .LP
428 407 \fBExample 3 \fRPrinting the approximate values of the function
429 408 .sp
430 409 .LP
431 410 Prints approximate values of the exponential function of the first ten
432 411 integers:
433 412
434 413 .sp
435 414 .in +2
436 415 .nf
437 416 \fBfor(i=1; i<=10; i++) e(i)\fR
438 417 .fi
439 418 .in -2
440 419 .sp
441 420
442 421 .sp
443 422 .LP
444 423 or
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
445 424
446 425 .sp
447 426 .in +2
448 427 .nf
449 428 \fBfor (i = 1; i <= 10; ++i) { e(i) }\fR
450 429 .fi
451 430 .in -2
452 431 .sp
453 432
454 433 .SH ENVIRONMENT VARIABLES
455 -.sp
456 -.LP
457 434 See \fBenviron\fR(5) for descriptions of the following environment variables
458 435 that affect the execution of \fBbc\fR: \fBLANG\fR, \fBLC_ALL\fR,
459 436 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
460 437 .SH EXIT STATUS
461 -.sp
462 -.LP
463 438 The following exit values are returned:
464 439 .sp
465 440 .ne 2
466 441 .na
467 442 \fB\fB0\fR\fR
468 443 .ad
469 444 .RS 15n
470 445 All input files were processed successfully.
471 446 .RE
472 447
473 448 .sp
474 449 .ne 2
475 450 .na
476 451 \fB\fBunspecified\fR\fR
477 452 .ad
478 453 .RS 15n
479 454 An error occurred.
480 455 .RE
481 456
482 457 .SH FILES
483 -.sp
484 458 .ne 2
485 459 .na
486 460 \fB\fB/usr/lib/lib.b\fR\fR
487 461 .ad
488 462 .RS 25n
489 463 mathematical library
490 464 .RE
491 465
492 466 .sp
493 467 .ne 2
494 468 .na
495 469 \fB\fB/usr/include/limits.h\fR\fR
496 470 .ad
497 471 .RS 25n
498 472 to define BC_ parameters
499 473 .RE
500 474
501 475 .SH ATTRIBUTES
502 -.sp
503 -.LP
504 476 See \fBattributes\fR(5) for descriptions of the following attributes:
505 477 .sp
506 478
507 479 .sp
508 480 .TS
509 481 box;
510 482 c | c
511 483 l | l .
512 484 ATTRIBUTE TYPE ATTRIBUTE VALUE
513 485 _
514 486 Interface Stability Standard
515 487 .TE
516 488
517 489 .SH SEE ALSO
518 -.sp
519 -.LP
520 490 \fBdc\fR(1), \fBawk\fR(1), \fBattributes\fR(5), \fBenviron\fR(5),
521 491 \fBstandards\fR(5)
522 492 .SH NOTES
523 -.sp
524 -.LP
525 493 The \fBbc\fR command does not recognize the logical operators \fB&&\fR and
526 494 \fB|\||\fR.
527 495 .sp
528 496 .LP
529 497 The \fBfor\fR statement must have all three expressions (\fIE\fR's).
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX