]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bc/manuals/bc.1
Import new 2-clause BSD licenced implementation of the bc and dc commands
[FreeBSD/FreeBSD.git] / contrib / bc / manuals / bc.1
1 .\" generated with Ronn/v0.7.3
2 .\" http://github.com/rtomayko/ronn/tree/0.7.3
3 .
4 .TH "BC" "1" "June 2020" "Gavin D. Howard" "General Commands Manual"
5 .
6 .SH "NAME"
7 \fBbc\fR \- arbitrary\-precision arithmetic language and calculator
8 .
9 .SH "SYNOPSIS"
10 \fBbc\fR [\fB\-ghilPqsvVw\fR] [\fB\-\-global\-stacks\fR] [\fB\-\-help\fR] [\fB\-\-interactive\fR] [\fB\-\-mathlib\fR] [\fB\-\-no\-prompt\fR] [\fB\-\-quiet\fR] [\fB\-\-standard\fR] [\fB\-\-warn\fR] [\fB\-\-version\fR] [\fB\-e\fR \fIexpr\fR] [\fB\-\-expression=\fR\fIexpr\fR\.\.\.] [\fB\-f\fR \fIfile\fR\.\.\.] [\fB\-file=\fR\fIfile\fR\.\.\.] [\fIfile\fR\.\.\.]
11 .
12 .SH "DESCRIPTION"
13 bc(1) is an interactive processor for a language first standardized in 1991 by POSIX\. (The current standard is here \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR\.) The language provides unlimited precision decimal arithmetic and is somewhat C\-like, but there are differences\. Such differences will be noted in this document\.
14 .
15 .P
16 After parsing and handling options, this bc(1) reads any files given on the command line and executes them before reading from \fBstdin\fR\.
17 .
18 .P
19 With all build options, except for extra math, enabled this bc(1) is a drop\-in replacement for \fB\fIany\fR\fR bc(1), including (and especially) the GNU bc(1)\. It is also a drop\-in replacement for any bc(1) if extra math is enabled, but it will have extra features not found in other bc(1) implementations\.
20 .
21 .SH "OPTIONS"
22 The following are the options that bc(1) accepts\.
23 .
24 .TP
25 \fB\-g\fR, \fB\-\-global\-stacks\fR
26 Turns the globals \fBibase\fR, \fBobase\fR, and \fBscale\fR into stacks\. This includes \fBseed\fR if bc(1) was built with the extra math option\.
27 .
28 .IP
29 This has the effect that a copy of the current value of all three are pushed onto a stack for every function call, as well as popped when every function returns\. This means that functions can assign to any and all of those globals without worrying that the change will affect other functions\. Thus, \fBoutput(x,b)\fR (in the \fIextended library\fR) could have been written like this:
30 .
31 .IP
32 \fBdefine void output(x, b) { obase=b; x }\fR
33 .
34 .IP
35 instead of like this:
36 .
37 .IP
38 \fBdefine void output(x, b) { auto c; c=obase; obase=b; x; obase=c }\fR
39 .
40 .IP
41 This makes writing functions much easier\.
42 .
43 .IP
44 However, since using this flag means that functions cannot set \fBibase\fR, \fBobase\fR, or \fBscale\fR globally, functions that are made to do so cannot work anymore\. There are two possible use cases for that, and each has a solution\.
45 .
46 .IP
47 First, if a function is called on startup to turn bc(1) into a number converter, it is possible to replace that capability with various shell aliases\. Examples:
48 .
49 .IP
50 \fBalias d2o="bc \-e ibase=A \-e obase=8"; alias h2b="bc \-e ibase=G \-e obase=2"\fR
51 .
52 .IP
53 Second, if the purpose of a function is to set \fBibase\fR, \fBobase\fR, or \fBscale\fR globally for any other purpose, it could be split into one to three functions (based on how many globals it sets) and each of those functions could return the desired value for a global\.
54 .
55 .IP
56 For functions that set \fBseed\fR, the value assigned to \fBseed\fR is not propagated to parent functions\. This means that the sequence of pseudo\-random numbers that they see will not be the same sequence of pseudo\-random numbers that any parent sees\. This is only the case once \fBseed\fR has been set\.
57 .
58 .IP
59 If a function desires to not affect the sequence of pseudo\-random numbers of its parents, but wants to use the same \fBseed\fR, it can use the following line:
60 .
61 .IP
62 \fBseed = seed\fR
63 .
64 .IP
65 If the behavior of this option is desired for every run of bc(1), then users could make sure to define \fBBC_ENV_ARGS\fR and include this option (see the ENVIRONMENT VARIABLES section for more details)\.
66 .
67 .IP
68 If \fB\-s\fR, \fB\-w\fR, or any equivalents are used, this option is ignored\.
69 .
70 .IP
71 This is a \fBnon\-portable extension\fR\.
72 .
73 .TP
74 \fB\-h\fR, \fB\-\-help\fR
75 Prints a usage message and quits\.
76 .
77 .TP
78 \fB\-i\fR, \fB\-\-interactive\fR
79 Forces interactive mode\. (See the INTERACTIVE MODE section\.)
80 .
81 .IP
82 This is a \fBnon\-portable extension\fR\.
83 .
84 .TP
85 \fB\-l\fR, \fB\-\-mathlib\fR
86 Sets \fBscale\fR (see the Scale section) to \fB20\fR and loads the included math library before running any code, including any expressions or files specified on the command line\.
87 .
88 .IP
89 To learn what is in the library, see the LIBRARY section\.
90 .
91 .TP
92 \fB\-P\fR, \fB\-\-no\-prompt\fR
93 Disables the prompt in interactive mode\. This is mostly for those users that do not want a prompt or are not used to having them in \fBbc\fR\. Most of those users would want to put this option in \fBBC_ENV_ARGS\fR\.
94 .
95 .IP
96 If the prompt has been disabled while building bc(1), this option is a no\-op\.
97 .
98 .IP
99 This is a \fBnon\-portable extension\fR\.
100 .
101 .TP
102 \fB\-q\fR, \fB\-\-quiet\fR
103 Do not print copyright header\. bc(1) will also suppress the header in non\-interactive mode\.
104 .
105 .IP
106 This is mostly for compatibility with the GNU bc(1) \fIhttps://www\.gnu\.org/software/bc/\fR\.
107 .
108 .IP
109 This is a \fBnon\-portable extension\fR\.
110 .
111 .TP
112 \fB\-s\fR, \fB\-\-standard\fR
113 Process exactly the language defined by the standard \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR and error if any extensions are used\.
114 .
115 .IP
116 This is a \fBnon\-portable extension\fR\.
117 .
118 .TP
119 \fB\-v\fR, \fB\-V\fR, \fB\-\-version\fR
120 Print the version information (copyright header) and exit\.
121 .
122 .IP
123 This is a \fBnon\-portable extension\fR\.
124 .
125 .TP
126 \fB\-w\fR, \fB\-\-warn\fR
127 Like \fB\-s\fR and \fB\-\-standard\fR, except that warnings (and not errors) are given for non\-standard extensions\.
128 .
129 .IP
130 This is a \fBnon\-portable extension\fR\.
131 .
132 .TP
133 \fB\-e\fR \fIexpr\fR, \fB\-\-expression\fR=\fIexpr\fR
134 Evaluates \fBexpr\fR\. If multiple expressions are given, they are evaluated in order\. If files are given as well (see below), the expressions and files are evaluated in the order given\. This means that if a file is given before an expression, the file is read in and evaluated first\.
135 .
136 .IP
137 In other bc(1) implementations, this option causes the program to execute the expressions and then exit\. This bc(1) does not, unless the \fBBC_EXPR_EXIT\fR is defined (see the ENVIRONMENT VARIABLES section)\.
138 .
139 .IP
140 This is a \fBnon\-portable extension\fR\.
141 .
142 .TP
143 \fB\-f\fR \fIfile\fR, \fB\-\-file\fR=\fIfile\fR
144 Reads in \fBfile\fR and evaluates it\. If expressions are also given (see above), the expressions are evaluated in the order given\.
145 .
146 .IP
147 In other bc(1) implementations, this option causes the program to execute the files and then exit\. This bc(1) does not, unless the \fBBC_EXPR_EXIT\fR is defined (see the ENVIRONMENT VARIABLES section)\.
148 .
149 .IP
150 This is a \fBnon\-portable extension\fR\.
151 .
152 .P
153 \fBNote\fR: long options are only accepted if bc(1) is built with them enabled\.
154 .
155 .SH "STDOUT"
156 Any non\-error output is written to \fBstdout\fR\.
157 .
158 .P
159 \fBNote\fR: Unlike other bc(1) implementations, this bc(1) will issue a fatal error (see the EXIT STATUS section) if it cannot write to \fBstdout\fR, so if \fBstdout\fR is closed, as in \fBbc <file> >&\-\fR, it will quit with an error\. This is done so that bc(1) can report problems when \fBstdout\fR is redirected to a file\.
160 .
161 .P
162 If there are scripts that depend on the behavior of other bc(1) implementations, it is recommended that those scripts be changed to redirect \fBstdout\fR to \fB/dev/null\fR\.
163 .
164 .SH "STDERR"
165 Any error output is written to \fBstderr\fR\.
166 .
167 .P
168 \fBNote\fR: Unlike other bc(1) implementations, this bc(1) will issue a fatal error (see the EXIT STATUS section) if it cannot write to \fBstderr\fR, so if \fBstderr\fR is closed, as in \fBbc <file> 2>&\-\fR, it will quit with an error\. This is done so that bc(1) can report problems when \fBstderr\fR is redirected to a file\.
169 .
170 .P
171 If there are scripts that depend on the behavior of other bc(1) implementations, it is recommended that those scripts be changed to redirect \fBstderr\fR to \fB/dev/null\fR\.
172 .
173 .SH "SYNTAX"
174 The syntax for bc(1) programs is mostly C\-like, with some differences\. This bc(1) follows the POSIX standard \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR, which is a much more thorough resource for the language this bc(1) accepts\. This section is meant to be a summary and a listing of all the extensions to the standard \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR\.
175 .
176 .P
177 In the sections below, \fBE\fR means expression, \fBS\fR means statement, and \fBI\fR means identifier\.
178 .
179 .P
180 Identifiers (\fBI\fR) start with a lowercase letter and can be followed by any number (up to \fBBC_NAME_MAX\-1\fR) of lowercase letters (\fBa\-z\fR), digits (\fB0\-9\fR), and underscores (\fB_\fR)\. The regex is \fB[a\-z][a\-z0\-9_]*\fR Identifiers with more than one character (letter) are a \fBnon\-portable extension\fR\.
181 .
182 .P
183 \fBibase\fR is a global variable determining how to interpret constant numbers\. It is the "input" base, or the number base used for interpreting input numbers\. \fBibase\fR is initially \fB10\fR\. If the \fB\-s\fR (\fB\-\-standard\fR) and \fB\-w\fR (\fB\-\-warn\fR) flags were not given on the command line, the max allowable value for \fBibase\fR is \fB36\fR\. Otherwise, it is \fB16\fR\. The min allowable value for \fBibase\fR is \fB2\fR\. The max allowable value for \fBibase\fR can be queried in bc(1) programs with the \fBmaxibase()\fR built in function\.
184 .
185 .P
186 \fBobase\fR is a global variable determining how to output results\. It is the "output" base, or the number base used for outputting numbers\. \fBobase\fR is initially \fB10\fR\. The max allowable value for \fBobase\fR is \fBBC_BASE_MAX\fR\. The min allowable value for \fBobase\fR is \fB2\fR, unless bc(1) was built with the extra math option\. If it was, then the min allowable value is \fB0\fR\. In this case, if \fBobase\fR is \fB0\fR, values are output in scientific notation, and if \fBobase\fR is \fB1\fR, values are output in engineering notation\. (Outputting in scientific or engineering notation are \fBnon\-portable extensions\fR\.) The max allowable value for \fBobase\fR can be queried in bc(1) programs with the \fBmaxobase()\fR built in function\.
187 .
188 .P
189 The \fBscale\fR of an expression is the number of digits in the result of the expression right of the decimal point, and \fBscale\fR is a global variable that sets the precision of any operations, with exceptions\. \fBscale\fR is initially \fB0\fR\. \fBscale\fR cannot be negative\. The max allowable value for \fBscale\fR can be queried in bc(1) programs with the \fBmaxscale()\fR built in function\.
190 .
191 .P
192 bc(1) has both \fBglobal\fR variables and \fBlocal\fR variables\. All \fBlocal\fR variables are local to the function; they are parameters or are introduced in the \fBauto\fR list of a function (see FUNCTIONS)\. If a variable is accessed which is not a parameter or in the \fBauto\fR list, it is assumed to be \fBglobal\fR\. If a parent function has a \fBlocal\fR variable version of a \fBglobal\fR variable that is accessed by a function that it calls, the value of that \fBglobal\fR variable in the child function is the value of the variable in the parent function, not the value of the actual \fBglobal\fR variable\.
193 .
194 .P
195 All of the above applies to arrays as well\.
196 .
197 .P
198 The value of a statement that is an expression (i\.e\., any of the \fINamed Expressions\fR or \fIOperands\fR) is printed unless the lowest precedence operator is an \fI\fBassignment\fR\fR operator \fB\fIand\fR\fR the expression is not surrounded by parentheses\.
199 .
200 .P
201 The value that is printed is also assigned to the special variable \fBlast\fR\. A single dot (\fB\.\fR) may also be used as a synonym for \fBlast\fR\. These are \fBnon\-portable extensions\fR\.
202 .
203 .P
204 Either semicolons or newlines may separate statements\.
205 .
206 .SS "Comments"
207 There are two kinds of comments:
208 .
209 .IP "1." 4
210 Block comments are enclosed in \fB/*\fR and \fB*/\fR\.
211 .
212 .IP "2." 4
213 Line comments go from \fB#\fR until, and not including, the next newline\. This is a \fBnon\-portable extension\fR\.
214 .
215 .IP "" 0
216 .
217 .P
218  \fI\fR
219 .
220 .SS "Named Expressions"
221 The following are named expressions in bc(1):
222 .
223 .IP "1." 4
224 Variables: \fBI\fR
225 .
226 .IP "2." 4
227 Array Elements: \fBI[E]\fR
228 .
229 .IP "3." 4
230 \fBibase\fR
231 .
232 .IP "4." 4
233 \fBobase\fR
234 .
235 .IP "5." 4
236 \fBscale\fR
237 .
238 .IP "6." 4
239 \fBlast\fR or a single dot (\fB\.\fR)
240 .
241 .IP "" 0
242 .
243 .P
244 Number 6 is a \fBnon\-portable extension\fR\.
245 .
246 .P
247 If bc(1) was built with the extra math option, the following is also a named expression:
248 .
249 .IP "1." 4
250 \fBseed\fR
251 .
252 .IP "" 0
253 .
254 .P
255 The meaning of \fBseed\fR is dependent on the current pseudo\-random number generator but is guaranteed to not change except for new major versions\.
256 .
257 .P
258 The \fBscale\fR of the value may be significant\.
259 .
260 .P
261 If a previously used \fBseed\fR value is assigned to \fBseed\fR and used again, the pseudo\-random number generator is guaranteed to produce the same sequence of pseudo\-random numbers as it did when the \fBseed\fR value was previously used\.
262 .
263 .P
264 The exact value assigned to \fBseed\fR is not guaranteed to be returned if \fBseed\fR is queried again immediately\. However, if \fBseed\fR \fIdoes\fR return a different value, both values, when assigned to \fBseed\fR, are guaranteed to produce the same sequence of pseudo\-random numbers\. This means that certain values assigned to \fBseed\fR will not produce unique sequences of pseudo\-random numbers\. The value of \fBseed\fR will change after any use of the \fBrand()\fR and \fBirand(E)\fR operands, except if the parameter passed to \fBirand(E)\fR is \fB0\fR or \fB1\fR\.
265 .
266 .P
267 There is no limit to the length (number of significant decimal digits) or \fIscale\fR of the value that can be assigned to \fBseed\fR\.
268 .
269 .P
270 This command is only available if bc(1) was built with the extra math option\.
271 .
272 .P
273 This is a \fBnon\-portable extension\fR\.
274 .
275 .P
276 Variables and arrays do not interfere; users can have arrays named the same as variables\. This also applies to functions (see the FUNCTIONS section), so a user can have a variable, array, and function that all have the same name, and they will not shadow each other\.
277 .
278 .P
279 Named expressions are required as the operand of \fI\fBincrement\fR/\fBdecrement\fR operators\fR and as the left side of \fI\fBassignment\fR operators\fR\.
280 .
281 .P
282  \fI\fR
283 .
284 .SS "Operands"
285 The following are valid operands in bc(1):
286 .
287 .IP "1." 4
288 Numbers (see \fINumbers\fR below)\.
289 .
290 .IP "2." 4
291 Array indices (\fBI[E]\fR)\.
292 .
293 .IP "3." 4
294 \fB(E)\fR: The value of \fBE\fR (used to change precedence)\.
295 .
296 .IP "4." 4
297 \fBsqrt(E)\fR: The square root of \fBE\fR\. \fBE\fR must be non\-negative\.
298 .
299 .IP "5." 4
300 \fBlength(E)\fR: The number of significant decimal digits in \fBE\fR\.
301 .
302 .IP "6." 4
303 \fBlength(I[])\fR: The number of elements in the array \fBI\fR\. This is a \fBnon\-portable extension\fR\.
304 .
305 .IP "7." 4
306 \fBscale(E)\fR: The \fBscale\fR of \fBE\fR\.
307 .
308 .IP "8." 4
309 \fBabs(E)\fR: The absolute value of \fBE\fR\. This is a \fBnon\-portable extension\fR\.
310 .
311 .IP "9." 4
312 \fBI()\fR, \fBI(E)\fR, \fBI(E, E)\fR, and so on, where \fBI\fR is an identifier for a non\-\fIvoid function\fR\. The \fBE\fR parameters may also be arrays, which will automatically be turned into \fIarray references\fR if the corresponding parameter is an array reference\.
313 .
314 .IP "10." 4
315 \fBread()\fR: Reads a line from \fBstdin\fR and uses that as an expression\. The result of that expression is the result of the \fBread()\fR operand\. This is a \fBnon\-portable extension\fR\.
316 .
317 .IP "11." 4
318 \fBmaxibase()\fR: The max allowable \fBibase\fR\. This is a \fBnon\-portable extension\fR\.
319 .
320 .IP "12." 4
321 \fBmaxobase()\fR: The max allowable \fBobase\fR\. This is a \fBnon\-portable extension\fR\.
322 .
323 .IP "13." 4
324 \fBmaxscale()\fR: The max allowable \fBscale\fR\. This is a \fBnon\-portable extension\fR\.
325 .
326 .IP "" 0
327 .
328 .P
329 If bc(1) was built with the extra math option, the following are also valid operands:
330 .
331 .IP "1." 4
332 \fBrand()\fR: A pseudo\-random integer between \fB0\fR (inclusive) and \fBBC_RAND_MAX\fR (inclusive)\. Using this operand will change the value of \fBseed\fR\. This is a \fBnon\-portable extension\fR\.
333 .
334 .IP "2." 4
335 \fBirand(E)\fR: A pseudo\-random integer between \fB0\fR (inclusive) and the value of \fBE\fR (exclusive)\. If \fBE\fR is negative or is a non\-integer (\fBscale\fR is not \fB0\fR), an error is raised, and bc(1) resets (see the RESET section)\. If \fBE\fR is larger than \fBBC_RAND_MAX\fR, the higher bound is honored by generating several pseudo\-random integers, multiplying them by appropriate powers of \fBBC_RAND_MAX + 1\fR, and adding them together\. Thus, the size of integer that can be generated with this operand is unbounded\. Using this operand will change the value of \fBseed\fR\. If \fBE\fR is \fB0\fR or \fB1\fR, then \fB0\fR is returned, and \fBseed\fR is not changed\. This is a \fBnon\-portable extension\fR\.
336 .
337 .IP "3." 4
338 \fBmaxrand()\fR: The max integer returned by \fBrand()\fR\. This is a \fBnon\-portable extension\fR\.
339 .
340 .IP "" 0
341 .
342 .P
343 The integers generated by \fBrand()\fR and \fBirand(E)\fR are guaranteed to be as unbiased as possible, subject to the limitations of the pseudo\-random number generator\.
344 .
345 .P
346 \fBNote\fR: The values returned by the pseudo\-random number generator with \fBrand()\fR and \fBirand(E)\fR are guaranteed to \fBNOT\fR be cryptographically\-secure\. This is a consequence of using a seeded pseudo\-random number generator\. However, they \fBare\fR guaranteed to be reproducible with identical \fBseed\fR values\.
347 .
348 .P
349  \fI\fR
350 .
351 .SS "Numbers"
352 Numbers are strings made up of digits, uppercase letters, and at most \fB1\fR period for a radix\. Numbers can have up to \fBBC_NUM_MAX\fR digits\. Uppercase letters equal \fB9\fR + their position in the alphabet (i\.e\., \fBA\fR equals \fB10\fR, or \fB9 + 1\fR)\. If a digit or letter makes no sense with the current value of \fBibase\fR, they are set to the value of the highest valid digit in \fBibase\fR\.
353 .
354 .P
355 Single\-character numbers (i\.e\., \fBA\fR) take the value that they would have if they were valid digits, regardless of the value of \fBibase\fR\. This means that \fBA\fR always equals decimal \fB10\fR and \fBZ\fR always equals decimal \fB35\fR\.
356 .
357 .P
358 In addition, if bc(1) was built with the extra math option, it accepts numbers in scientific notation\. For bc(1), an example is \fB1\.89237e9\fR, which is equal to \fB1892370000\fR\. Negative exponents are also allowed, so \fB4\.2890e\-3\fR is equal to \fB0\.0042890\fR\.
359 .
360 .P
361 Using scientific notation is an error or warning if the \fB\-s\fR or \fB\-w\fR, respectively, command\-line options (or equivalents) are given\.
362 .
363 .P
364 \fBWARNING\fR: Both the number and the exponent in scientific notation are interpreted according to the current \fBibase\fR, but the number is still multiplied by \fB10^exponent\fR regardless of the current \fBibase\fR\. For example, if \fBibase\fR is \fB16\fR and bc(1) is given the number string \fB"FFeA"\fR, the resulting decimal number will be \fB2550000000000\fR, and if bc(1) is given the number string \fB"10e\-4"\fR, the resulting decimal number will be \fB0\.0016\fR\.
365 .
366 .P
367 Accepting input as scientific notation is a \fBnon\-portable extension\fR\.
368 .
369 .SS "Operators"
370 The following arithmetic and logical operators can be used\. They are listed in order of decreasing precedence\. Operators in the same group have the same precedence\.
371 .
372 .TP
373 \fB++\fR \fB\-\-\fR
374 Type: Prefix and Postfix
375 .
376 .IP
377 Associativity: None
378 .
379 .IP
380 Description: \fBincrement\fR, \fBdecrement\fR
381 .
382 .TP
383 \fB\-\fR \fB!\fR
384 Type: Prefix
385 .
386 .IP
387 Associativity: None
388 .
389 .IP
390 Description: \fBnegation\fR, \fBboolean not\fR
391 .
392 .TP
393 \fB$\fR
394 Type: Postfix
395 .
396 .IP
397 Associativity: None
398 .
399 .IP
400 Description: \fBtruncation\fR
401 .
402 .TP
403 \fB@\fR
404 Type: Binary
405 .
406 .IP
407 Associativity: Right
408 .
409 .IP
410 Description: \fBset precision\fR
411 .
412 .TP
413 \fB^\fR
414 Type: Binary
415 .
416 .IP
417 Associativity: Right
418 .
419 .IP
420 Description: \fBpower\fR
421 .
422 .TP
423 \fB*\fR \fB/\fR \fB%\fR
424 Type: Binary
425 .
426 .IP
427 Associativity: Left
428 .
429 .IP
430 Description: \fBmultiply\fR, \fBdivide\fR, \fBmodulus\fR
431 .
432 .TP
433 \fB+\fR \fB\-\fR
434 Type: Binary
435 .
436 .IP
437 Associativity: Left
438 .
439 .IP
440 Description: \fBadd\fR, \fBsubtract\fR
441 .
442 .TP
443 \fB<<\fR \fB>>\fR
444 Type: Binary
445 .
446 .IP
447 Associativity: Left
448 .
449 .IP
450 Description: \fBshift left\fR, \fBshift right\fR
451 .
452 .TP
453 \fB=\fR \fB<<=\fR \fB>>=\fR \fB+=\fR \fB\-=\fR \fB*=\fR \fB/=\fR \fB%=\fR \fB^=\fR \fB@=\fR
454 Type: Binary
455 .
456 .IP
457 Associativity: Right
458 .
459 .IP
460 Description: \fBassignment\fR
461 .
462 .TP
463 \fB==\fR \fB<=\fR \fB>=\fR \fB!=\fR \fB<\fR \fB>\fR
464 Type: Binary
465 .
466 .IP
467 Associativity: Left
468 .
469 .IP
470 Description: \fBrelational\fR
471 .
472 .TP
473 \fB&&\fR
474 Type: Binary
475 .
476 .IP
477 Associativity: Left
478 .
479 .IP
480 Description: \fBboolean and\fR
481 .
482 .TP
483 \fB||\fR
484 Type: Binary
485 .
486 .IP
487 Associativity: Left
488 .
489 .IP
490 Description: \fBboolean or\fR
491 .
492 .P
493 The operators will be described in more detail below\.
494 .
495 .P
496  \fI\fR
497 .
498 .TP
499 \fB++\fR \fB\-\-\fR
500 The prefix and postfix \fBincrement\fR and \fBdecrement\fR operators behave exactly like they would in C\. They require a \fInamed expression\fR as an operand\.
501 .
502 .IP
503 The prefix versions of these operators are more efficient; use them where possible\.
504 .
505 .TP
506 \fB\-\fR
507 The \fBnegation\fR operator returns \fB0\fR if a user attempts to negate any expression with the value \fB0\fR\. Otherwise, a copy of the expression with its sign flipped is returned\.
508 .
509 .TP
510 \fB!\fR
511 The \fBboolean not\fR operator returns \fB1\fR if the expression is \fB0\fR, or \fB0\fR otherwise\.
512 .
513 .IP
514 This is a \fBnon\-portable extension\fR\.
515 .
516 .TP
517 \fB$\fR
518 The \fBtruncation\fR operator returns a copy of the given expression with all of its \fBscale\fR removed\.
519 .
520 .IP
521 This is a \fBnon\-portable extension\fR\.
522 .
523 .IP
524 This is only available if bc(1) has been compiled with the extra math option enabled\.
525 .
526 .TP
527 \fB@\fR
528 The \fBset precision\fR operator takes two expressions and returns a copy of the first with its \fBscale\fR equal to the value of the second expression\. That could either mean that the number is returned without change (if the \fBscale\fR of the first expression matches the value of the second expression), extended (if it is less), or truncated (if it is more)\.
529 .
530 .IP
531 The second expression must be an integer (no \fBscale\fR) and non\-negative\.
532 .
533 .IP
534 This is a \fBnon\-portable extension\fR\.
535 .
536 .IP
537 This is only available if bc(1) has been compiled with the extra math option enabled\.
538 .
539 .TP
540 \fB^\fR
541 The \fBpower\fR operator (not the \fBexclusive or\fR operator, as it would be in C) takes two expressions and raises the first to the power of the value of the second\.
542 .
543 .IP
544 The second expression must be an integer (no \fBscale\fR), and if it is negative, the first value must be non\-zero\.
545 .
546 .TP
547 \fB*\fR
548 The \fBmultiply\fR operator takes two expressions, multiplies them, and returns the product\. If \fBa\fR is the \fBscale\fR of the first expression and \fBb\fR is the \fBscale\fR of the second expression, the scale of the result is equal to \fBmin(a+b,max(scale,a,b))\fR where \fBmin\fR and \fBmax\fR return the obvious values\.
549 .
550 .TP
551 \fB/\fR
552 The \fBdivide\fR operator takes two expressions, divides them, and returns the quotient\. The scale of the result shall be the value of \fBscale\fR\.
553 .
554 .IP
555 The second expression must be non\-zero\.
556 .
557 .TP
558 \fB%\fR
559 The \fBmodulus\fR operator takes two expressions, \fBa\fR and \fBb\fR, and evaluates them by 1) Computing \fBa/b\fR to current \fBscale\fR and 2) Using the result of step 1 to calculate \fBa\-(a/b)*b\fR to scale \fBmax(scale+scale(b),scale(a))\fR\.
560 .
561 .IP
562 The second expression must be non\-zero\.
563 .
564 .TP
565 \fB+\fR
566 The \fBadd\fR operator takes two expressions, \fBa\fR and \fBb\fR, and returns the sum, with a \fBscale\fR equal to the max of the \fBscale\fRs of \fBa\fR and \fBb\fR\.
567 .
568 .TP
569 \fB\-\fR
570 The \fBsubtract\fR operator takes two expressions, \fBa\fR and \fBb\fR, and returns the difference, with a \fBscale\fR equal to the max of the \fBscale\fRs of \fBa\fR and \fBb\fR\.
571 .
572 .TP
573 \fB<<\fR
574 The \fBleft shift\fR operator takes two expressions, \fBa\fR and \fBb\fR, and returns a copy of the value of \fBa\fR with its decimal point moved \fBb\fR places to the right\.
575 .
576 .IP
577 The second expression must be an integer (no \fBscale\fR) and non\-negative\.
578 .
579 .IP
580 This is a \fBnon\-portable extension\fR\.
581 .
582 .IP
583 This is only available if bc(1) has been compiled with the extra math option enabled\.
584 .
585 .TP
586 \fB>>\fR
587 The \fBright shift\fR operator takes two expressions, \fBa\fR and \fBb\fR, and returns a copy of the value of \fBa\fR with its decimal point moved \fBb\fR places to the left\.
588 .
589 .IP
590 The second expression must be an integer (no \fBscale\fR) and non\-negative\.
591 .
592 .IP
593 This is a \fBnon\-portable extension\fR\.
594 .
595 .IP
596 This is only available if bc(1) has been compiled with the extra math option enabled\.
597 .
598 .P
599  \fI\fR
600 .
601 .TP
602 \fB=\fR \fB<<=\fR \fB>>=\fR \fB+=\fR \fB\-=\fR \fB*=\fR \fB/=\fR \fB%=\fR \fB^=\fR \fB@=\fR
603 The \fBassignment\fR operators take two expressions, \fBa\fR and \fBb\fR where \fBa\fR is a \fInamed expression\fR\.
604 .
605 .IP
606 For \fB=\fR, \fBb\fR is copied and the result is assigned to \fBa\fR\. For all others, \fBa\fR and \fBb\fR are applied as operands to the corresponding arithmetic operator and the result is assigned to \fBa\fR\.
607 .
608 .IP
609 The \fBassignment\fR operators that correspond to operators that are extensions are themselves extensions\.
610 .
611 .IP
612 Also, those \fBassignment\fR operators that are extensions are only available if bc(1) has been compiled with the extra math option enabled\.
613 .
614 .TP
615 \fB==\fR \fB<=\fR \fB>=\fR \fB!=\fR \fB<\fR \fB>\fR
616 The \fBrelational\fR operators compare two expressions, \fBa\fR and \fBb\fR, and if the relation holds, according to C language semantics, the result is \fB1\fR\. Otherwise, it is \fB0\fR\.
617 .
618 .IP
619 Note that unlike in C, these operators have a lower precedence than the \fBassignment\fR operators, which means that \fBa=b>c\fR is interpreted as \fB(a=b)>c\fR\.
620 .
621 .IP
622 Also, unlike the standard \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR requires, these operators can appear anywhere any other expressions can be used\. This allowance is a \fBnon\-portable extension\fR\.
623 .
624 .TP
625 \fB&&\fR
626 The \fBboolean and\fR operator takes two expressions and returns \fB1\fR if both expressions are non\-zero, \fB0\fR otherwise\.
627 .
628 .IP
629 This is \fB\fInot\fR\fR a short\-circuit operator\.
630 .
631 .IP
632 This is a \fBnon\-portable extension\fR\.
633 .
634 .TP
635 \fB||\fR
636 The \fBboolean or\fR operator takes two expressions and returns \fB1\fR if one of the expressions is non\-zero, \fB0\fR otherwise\.
637 .
638 .IP
639 This is \fB\fInot\fR\fR a short\-circuit operator\.
640 .
641 .IP
642 This is a \fBnon\-portable extension\fR\.
643 .
644 .SS "Statements"
645 The following items are statements:
646 .
647 .IP "1." 4
648 \fBE\fR
649 .
650 .IP "2." 4
651 \fB{\fR \fBS\fR \fB;\fR \.\.\. \fB;\fR \fBS\fR \fB}\fR
652 .
653 .IP "3." 4
654 \fBif\fR \fB(\fR \fBE\fR \fB)\fR \fBS\fR
655 .
656 .IP "4." 4
657 \fBif\fR \fB(\fR \fBE\fR \fB)\fR \fBS\fR \fBelse\fR \fBS\fR
658 .
659 .IP "5." 4
660 \fBwhile\fR \fB(\fR \fBE\fR \fB)\fR \fBS\fR
661 .
662 .IP "6." 4
663 \fBfor\fR \fB(\fR \fBE\fR \fB;\fR \fBE\fR \fB;\fR \fBE\fR \fB)\fR \fBS\fR
664 .
665 .IP "7." 4
666 An empty statement
667 .
668 .IP "8." 4
669 \fBbreak\fR
670 .
671 .IP "9." 4
672 \fBcontinue\fR
673 .
674 .IP "10." 4
675 \fBquit\fR
676 .
677 .IP "11." 4
678 \fBhalt\fR
679 .
680 .IP "12." 4
681 \fBlimits\fR
682 .
683 .IP "13." 4
684 A string of characters, enclosed in double quotes
685 .
686 .IP "14." 4
687 \fBprint\fR \fBE\fR \fB,\fR \.\.\. \fB,\fR \fBE\fR
688 .
689 .IP "15." 4
690 \fBI()\fR, \fBI(E)\fR, \fBI(E, E)\fR, and so on, where \fBI\fR is an identifier for a \fIvoid function\fR\. The \fBE\fR parameters may also be arrays, which will automatically be turned into \fIarray references\fR if the corresponding parameter is an array reference\.
691 .
692 .IP "" 0
693 .
694 .P
695 Numbers 4, 9, 11, 12, 14, and 15 are \fBnon\-portable extensions\fR\.
696 .
697 .P
698 Also, as a \fBnon\-portable extension\fR, any or all of the expressions in the header of a for loop may be omitted\. If the condition (second expression) is omitted, it is assumed to be a constant \fB1\fR\.
699 .
700 .P
701 The \fBbreak\fR statement causes a loop to stop iterating and resume execution immediately following a loop\. This is only allowed in loops\.
702 .
703 .P
704 The \fBcontinue\fR statement causes a loop iteration to stop early and returns to the start of the loop, including testing the loop condition\. This is only allowed in loops\.
705 .
706 .P
707 The \fBif\fR \fBelse\fR statement does the same thing as in C\.
708 .
709 .P
710 The \fBquit\fR statement causes bc(1) to quit, even if it is on a branch that will not be executed (it is a compile\-time command)\.
711 .
712 .P
713 The \fBhalt\fR statement causes bc(1) to quit, if it is executed\. (Unlike \fBquit\fR if it is on a branch of an \fBif\fR statement that is not executed, bc(1) does not quit\.)
714 .
715 .P
716 The \fBlimits\fR statement prints the limits that this bc(1) is subject to\. This is like the \fBquit\fR statement in that it is a compile\-time command\.
717 .
718 .P
719 An expression by itself is evaluated and printed, followed by a newline\. If bc(1) has been built with the extra math option enabled, both scientific notation and engineering notation are available for printing the results of expressions\. Scientific notation is activated by assigning \fB0\fR to \fBobase\fR (in any other context, an \fBobase\fR of \fB0\fR is invalid), and engineering notation is activated by assigning \fB1\fR to \fBobase\fR (which is also invalid in any other context)\. To deactivate them, just assign a different value to \fBobase\fR\.
720 .
721 .P
722 Scientific notation and engineering notation are disabled if bc(1) is run with either the \fB\-s\fR or \fB\-w\fR command\-line options (or equivalents)\.
723 .
724 .P
725 Printing numbers in scientific notation and/or engineering notation is a \fBnon\-portable extension\fR\.
726 .
727 .SS "Print Statement"
728 The "expressions" in a \fBprint\fR statement may also be strings\. If they are, there are backslash escape sequences that are interpreted specially\. What those sequences are, and what they cause to be printed, are shown below:
729 .
730 .TP
731 \fB\ea\fR
732 \fB\ea\fR
733 .
734 .TP
735 \fB\eb\fR
736 \fB\eb\fR
737 .
738 .TP
739 \fB\e\e\fR
740 \fB\e\fR
741 .
742 .TP
743 \fB\ee\fR
744 \fB\e\fR
745 .
746 .TP
747 \fB\ef\fR
748 \fB\ef\fR
749 .
750 .TP
751 \fB\en\fR
752 \fB\en\fR
753 .
754 .TP
755 \fB\eq\fR
756 \fB"\fR
757 .
758 .TP
759 \fB\er\fR
760 \fB\er\fR
761 .
762 .TP
763 \fB\et\fR
764 \fB\et\fR
765 .
766 .P
767 Any other character following a backslash causes the backslash and character to be printed as\-is\.
768 .
769 .P
770 Any non\-string expression in a print statement shall be assigned to \fBlast\fR, like any other expression that is printed\.
771 .
772 .SS "Order of Evaluation"
773 All expressions in a statment are evaluated left to right, except as necessary to maintain order of operations\. This means, for example, that in the expression \fBi = 0; a[i++] = i++\fR, the first (or 0th) element of \fBa\fR is set to \fB1\fR, and \fBi\fR is equal to \fB2\fR at the end of the expression\.
774 .
775 .P
776 This includes function arguments\. Thus, this means that in the expression \fBi = 0; x(i++, i++)\fR, the first argument passed to \fBx()\fR is \fB0\fR, and the second argument is \fB1\fR, while \fBi\fR is equal to \fB2\fR before the function starts executing\.
777 .
778 .SH "FUNCTIONS"
779 Function definitions are as follows:
780 .
781 .IP "" 4
782 .
783 .nf
784
785 define I(I,\.\.\.,I){
786     auto I,\.\.\.,I
787     S;\.\.\.;S
788     return(E)
789 }
790 .
791 .fi
792 .
793 .IP "" 0
794 .
795 .P
796 Any \fBI\fR in the parameter list or \fBauto\fR list may be replaced with \fBI[]\fR to make a parameter or \fBauto\fR var an array, and any \fBI\fR in the parameter list may be replaced with \fB*I[]\fR to make a parameter an array reference\. Callers of functions that take array references should not put an asterisk in the call; they must be called with just \fBI[]\fR like normal array parameters and will be automatically converted into references\.
797 .
798 .P
799 As a \fBnon\-portable extension\fR, the opening brace of a \fBdefine\fR statement may appear on the next line\.
800 .
801 .P
802 The return statement may also be in the following forms:
803 .
804 .IP "1." 4
805 \fBreturn\fR
806 .
807 .IP "2." 4
808 \fBreturn\fR \fB(\fR \fB)\fR
809 .
810 .IP "3." 4
811 \fBreturn\fR \fBE\fR
812 .
813 .IP "" 0
814 .
815 .P
816 The first two, or not specifying a \fBreturn\fR statement, is equivalent to \fBreturn (0)\fR, unless the function is a \fIvoid function\fR\.
817 .
818 .P
819  \fI\fR
820 .
821 .SS "Void Functions"
822 Functions can also be void functions, defined as follows:
823 .
824 .IP "" 4
825 .
826 .nf
827
828 define void I(I,\.\.\.,I){
829     auto I,\.\.\.,I
830     S;\.\.\.;S
831     return
832 }
833 .
834 .fi
835 .
836 .IP "" 0
837 .
838 .P
839 They can only be used as standalone expressions, where such an expression would be printed alone, except in a print statement\.
840 .
841 .P
842 Void functions can only use the first two \fBreturn\fR statements listed above\. They can also omit the return statement entirely\.
843 .
844 .P
845 The word \fBvoid\fR is not treated as a keyword; it is still possible to have variables, arrays, and functions named \fBvoid\fR\. The word \fBvoid\fR is only treated specially right after the \fBdefine\fR keyword\.
846 .
847 .P
848 This is a \fBnon\-portable extension\fR\.
849 .
850 .P
851  \fI\fR
852 .
853 .SS "Array References"
854 For any array in the parameter list, if the array is declared in the form
855 .
856 .IP "" 4
857 .
858 .nf
859
860 *I[]
861 .
862 .fi
863 .
864 .IP "" 0
865 .
866 .P
867 it is a \fBreference\fR\. Any changes to the array in the function are reflected, when the function returns, to the array that was passed in\.
868 .
869 .P
870 Other than this, all function arguments are passed by value\.
871 .
872 .P
873 This is a \fBnon\-portable extension\fR\.
874 .
875 .SH "LIBRARY"
876 All of the functions below, including the functions in the \fIextended library\fR if bc(1) has been compiled with the extra math option enabled, are available when the \fB\-l\fR or \fB\-\-mathlib\fR command\-line flags are given\.
877 .
878 .P
879  \fI\fR
880 .
881 .SS "Standard Library"
882 The standard \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR defines the following functions for the math library:
883 .
884 .TP
885 \fBs(x)\fR
886 Returns the sine of \fBx\fR, which is assumed to be in radians\.
887 .
888 .IP
889 This is a \fItranscendental function\fR\.
890 .
891 .TP
892 \fBc(x)\fR
893 Returns the cosine of \fBx\fR, which is assumed to be in radians\.
894 .
895 .IP
896 This is a \fItranscendental function\fR\.
897 .
898 .TP
899 \fBa(x)\fR
900 Returns the arctangent of \fBx\fR, in radians\.
901 .
902 .IP
903 This is a \fItranscendental function\fR\.
904 .
905 .TP
906 \fBl(x)\fR
907 Returns the natural logarithm of \fBx\fR\.
908 .
909 .IP
910 This is a \fItranscendental function\fR\.
911 .
912 .TP
913 \fBe(x)\fR
914 Returns the mathematical constant \fBe\fR raised to the power of \fBx\fR\.
915 .
916 .IP
917 This is a \fItranscendental function\fR\.
918 .
919 .TP
920 \fBj(x, n)\fR
921 Returns the bessel integer order \fBn\fR (truncated) of \fBx\fR\.
922 .
923 .IP
924 This is a \fItranscendental function\fR\.
925 .
926 .P
927  \fI\fR
928 .
929 .SS "Extended Library"
930 In addition to the \fIstandard library\fR, if bc(1) has been built with the extra math option, the following functions are available when either the \fB\-l\fR or \fB\-\-mathlib\fR options are given\.
931 .
932 .P
933 However, the extended library is \fB\fInot\fR\fR loaded when the \fB\-s\fR/\fB\-\-standard\fR or \fB\-w\fR/\fB\-\-warn\fR options are given since they are not part of the library defined by the standard \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR\.
934 .
935 .P
936 The extended library is a \fBnon\-portable extension\fR\.
937 .
938 .TP
939 \fBp(x, y)\fR
940 Calculates \fBx\fR to the power of \fBy\fR, even if \fBy\fR is not an integer, and returns the result to the current \fBscale\fR\.
941 .
942 .IP
943 This is a \fItranscendental function\fR\.
944 .
945 .TP
946 \fBr(x, p)\fR
947 Returns \fBx\fR rounded to \fBp\fR decimal places according to the rounding mode round half away from \fB0\fR \fIhttps://en\.wikipedia\.org/wiki/Rounding#Round_half_away_from_zero\fR\.
948 .
949 .TP
950 \fBceil(x, p)\fR
951 Returns \fBx\fR rounded to \fBp\fR decimal places according to the rounding mode round away from \fB0\fR \fIhttps://en\.wikipedia\.org/wiki/Rounding#Rounding_away_from_zero\fR\.
952 .
953 .TP
954 \fBf(x)\fR
955 Returns the factorial of the truncated absolute value of \fBx\fR\.
956 .
957 .TP
958 \fBperm(n, k)\fR
959 Returns the permutation of the truncated absolute value of \fBn\fR of the truncated absolute value of \fBk\fR, if \fBk <= n\fR\. If not, it returns \fB0\fR\.
960 .
961 .TP
962 \fBcomb(n, k)\fR
963 Returns the combination of the truncated absolute value of \fBn\fR of the truncated absolute value of \fBk\fR, if \fBk <= n\fR\. If not, it returns \fB0\fR\.
964 .
965 .TP
966 \fBl2(x)\fR
967 Returns the logarithm base \fB2\fR of \fBx\fR\.
968 .
969 .IP
970 This is a \fItranscendental function\fR\.
971 .
972 .TP
973 \fBl10(x)\fR
974 Returns the logarithm base \fB10\fR of \fBx\fR\.
975 .
976 .IP
977 This is a \fItranscendental function\fR\.
978 .
979 .TP
980 \fBlog(x, b)\fR
981 Returns the logarithm base \fBb\fR of \fBx\fR\.
982 .
983 .IP
984 This is a \fItranscendental function\fR\.
985 .
986 .TP
987 \fBcbrt(x)\fR
988 Returns the cube root of \fBx\fR\.
989 .
990 .TP
991 \fBroot(x, n)\fR
992 Calculates the truncated value of \fBn\fR, \fBr\fR, and returns the \fBr\fRth root of \fBx\fR to the current \fBscale\fR\.
993 .
994 .IP
995 If \fBr\fR is \fB0\fR or negative, this raises an error and causes bc(1) to reset (see the RESET section)\. It also raises an error and causes bc(1) to reset if \fBr\fR is even and \fBx\fR is negative\.
996 .
997 .TP
998 \fBpi(p)\fR
999 Returns \fBpi\fR to \fBp\fR decimal places\.
1000 .
1001 .IP
1002 This is a \fItranscendental function\fR\.
1003 .
1004 .TP
1005 \fBt(x)\fR
1006 Returns the tangent of \fBx\fR, which is assumed to be in radians\.
1007 .
1008 .IP
1009 This is a \fItranscendental function\fR\.
1010 .
1011 .TP
1012 \fBa2(y, x)\fR
1013 Returns the arctangent of \fBy/x\fR, in radians\. If both \fBy\fR and \fBx\fR are equal to \fB0\fR, it raises an error and causes bc(1) to reset (see the RESET section)\. Otherwise, if \fBx\fR is greater than \fB0\fR, it returns \fBa(y/x)\fR\. If \fBx\fR is less than \fB0\fR, and \fBy\fR is greater than or equal to \fB0\fR, it returns \fBa(y/x) + pi\fR\. If \fBx\fR is less than \fB0\fR, and \fBy\fR is less than \fB0\fR, it returns \fBa(y/x) \- pi\fR\. If \fBx\fR is equal to \fB0\fR, and \fBy\fR is greater than \fB0\fR, it returns \fBpi/2\fR\. If \fBx\fR is equal to \fB0\fR, and \fBy\fR is less than \fB0\fR, it returns \fB\-pi/2\fR\.
1014 .
1015 .IP
1016 This function is the same as the \fBatan2()\fR function in many programming languages\.
1017 .
1018 .IP
1019 This is a \fItranscendental function\fR\.
1020 .
1021 .TP
1022 \fBsin(x)\fR
1023 Returns the sine of \fBx\fR, which is assumed to be in radians\.
1024 .
1025 .IP
1026 This is an alias of \fBs(x)\fR\.
1027 .
1028 .IP
1029 This is a \fItranscendental function\fR\.
1030 .
1031 .TP
1032 \fBcos(x)\fR
1033 Returns the cosine of \fBx\fR, which is assumed to be in radians\.
1034 .
1035 .IP
1036 This is an alias of \fBc(x)\fR\.
1037 .
1038 .IP
1039 This is a \fItranscendental function\fR\.
1040 .
1041 .TP
1042 \fBtan(x)\fR
1043 Returns the tangent of \fBx\fR, which is assumed to be in radians\.
1044 .
1045 .IP
1046 If \fBx\fR is equal to \fB1\fR or \fB\-1\fR, this raises an error and causes bc(1) to reset (see the RESET section)\.
1047 .
1048 .IP
1049 This is an alias of \fBt(x)\fR\.
1050 .
1051 .IP
1052 This is a \fItranscendental function\fR\.
1053 .
1054 .TP
1055 \fBatan(x)\fR
1056 Returns the arctangent of \fBx\fR, in radians\.
1057 .
1058 .IP
1059 This is an alias of \fBa(x)\fR\.
1060 .
1061 .IP
1062 This is a \fItranscendental function\fR\.
1063 .
1064 .TP
1065 \fBatan2(y, x)\fR
1066 Returns the arctangent of \fBy/x\fR, in radians\. If both \fBy\fR and \fBx\fR are equal to \fB0\fR, it raises an error and causes bc(1) to reset (see the RESET section)\. Otherwise, if \fBx\fR is greater than \fB0\fR, it returns \fBa(y/x)\fR\. If \fBx\fR is less than \fB0\fR, and \fBy\fR is greater than or equal to \fB0\fR, it returns \fBa(y/x) + pi\fR\. If \fBx\fR is less than \fB0\fR, and \fBy\fR is less than \fB0\fR, it returns \fBa(y/x) \- pi\fR\. If \fBx\fR is equal to \fB0\fR, and \fBy\fR is greater than \fB0\fR, it returns \fBpi/2\fR\. If \fBx\fR is equal to \fB0\fR, and \fBy\fR is less than \fB0\fR, it returns \fB\-pi/2\fR\.
1067 .
1068 .IP
1069 This function is the same as the \fBatan2()\fR function in many programming languages\.
1070 .
1071 .IP
1072 This is an alias of \fBa2(y, x)\fR\.
1073 .
1074 .IP
1075 This is a \fItranscendental function\fR\.
1076 .
1077 .TP
1078 \fBr2d(x)\fR
1079 Converts \fBx\fR from radians to degrees and returns the result\.
1080 .
1081 .IP
1082 This is a \fItranscendental function\fR\.
1083 .
1084 .TP
1085 \fBd2r(x)\fR
1086 Converts \fBx\fR from degrees to radians and returns the result\.
1087 .
1088 .IP
1089 This is a \fItranscendental function\fR\.
1090 .
1091 .TP
1092 \fBfrand(p)\fR
1093 Generates a pseudo\-random number between \fB0\fR (inclusive) and \fB1\fR (exclusive) with the number of decimal digits after the decimal point equal to the truncated absolute value of \fBp\fR\. If \fBp\fR is not \fB0\fR, then calling this function will change the value of \fBseed\fR\. If \fBp\fR is \fB0\fR, then \fB0\fR is returned, and \fBseed\fR is not changed\.
1094 .
1095 .TP
1096 \fBifrand(i, p)\fR
1097 Generates a pseudo\-random number that is between \fB0\fR (inclusive) and the truncated absolute value of \fBi\fR (exclusive) with the number of decimal digits after the decimal point equal to the truncated absolute value of \fBp\fR\. If the absolute value of \fBi\fR is greater than or equal to \fB2\fR, and \fBp\fR is not \fB0\fR, then calling this function will change the value of \fBseed\fR, otherwise, \fB0\fR is returned and \fBseed\fR is not changed\.
1098 .
1099 .TP
1100 \fBsrand(x)\fR
1101 Returns \fBx\fR with its sign flipped with probability \fB0\.5\fR\. In other words, it randomizes the sign of \fBx\fR\.
1102 .
1103 .TP
1104 \fBbrand()\fR
1105 Returns a random boolean value (either \fB0\fR or \fB1\fR)\.
1106 .
1107 .TP
1108 \fBubytes(x)\fR
1109 Returns the numbers of unsigned integer bytes required to hold the truncated absolute value of \fBx\fR\.
1110 .
1111 .TP
1112 \fBsbytes(x)\fR
1113 Returns the numbers of signed, two\'s\-complement integer bytes required to hold the truncated value of \fBx\fR\.
1114 .
1115 .TP
1116 \fBhex(x)\fR
1117 Outputs the hexadecimal (base \fB16\fR) representation of \fBx\fR\.
1118 .
1119 .IP
1120 This is a \fIvoid function\fR\.
1121 .
1122 .TP
1123 \fBbinary(x)\fR
1124 Outputs the binary (base \fB2\fR) representation of \fBx\fR\.
1125 .
1126 .IP
1127 This is a \fIvoid function\fR\.
1128 .
1129 .TP
1130 \fBoutput(x, b)\fR
1131 Outputs the base \fBb\fR representation of \fBx\fR\.
1132 .
1133 .IP
1134 This is a \fIvoid function\fR\.
1135 .
1136 .TP
1137 \fBuint(x)\fR
1138 Outputs the representation, in binary and hexadecimal, of \fBx\fR as an unsigned integer in as few power of two bytes as possible\. Both outputs are split into bytes separated by spaces\.
1139 .
1140 .IP
1141 If \fBx\fR is not an integer or is negative, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1142 .
1143 .IP
1144 This is a \fIvoid function\fR\.
1145 .
1146 .TP
1147 \fBint(x)\fR
1148 Outputs the representation, in binary and hexadecimal, of \fBx\fR as a signed, two\'s\-complement integer in as few power of two bytes as possible\. Both outputs are split into bytes separated by spaces\.
1149 .
1150 .IP
1151 If \fBx\fR is not an integer, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1152 .
1153 .IP
1154 This is a \fIvoid function\fR\.
1155 .
1156 .TP
1157 \fBuintn(x, n)\fR
1158 Outputs the representation, in binary and hexadecimal, of \fBx\fR as an unsigned integer in \fBn\fR bytes\. Both outputs are split into bytes separated by spaces\.
1159 .
1160 .IP
1161 If \fBx\fR is not an integer, is negative, or cannot fit into \fBn\fR bytes, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1162 .
1163 .IP
1164 This is a \fIvoid function\fR\.
1165 .
1166 .TP
1167 \fBintn(x, n)\fR
1168 Outputs the representation, in binary and hexadecimal, of \fBx\fR as a signed, two\'s\-complement integer in \fBn\fR bytes\. Both outputs are split into bytes separated by spaces\.
1169 .
1170 .IP
1171 If \fBx\fR is not an integer or cannot fit into \fBn\fR bytes, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1172 .
1173 .IP
1174 This is a \fIvoid function\fR\.
1175 .
1176 .TP
1177 \fBuint8(x)\fR
1178 Outputs the representation, in binary and hexadecimal, of \fBx\fR as an unsigned integer in \fB1\fR byte\. Both outputs are split into bytes separated by spaces\.
1179 .
1180 .IP
1181 If \fBx\fR is not an integer, is negative, or cannot fit into \fB1\fR byte, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1182 .
1183 .IP
1184 This is a \fIvoid function\fR\.
1185 .
1186 .TP
1187 \fBint8(x)\fR
1188 Outputs the representation, in binary and hexadecimal, of \fBx\fR as a signed, two\'s\-complement integer in \fB1\fR byte\. Both outputs are split into bytes separated by spaces\.
1189 .
1190 .IP
1191 If \fBx\fR is not an integer or cannot fit into \fB1\fR byte, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1192 .
1193 .IP
1194 This is a \fIvoid function\fR\.
1195 .
1196 .TP
1197 \fBuint16(x)\fR
1198 Outputs the representation, in binary and hexadecimal, of \fBx\fR as an unsigned integer in \fB2\fR bytes\. Both outputs are split into bytes separated by spaces\.
1199 .
1200 .IP
1201 If \fBx\fR is not an integer, is negative, or cannot fit into \fB2\fR bytes, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1202 .
1203 .IP
1204 This is a \fIvoid function\fR\.
1205 .
1206 .TP
1207 \fBint16(x)\fR
1208 Outputs the representation, in binary and hexadecimal, of \fBx\fR as a signed, two\'s\-complement integer in \fB2\fR bytes\. Both outputs are split into bytes separated by spaces\.
1209 .
1210 .IP
1211 If \fBx\fR is not an integer or cannot fit into \fB2\fR bytes, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1212 .
1213 .IP
1214 This is a \fIvoid function\fR\.
1215 .
1216 .TP
1217 \fBuint32(x)\fR
1218 Outputs the representation, in binary and hexadecimal, of \fBx\fR as an unsigned integer in \fB4\fR bytes\. Both outputs are split into bytes separated by spaces\.
1219 .
1220 .IP
1221 If \fBx\fR is not an integer, is negative, or cannot fit into \fB4\fR bytes, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1222 .
1223 .IP
1224 This is a \fIvoid function\fR\.
1225 .
1226 .TP
1227 \fBint32(x)\fR
1228 Outputs the representation, in binary and hexadecimal, of \fBx\fR as a signed, two\'s\-complement integer in \fB4\fR bytes\. Both outputs are split into bytes separated by spaces\.
1229 .
1230 .IP
1231 If \fBx\fR is not an integer or cannot fit into \fB4\fR bytes, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1232 .
1233 .IP
1234 This is a \fIvoid function\fR\.
1235 .
1236 .TP
1237 \fBuint64(x)\fR
1238 Outputs the representation, in binary and hexadecimal, of \fBx\fR as an unsigned integer in \fB8\fR bytes\. Both outputs are split into bytes separated by spaces\.
1239 .
1240 .IP
1241 If \fBx\fR is not an integer, is negative, or cannot fit into \fB8\fR bytes, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1242 .
1243 .IP
1244 This is a \fIvoid function\fR\.
1245 .
1246 .TP
1247 \fBint64(x)\fR
1248 Outputs the representation, in binary and hexadecimal, of \fBx\fR as a signed, two\'s\-complement integer in \fB8\fR bytes\. Both outputs are split into bytes separated by spaces\.
1249 .
1250 .IP
1251 If \fBx\fR is not an integer or cannot fit into \fB8\fR bytes, an error message is printed instead, but bc(1) is not reset (see the RESET section)\.
1252 .
1253 .IP
1254 This is a \fIvoid function\fR\.
1255 .
1256 .TP
1257 \fBhex_uint(x, n)\fR
1258 Outputs the representation of the truncated absolute value of \fBx\fR as an unsigned integer in hexadecimal using \fBn\fR bytes\. Not all of the value will be output if \fBn\fR is too small\.
1259 .
1260 .IP
1261 This is a \fIvoid function\fR\.
1262 .
1263 .TP
1264 \fBbinary_uint(x, n)\fR
1265 Outputs the representation of the truncated absolute value of \fBx\fR as an unsigned integer in binary using \fBn\fR bytes\. Not all of the value will be output if \fBn\fR is too small\.
1266 .
1267 .IP
1268 This is a \fIvoid function\fR\.
1269 .
1270 .TP
1271 \fBoutput_uint(x, n)\fR
1272 Outputs the representation of the truncated absolute value of \fBx\fR as an unsigned integer in the current \fI\fBobase\fR\fR using \fBn\fR bytes\. Not all of the value will be output if \fBn\fR is too small\.
1273 .
1274 .IP
1275 This is a \fIvoid function\fR\.
1276 .
1277 .TP
1278 \fBoutput_byte(x, i)\fR
1279 Outputs byte \fBi\fR of the truncated absolute value of \fBx\fR, where \fB0\fR is the least significant byte and \fBnumber_of_bytes \- 1\fR is the most significant byte\.
1280 .
1281 .IP
1282 This is a \fIvoid function\fR\.
1283 .
1284 .P
1285  \fI\fR
1286 .
1287 .SS "Transcendental Functions"
1288 All transcendental functions can return slightly inaccurate results (up to 1 ULP \fIhttps://en\.wikipedia\.org/wiki/Unit_in_the_last_place\fR)\. This is unavoidable, and this article \fIhttps://people\.eecs\.berkeley\.edu/~wkahan/LOG10HAF\.TXT\fR explains why it is impossible and unnecessary to calculate exact results for the transcendental functions\.
1289 .
1290 .P
1291 Because of the possible inaccuracy, I recommend that users call those functions with the precision (\fBscale\fR) set to at least 1 higher than is necessary\. If exact results are \fIabsolutely\fR required, users can double the precision (\fBscale\fR) and then truncate\.
1292 .
1293 .P
1294 The transcendental functions in the standard math library are:
1295 .
1296 .IP "\(bu" 4
1297 \fBs(x)\fR
1298 .
1299 .IP "\(bu" 4
1300 \fBc(x)\fR
1301 .
1302 .IP "\(bu" 4
1303 \fBa(x)\fR
1304 .
1305 .IP "\(bu" 4
1306 \fBl(x)\fR
1307 .
1308 .IP "\(bu" 4
1309 \fBe(x)\fR
1310 .
1311 .IP "\(bu" 4
1312 \fBj(x, n)\fR
1313 .
1314 .IP "" 0
1315 .
1316 .P
1317 The transcendental functions in the extended math library are:
1318 .
1319 .IP "\(bu" 4
1320 \fBl2(x)\fR
1321 .
1322 .IP "\(bu" 4
1323 \fBl10(x)\fR
1324 .
1325 .IP "\(bu" 4
1326 \fBlog(x, b)\fR
1327 .
1328 .IP "\(bu" 4
1329 \fBpi(p)\fR
1330 .
1331 .IP "\(bu" 4
1332 \fBt(x)\fR
1333 .
1334 .IP "\(bu" 4
1335 \fBa2(y, x)\fR
1336 .
1337 .IP "\(bu" 4
1338 \fBsin(x)\fR
1339 .
1340 .IP "\(bu" 4
1341 \fBcos(x)\fR
1342 .
1343 .IP "\(bu" 4
1344 \fBtan(x)\fR
1345 .
1346 .IP "\(bu" 4
1347 \fBatan(x)\fR
1348 .
1349 .IP "\(bu" 4
1350 \fBatan2(y, x)\fR
1351 .
1352 .IP "\(bu" 4
1353 \fBr2d(x)\fR
1354 .
1355 .IP "\(bu" 4
1356 \fBd2r(x)\fR
1357 .
1358 .IP "" 0
1359 .
1360 .SH "RESET"
1361 When bc(1) encounters an error or a signal that it has a non\-default handler for, it resets\. This means that several things happen\.
1362 .
1363 .P
1364 First, any functions that are executing are stopped and popped off the stack\. The behavior is not unlike that of exceptions in programming languages\. Then the execution point is set so that any code waiting to execute (after all functions returned) is skipped\.
1365 .
1366 .P
1367 Thus, when bc(1) resets, it skips any remaining code waiting to be executed\. Then, if it is interactive mode, and the error was not a fatal error (see the EXIT STATUS section), it asks for more input; otherwise, it exits with the appropriate return code\.
1368 .
1369 .P
1370 Note that this reset behavior is different from the GNU bc(1), which attempts to start executing the statement right after the one that caused an error\.
1371 .
1372 .SH "PERFORMANCE"
1373 Most bc(1) implementations use \fBchar\fR types to calculate the value of \fB1\fR decimal digit at a time, but that can be slow\. This bc(1) does something different\.
1374 .
1375 .P
1376 It uses large integers to calculate more than \fB1\fR decimal digit at a time\. If built in a environment where \fBBC_LONG_BIT\fR (see the LIMITS section) is \fB64\fR, then each integer has \fB9\fR decimal digits\. If built in an environment where \fBBC_LONG_BIT\fR is \fB32\fR then each integer has \fB4\fR decimal digits\. This value (the number of decimal digits per large integer) is called \fBBC_BASE_DIGS\fR\.
1377 .
1378 .P
1379 In addition, this bc(1) uses an even larger integer for overflow checking\. This integer type depends on the value of \fBBC_LONG_BIT\fR, but is always at least twice as large as the integer type used to store digits\.
1380 .
1381 .SH "LIMITS"
1382 The following are the limits on bc(1):
1383 .
1384 .TP
1385 \fBBC_LONG_BIT\fR
1386 The number of bits in the \fBlong\fR type in the environment where bc(1) was built\. This determines how many decimal digits can be stored in a single large integer (see the PERFORMANCE section)\.
1387 .
1388 .TP
1389 \fBBC_BASE_DIGS\fR
1390 The number of decimal digits per large integer (see the PERFORMANCE section)\. Depends on \fBBC_LONG_BIT\fR\.
1391 .
1392 .TP
1393 \fBBC_BASE_POW\fR
1394 The max decimal number that each large integer can store (see \fBBC_BASE_DIGS\fR) plus \fB1\fR\. Depends on \fBBC_BASE_DIGS\fR\.
1395 .
1396 .TP
1397 \fBBC_OVERFLOW_MAX\fR
1398 The max number that the overflow type (see the PERFORMANCE section) can hold\. Depends on \fBBC_LONG_BIT\fR\.
1399 .
1400 .TP
1401 \fBBC_BASE_MAX\fR
1402 The maximum output base\. Set at \fBBC_BASE_POW\fR\.
1403 .
1404 .TP
1405 \fBBC_DIM_MAX\fR
1406 The maximum size of arrays\. Set at \fBSIZE_MAX\-1\fR\.
1407 .
1408 .TP
1409 \fBBC_SCALE_MAX\fR
1410 The maximum \fBscale\fR\. Set at \fBBC_OVERFLOW_MAX\-1\fR\.
1411 .
1412 .TP
1413 \fBBC_STRING_MAX\fR
1414 The maximum length of strings\. Set at \fBBC_OVERFLOW_MAX\-1\fR\.
1415 .
1416 .TP
1417 \fBBC_NAME_MAX\fR
1418 The maximum length of identifiers\. Set at \fBBC_OVERFLOW_MAX\-1\fR\.
1419 .
1420 .TP
1421 \fBBC_NUM_MAX\fR
1422 The maximum length of a number (in decimal digits), which includes digits after the decimal point\. Set at \fBBC_OVERFLOW_MAX\-1\fR\.
1423 .
1424 .TP
1425 \fBBC_RAND_MAX\fR
1426 The maximum integer (inclusive) returned by the \fBrand()\fR operand, if bc(1) has been built with the extra math option\. Set at \fB2^BC_LONG_BIT\-1\fR\.
1427 .
1428 .TP
1429 Exponent
1430 The maximum allowable exponent (positive or negative)\. Set at \fBBC_OVERFLOW_MAX\fR\.
1431 .
1432 .TP
1433 Number of vars
1434 The maximum number of vars/arrays\. Set at \fBSIZE_MAX\-1\fR\.
1435 .
1436 .P
1437 Actual values can be queried with the \fBlimits\fR statement\.
1438 .
1439 .P
1440 These limits are meant to be effectively non\-existent; the limits are so large (at least on 64\-bit machines) that there should not be any point at which they become a problem\. In fact, memory should be exhausted before these limits should be hit\.
1441 .
1442 .SH "ENVIRONMENT VARIABLES"
1443 bc(1) recognizes the following environment variables:
1444 .
1445 .TP
1446 \fBPOSIXLY_CORRECT\fR
1447 If this variable exists (no matter the contents), bc(1) behaves as if the \fB\-s\fR option was given\.
1448 .
1449 .TP
1450 \fBBC_ENV_ARGS\fR
1451 This is another way to give command\-line arguments to bc(1)\. They should be in the same format as all other command\-line arguments\. These are always processed first, so any files given in \fBBC_ENV_ARGS\fR will be processed before arguments and files given on the command\-line\. This gives the user the ability to set up "standard" options and files to be used at every invocation\. The most useful thing for such files to contain would be useful functions that the user might want every time bc(1) runs\.
1452 .
1453 .IP
1454 The code that parses \fBBC_ENV_ARGS\fR will correctly handle quoted arguments, but it does not understand escape sequences\. For example, the string \fB"/home/gavin/some bc file\.bc"\fR will be correctly parsed, but the string \fB"/home/gavin/some \e"bc\e" file\.bc"\fR will include the backslashes\.
1455 .
1456 .IP
1457 The quote parsing will handle either kind of quotes, \fB'\fR or \fB"\fR\. Thus, if you have a file with any number of single quotes in the name, you can use double quotes as the outside quotes, as in \fB"some \'bc\' file\.bc"\fR, and vice versa if you have a file with double quotes\. However, handling a file with both kinds of quotes in \fBBC_ENV_ARGS\fR is not supported due to the complexity of the parsing, though such files are still supported on the command\-line where the parsing is done by the shell\.
1458 .
1459 .TP
1460 \fBBC_LINE_LENGTH\fR
1461 If this environment variable exists and contains an integer that is greater than \fB1\fR and is less than \fBUINT16_MAX\fR (\fB2^16\-1\fR), bc(1) will output lines to that length, including the backslash (\fB\e\fR)\. The default line length is \fB70\fR\.
1462 .
1463 .TP
1464 \fBBC_EXPR_EXIT\fR
1465 If this variable exists (no matter the contents), bc(1) will exit immediately after executing expressions and files given by the \fB\-e\fR and/or \fB\-f\fR command\-line options (and any equivalents)\.
1466 .
1467 .SH "EXIT STATUS"
1468 bc(1) returns the following exit statuses:
1469 .
1470 .TP
1471 \fB0\fR
1472 No error\.
1473 .
1474 .TP
1475 \fB1\fR
1476 A math error occurred\. This follows standard practice of using \fB1\fR for expected errors, since math errors will happen in the process of normal execution\.
1477 .
1478 .IP
1479 Math errors include divide by \fB0\fR, taking the square root of a negative number, using a negative number as a bound for the pseudo\-random number generator, attempting to convert a negative number to a hardware integer, overflow when converting a number to a hardware integer, and attempting to use a non\-integer where an integer is required\.
1480 .
1481 .IP
1482 Converting to a hardware integer happens for the second operand of the power (\fB^\fR), places (\fB@\fR), left shift (\fB<<\fR), and right shift (\fB>>\fR) operators and their corresponding assignment operators\.
1483 .
1484 .TP
1485 \fB2\fR
1486 A parse error occurred\.
1487 .
1488 .IP
1489 Parse errors include unexpected \fBEOF\fR, using an invalid character, failing to find the end of a string or comment, using a token where it is invalid, giving an invalid expression, giving an invalid print statement, giving an invalid function definition, attempting to assign to an expression that is not a \fInamed expression\fR, giving an invalid \fBauto\fR list, having a duplicate \fBauto\fR/function parameter, failing to find the end of a code block, attempting to return a value from a \fBvoid\fR function, attempting to use a variable as a reference, and using any extensions when the option \fB\-s\fR or any equivalents were given\.
1490 .
1491 .TP
1492 \fB3\fR
1493 A runtime error occurred\.
1494 .
1495 .IP
1496 Runtime errors include assigning an invalid number to \fBibase\fR, \fBobase\fR, or \fBscale\fR; give a bad expression to a \fBread()\fR call, calling \fBread()\fR inside of a \fBread()\fR call, type errors, passing the wrong number of parameters to functions, attempting to call an undefined function, and attempting to use a \fBvoid\fR function call as a value in an expression\.
1497 .
1498 .TP
1499 \fB4\fR
1500 A fatal error occurred\.
1501 .
1502 .IP
1503 Fatal errors include memory allocation errors, I/O errors, failing to open files, attempting to use files that do not have only ASCII characters (bc(1) only accepts ASCII characters), attempting to open a directory as a file, and giving invalid command\-line options\.
1504 .
1505 .P
1506 The exit status \fB4\fR is special; when a fatal error occurs, bc(1) always exits and returns \fB4\fR, no matter what mode bc(1) is in\.
1507 .
1508 .P
1509 The other statuses will only be returned when bc(1) is not in interactive mode (see the INTERACTIVE MODE section), since bc(1) resets its state (see the RESET section) and accepts more input when one of those errors occurs in interactive mode\. This is also the case when interactive mode is forced by the \fB\-i\fR flag or \fB\-\-interactive\fR option\.
1510 .
1511 .P
1512 These exit statuses allow bc(1) to be used in shell scripting with error checking, and its normal behavior can be forced by using the \fB\-i\fR flag or \fB\-\-interactive\fR option\.
1513 .
1514 .SH "INTERACTIVE MODE"
1515 Per the standard \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR, bc(1) has an interactive mode and a non\-interactive mode\. Interactive mode is turned on automatically when both \fBstdin\fR and \fBstdout\fR are hooked to a terminal, but the \fB\-i\fR flag and \fB\-\-interactive\fR option can turn it on in other cases\.
1516 .
1517 .P
1518 In interactive mode, bc(1) attempts to recover from errors (see the RESET section), and in normal execution, flushes \fBstdout\fR as soon as execution is done for the current input\.
1519 .
1520 .SH "TTY MODE"
1521 If \fBstdin\fR, \fBstdout\fR, and \fBstderr\fR are all connected to a TTY, bc(1) turns on "TTY mode\."
1522 .
1523 .P
1524 TTY mode is required for history to be enabled (see the COMMAND LINE HISTORY section)\. It is also required to enable special handling for \fBSIGINT\fR signals\.
1525 .
1526 .P
1527 TTY mode is different from interactive mode because interactive mode is required in the bc(1) specification \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR, and interactive mode requires only \fBstdin\fR and \fBstdout\fR to be connected to a terminal\.
1528 .
1529 .SH "SIGNAL HANDLING"
1530 Sending a \fBSIGINT\fR will cause bc(1) to stop execution of the current input\. If bc(1) is in TTY mode (see the TTY MODE section), it will reset (see the RESET section)\. Otherwise, it will clean up and exit\.
1531 .
1532 .P
1533 Note that "current input" can mean one of two things\. If bc(1) is processing input from \fBstdin\fR in TTY mode, it will ask for more input\. If bc(1) is processing input from a file in TTY mode, it will stop processing the file and start processing the next file, if one exists, or ask for input from \fBstdin\fR if no other file exists\.
1534 .
1535 .P
1536 This means that if a \fBSIGINT\fR is sent to bc(1) as it is executing a file, it can seem as though bc(1) did not respond to the signal since it will immediately start executing the next file\. This is by design; most files that users execute when interacting with bc(1) have function definitions, which are quick to parse\. If a file takes a long time to execute, there may be a bug in that file\. The rest of the files could still be executed without problem, allowing the user to continue\.
1537 .
1538 .P
1539 \fBSIGTERM\fR and \fBSIGQUIT\fR cause bc(1) to clean up and exit, and it uses the default handler for all other signals\. The one exception is \fBSIGHUP\fR, if bc(1) was built with history support; in that case, when bc(1) is in TTY mode, a \fBSIGHUP\fR will cause bc(1) to clean up and exit\.
1540 .
1541 .SH "COMMAND LINE HISTORY"
1542 bc(1) supports interactive command\-line editing, if compiled with the history option enabled\. If bc(1) is in TTY mode (see the TTY MODE section), history is enabled\. Previous lines can be recalled and edited with the arrow keys\.
1543 .
1544 .P
1545 \fBNote\fR: when bc(1) is built with history support, tabs are converted to 8 spaces\.
1546 .
1547 .SH "LOCALES"
1548 This bc(1) ships with support for adding error messages for different locales\.
1549 .
1550 .SH "SEE ALSO"
1551 dc(1)
1552 .
1553 .SH "STANDARDS"
1554 bc(1) is compliant with the IEEE Std 1003\.1\-2017 (“POSIX\.1\-2017”) \fIhttps://pubs\.opengroup\.org/onlinepubs/9699919799/utilities/bc\.html\fR specification\. The flags \fB\-efghiqsvVw\fR, all long options, and the extensions noted above are extensions to that specification\.
1555 .
1556 .P
1557 Note that the specification explicitly says that bc(1) only accepts numbers that use a period (\fB\.\fR) as a radix point, regardless of the value of \fBLC_NUMERIC\fR\.
1558 .
1559 .P
1560 This bc(1) ships with support for adding error messages for different locales, so it supports \fBLC_MESSAGES\fR\.
1561 .
1562 .SH "AUTHOR"
1563 This bc(1) was made from scratch by Gavin D\. Howard\.
1564 .
1565 .SH "BUGS"
1566 None are known\. Report bugs at https://git\.yzena\.com/gavin/bc\.