Print this page
11622 clean up rarer mandoc lint warnings
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man1/bc.1.man.txt
+++ new/usr/src/man/man1/bc.1.man.txt
1 1 BC(1) User Commands BC(1)
2 2
3 3
4 4
5 5 NAME
6 6 bc - arbitrary precision arithmetic language
7 7
8 8 SYNOPSIS
9 9 /usr/bin/bc [-c] [-l] [file]...
10 10
11 11
12 12 /usr/xpg6/bin/bc [-c] [-l] [file]...
13 13
14 14
15 15 DESCRIPTION
16 16 The bc utility implements an arbitrary precision calculator. It takes
17 17 input from any files given, then reads from the standard input. If the
18 18 standard input and standard output to bc are attached to a terminal,
19 19 the invocation of bc is interactive, causing behavioral constraints
20 20 described in the following sections. bc processes a language that
21 21 resembles C and is a preprocessor for the desk calculator program dc,
22 22 which it invokes automatically unless the -c option is specified. In
23 23 this case the dc input is sent to the standard output instead.
24 24
25 25 USAGE
26 26 The syntax for bc programs is as follows:
27 27
28 28 L
29 29 Means a letter a-z,
30 30
31 31
32 32 E
33 33 Means an expression: a (mathematical or logical) value, an operand
34 34 that takes a value, or a combination of operands and operators
35 35 that evaluates to a value,
36 36
37 37
38 38 S
39 39 Means a statement.
40 40
41 41
42 42 Comments
43 43 Enclosed in /* and */.
44 44
45 45 Names (Operands)
46 46 Simple variables: L.
47 47 Array elements: L [ E ] (up to BC_DIM_MAX dimensions).
48 48 The words ibase, obase (limited to BC_BASE_MAX), and scale (limited
49 49 to BC_SCALE_MAX).
50 50
51 51 Other Operands
52 52 Arbitrarily long numbers with optional sign and decimal point. Strings
53 53 of fewer than BC_STRING_MAX characters, between double quotes ("). ( E
54 54 )
55 55
56 56 sqrt ( E )
57 57 Square root
58 58
59 59
60 60 length ( E )
61 61 Number of significant decimal digits.
62 62
63 63
64 64 scale ( E )
65 65 Number of digits right of decimal point.
66 66
67 67
68 68 L ( E , ... , E )
69 69
70 70
71 71
72 72 Operators
73 73 + - * / % ^
74 74
75 75 (% is remainder; ^ is power)
76 76
77 77
78 78 ++ --
79 79
80 80 (prefix and postfix; apply to names)
81 81
82 82
83 83 == <= >= != < >
84 84
85 85
86 86
87 87
88 88 = =+ =- =* =/ =% =^
89 89
90 90
91 91
92 92
93 93 Statements
94 94 E
95 95 { S ;... ; S }
96 96 if ( E ) S
97 97 while ( E ) S
98 98 for ( E ; E ; E ) S
99 99 null statement
100 100 break
101 101 quit
102 102
103 103
104 104 .string
105 105
106 106 Function Definitions
107 107 define L ( L ,..., L ) {
108 108 auto L ,..., L
109 109 S ;... S
110 110 return ( E )
111 111 }
112 112
113 113 Functions in -l Math Library
114 114 s(x)
115 115 sine
116 116
117 117
118 118 c(x)
119 119 cosine
120 120
121 121
122 122 e(x)
123 123 exponential
124 124
125 125
126 126 l(x)
127 127 log
128 128
129 129
130 130 a(x)
131 131 arctangent
132 132
133 133
134 134 j(n,x)
135 135 Bessel function
136 136
137 137
138 138
139 139 All function arguments are passed by value.
140 140
141 141
142 142 The value of a statement that is an expression is printed unless the
143 143 main operator is an assignment. Either semicolons or new-lines may
144 144 separate statements. Assignment to scale influences the number of
145 145 digits to be retained on arithmetic operations in the manner of dc.
146 146 Assignments to ibase or obase set the input and output number radix
147 147 respectively.
148 148
149 149
150 150 The same letter may be used as an array, a function, and a simple
151 151 variable simultaneously. All variables are global to the program. auto
152 152 variables are stacked during function calls. When using arrays as
153 153 function arguments or defining them as automatic variables, empty
154 154 square brackets must follow the array name.
155 155
156 156 OPTIONS
157 157 The following operands are supported:
158 158
159 159 -c
160 160 Compiles only. The output is dc commands that are sent to the
161 161 standard output.
162 162
163 163
164 164 /usr/bin/bc
165 165 -l
166 166 Defines the math functions and initializes scale to 20, instead
167 167 of the default zero.
168 168
169 169
170 170 /usr/xpg6/bin/bc
171 171 -l
172 172 Defines the math functions and initializes scale to 20, instead
173 173 of the default zero. All math results have the scale of 20.
174 174
175 175
176 176 OPERANDS
177 177 The following operands are supported:
178 178
179 179 file
180 180 A pathname of a text file containing bc program statements.
181 181 After all cases of file have been read, bc reads the standard
182 182 input.
183 183
184 184
185 185 EXAMPLES
186 186 Example 1 Setting the precision of a variable
187 187
188 188
189 189 In the shell, the following assigns an approximation of the first ten
190 190 digits of n to the variable x:
191 191
192 192
193 193 x=$(printf "%s\n" 'scale = 10; 104348/33215' | bc)
194 194
195 195
196 196
197 197 Example 2 Defining a computing function
198 198
199 199
200 200 Defines a function to compute an approximate value of the exponential
201 201 function:
202 202
203 203
204 204 scale = 20
205 205 define e(x){
206 206 auto a, b, c, i, s
207 207 a = 1
208 208 b = 1
209 209 s = 1
210 210 for(i=1; 1==1; i++){
211 211 a = a*x
212 212 b = b*i
213 213 c = a/b
214 214 if(c == 0) return(s)
215 215 s = s+c
216 216 }
217 217 }
218 218
219 219
220 220
221 221 Example 3 Printing the approximate values of the function
222 222
223 223
224 224 Prints approximate values of the exponential function of the first ten
225 225 integers:
226 226
227 227
228 228 for(i=1; i<=10; i++) e(i)
229 229
230 230
231 231
232 232
233 233 or
234 234
235 235
236 236 for (i = 1; i <= 10; ++i) { e(i) }
237 237
238 238
239 239
240 240 ENVIRONMENT VARIABLES
241 241 See environ(5) for descriptions of the following environment variables
242 242 that affect the execution of bc: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
243 243 and NLSPATH.
244 244
245 245 EXIT STATUS
246 246 The following exit values are returned:
247 247
248 248 0
249 249 All input files were processed successfully.
250 250
251 251
252 252 unspecified
253 253 An error occurred.
254 254
255 255
256 256 FILES
257 257 /usr/lib/lib.b
258 258 mathematical library
259 259
260 260
261 261 /usr/include/limits.h
262 262 to define BC_ parameters
263 263
264 264
265 265 ATTRIBUTES
266 266 See attributes(5) for descriptions of the following attributes:
267 267
268 268
269 269
270 270
271 271 +--------------------+-----------------+
272 272 | ATTRIBUTE TYPE | ATTRIBUTE VALUE |
273 273 +--------------------+-----------------+
274 274 |Interface Stability | Standard |
275 275 +--------------------+-----------------+
276 276
277 277 SEE ALSO
278 278 dc(1), awk(1), attributes(5), environ(5), standards(5)
279 279
280 280 NOTES
281 281 The bc command does not recognize the logical operators && and ||.
282 282
283 283
284 284 The for statement must have all three expressions (E's).
285 285
286 286
287 287
288 288 August 29, 2003 BC(1)
↓ open down ↓ |
288 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX