xref: /freebsd/contrib/bc/manuals/bc/EH.1.md (revision 38a52bd3)
1<!---
2
3SPDX-License-Identifier: BSD-2-Clause
4
5Copyright (c) 2018-2021 Gavin D. Howard and contributors.
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are met:
9
10* Redistributions of source code must retain the above copyright notice, this
11  list of conditions and the following disclaimer.
12
13* Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27POSSIBILITY OF SUCH DAMAGE.
28
29-->
30
31# NAME
32
33bc - arbitrary-precision decimal arithmetic language and calculator
34
35# SYNOPSIS
36
37**bc** [**-ghilPqRsvVw**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...]
38
39# DESCRIPTION
40
41bc(1) is an interactive processor for a language first standardized in 1991 by
42POSIX. (The current standard is at
43https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .) The
44language provides unlimited precision decimal arithmetic and is somewhat C-like,
45but there are differences. Such differences will be noted in this document.
46
47After parsing and handling options, this bc(1) reads any files given on the
48command line and executes them before reading from **stdin**.
49
50This bc(1) is a drop-in replacement for *any* bc(1), including (and especially)
51the GNU bc(1).
52
53**Note**: If running this bc(1) on *any* script meant for another bc(1) gives a
54parse error, it is probably because a word this bc(1) reserves as a keyword is
55used as the name of a function, variable, or array. To fix that, use the
56command-line option **-r** *keyword*, where *keyword* is the keyword that is
57used as a name in the script. For more information, see the **OPTIONS** section.
58
59If parsing scripts meant for other bc(1) implementations still does not work,
60that is a bug and should be reported. See the **BUGS** section.
61
62# OPTIONS
63
64The following are the options that bc(1) accepts.
65
66**-g**, **-\-global-stacks**
67
68:   Turns the globals **ibase**, **obase**, and **scale** into stacks.
69
70    This has the effect that a copy of the current value of all three are pushed
71    onto a stack for every function call, as well as popped when every function
72    returns. This means that functions can assign to any and all of those
73    globals without worrying that the change will affect other functions.
74    Thus, a hypothetical function named **output(x,b)** that simply printed
75    **x** in base **b** could be written like this:
76
77        define void output(x, b) {
78            obase=b
79            x
80        }
81
82    instead of like this:
83
84        define void output(x, b) {
85            auto c
86            c=obase
87            obase=b
88            x
89            obase=c
90        }
91
92    This makes writing functions much easier.
93
94    However, since using this flag means that functions cannot set **ibase**,
95    **obase**, or **scale** globally, functions that are made to do so cannot
96    work anymore. There are two possible use cases for that, and each has a
97    solution.
98
99    First, if a function is called on startup to turn bc(1) into a number
100    converter, it is possible to replace that capability with various shell
101    aliases. Examples:
102
103        alias d2o="bc -e ibase=A -e obase=8"
104        alias h2b="bc -e ibase=G -e obase=2"
105
106    Second, if the purpose of a function is to set **ibase**, **obase**, or
107    **scale** globally for any other purpose, it could be split into one to
108    three functions (based on how many globals it sets) and each of those
109    functions could return the desired value for a global.
110
111    If the behavior of this option is desired for every run of bc(1), then users
112    could make sure to define **BC_ENV_ARGS** and include this option (see the
113    **ENVIRONMENT VARIABLES** section for more details).
114
115    If **-s**, **-w**, or any equivalents are used, this option is ignored.
116
117    This is a **non-portable extension**.
118
119**-h**, **-\-help**
120
121:   Prints a usage message and quits.
122
123**-i**, **-\-interactive**
124
125:   Forces interactive mode. (See the **INTERACTIVE MODE** section.)
126
127    This is a **non-portable extension**.
128
129**-L**, **-\-no-line-length**
130
131:   Disables line length checking and prints numbers without backslashes and
132    newlines. In other words, this option sets **BC_LINE_LENGTH** to **0** (see
133    the **ENVIRONMENT VARIABLES** section).
134
135    This is a **non-portable extension**.
136
137**-l**, **-\-mathlib**
138
139:   Sets **scale** (see the **SYNTAX** section) to **20** and loads the included
140    math library before running any code, including any expressions or files
141    specified on the command line.
142
143    To learn what is in the library, see the **LIBRARY** section.
144
145**-P**, **-\-no-prompt**
146
147:   Disables the prompt in TTY mode. (The prompt is only enabled in TTY mode.
148    See the **TTY MODE** section.) This is mostly for those users that do not
149    want a prompt or are not used to having them in bc(1). Most of those users
150    would want to put this option in **BC_ENV_ARGS** (see the
151    **ENVIRONMENT VARIABLES** section).
152
153    These options override the **BC_PROMPT** and **BC_TTY_MODE** environment
154    variables (see the **ENVIRONMENT VARIABLES** section).
155
156    This is a **non-portable extension**.
157
158**-R**, **-\-no-read-prompt**
159
160:   Disables the read prompt in TTY mode. (The read prompt is only enabled in
161    TTY mode. See the **TTY MODE** section.) This is mostly for those users that
162    do not want a read prompt or are not used to having them in bc(1). Most of
163    those users would want to put this option in **BC_ENV_ARGS** (see the
164    **ENVIRONMENT VARIABLES** section). This option is also useful in hash bang
165    lines of bc(1) scripts that prompt for user input.
166
167    This option does not disable the regular prompt because the read prompt is
168    only used when the **read()** built-in function is called.
169
170    These options *do* override the **BC_PROMPT** and **BC_TTY_MODE**
171    environment variables (see the **ENVIRONMENT VARIABLES** section), but only
172    for the read prompt.
173
174    This is a **non-portable extension**.
175
176**-r** *keyword*, **-\-redefine**=*keyword*
177
178:   Redefines *keyword* in order to allow it to be used as a function, variable,
179    or array name. This is useful when this bc(1) gives parse errors when
180    parsing scripts meant for other bc(1) implementations.
181
182    The keywords this bc(1) allows to be redefined are:
183
184    * **abs**
185    * **asciify**
186    * **continue**
187    * **divmod**
188    * **else**
189    * **halt**
190    * **last**
191    * **limits**
192    * **maxibase**
193    * **maxobase**
194    * **maxscale**
195    * **modexp**
196    * **print**
197    * **read**
198	* **stream**
199
200    If any of those keywords are used as a function, variable, or array name in
201    a script, use this option with the keyword as the argument. If multiple are
202    used, use this option for all of them; it can be used multiple times.
203
204    Keywords are *not* redefined when parsing the builtin math library (see the
205    **LIBRARY** section).
206
207    It is a fatal error to redefine keywords mandated by the POSIX standard
208    (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). It is
209    a fatal error to attempt to redefine words that this bc(1) does not reserve
210    as keywords.
211
212**-q**, **-\-quiet**
213
214:   This option is for compatibility with the GNU bc(1)
215    (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
216    bc(1) prints a copyright header. This bc(1) only prints the copyright header
217    if one or more of the **-v**, **-V**, or **-\-version** options are given
218    unless the **BC_BANNER** environment variable is set and contains a non-zero
219    integer or if this bc(1) was built with the header displayed by default. If
220    *any* of that is the case, then this option *does* prevent bc(1) from
221    printing the header.
222
223    This is a **non-portable extension**.
224
225**-s**, **-\-standard**
226
227:   Process exactly the language defined by the standard
228    (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) and
229    error if any extensions are used.
230
231    This is a **non-portable extension**.
232
233**-v**, **-V**, **-\-version**
234
235:   Print the version information (copyright header) and exit.
236
237    This is a **non-portable extension**.
238
239**-w**, **-\-warn**
240
241:   Like **-s** and **-\-standard**, except that warnings (and not errors) are
242    printed for non-standard extensions and execution continues normally.
243
244    This is a **non-portable extension**.
245
246**-z**, **-\-leading-zeroes**
247
248:   Makes bc(1) print all numbers greater than **-1** and less than **1**, and
249    not equal to **0**, with a leading zero.
250
251    This can be set for individual numbers with the **plz(x)**, plznl(x)**,
252    **pnlz(x)**, and **pnlznl(x)** functions in the extended math library (see
253    the **LIBRARY** section).
254
255    This is a **non-portable extension**.
256
257**-e** *expr*, **-\-expression**=*expr*
258
259:   Evaluates *expr*. If multiple expressions are given, they are evaluated in
260    order. If files are given as well (see below), the expressions and files are
261    evaluated in the order given. This means that if a file is given before an
262    expression, the file is read in and evaluated first.
263
264    If this option is given on the command-line (i.e., not in **BC_ENV_ARGS**,
265    see the **ENVIRONMENT VARIABLES** section), then after processing all
266    expressions and files, bc(1) will exit, unless **-** (**stdin**) was given
267    as an argument at least once to **-f** or **-\-file**, whether on the
268    command-line or in **BC_ENV_ARGS**. However, if any other **-e**,
269    **-\-expression**, **-f**, or **-\-file** arguments are given after **-f-**
270    or equivalent is given, bc(1) will give a fatal error and exit.
271
272    This is a **non-portable extension**.
273
274**-f** *file*, **-\-file**=*file*
275
276:   Reads in *file* and evaluates it, line by line, as though it were read
277    through **stdin**. If expressions are also given (see above), the
278    expressions are evaluated in the order given.
279
280    If this option is given on the command-line (i.e., not in **BC_ENV_ARGS**,
281    see the **ENVIRONMENT VARIABLES** section), then after processing all
282    expressions and files, bc(1) will exit, unless **-** (**stdin**) was given
283    as an argument at least once to **-f** or **-\-file**. However, if any other
284    **-e**, **-\-expression**, **-f**, or **-\-file** arguments are given after
285    **-f-** or equivalent is given, bc(1) will give a fatal error and exit.
286
287    This is a **non-portable extension**.
288
289**-I** *ibase*, **-\-ibase**=*ibase*
290
291:   Sets the builtin variable **ibase** to the value *ibase* assuming that
292    *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
293
294    If multiple instances of this option are given, the last is used.
295
296    This is a **non-portable extension**.
297
298**-O** *obase*, **-\-obase**=*obase*
299
300:   Sets the builtin variable **obase** to the value *obase* assuming that
301    *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
302
303    If multiple instances of this option are given, the last is used.
304
305    This is a **non-portable extension**.
306
307**-S** *scale*, **-\-scale**=*scale*
308
309:   Sets the builtin variable **scale** to the value *scale* assuming that
310    *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
311
312    If multiple instances of this option are given, the last is used.
313
314    This is a **non-portable extension**.
315
316All long options are **non-portable extensions**.
317
318# STDIN
319
320If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
321**-\-expression** options, then bc(1) reads from **stdin**.
322
323However, there are a few caveats to this.
324
325First, **stdin** is evaluated a line at a time. The only exception to this is if
326the parse cannot complete. That means that starting a string without ending it
327or starting a function, **if** statement, or loop without ending it will also
328cause bc(1) to not execute.
329
330Second, after an **if** statement, bc(1) doesn't know if an **else** statement
331will follow, so it will not execute until it knows there will not be an **else**
332statement.
333
334# STDOUT
335
336Any non-error output is written to **stdout**. In addition, if history (see the
337**HISTORY** section) and the prompt (see the **TTY MODE** section) are enabled,
338both are output to **stdout**.
339
340**Note**: Unlike other bc(1) implementations, this bc(1) will issue a fatal
341error (see the **EXIT STATUS** section) if it cannot write to **stdout**, so if
342**stdout** is closed, as in **bc <file> >&-**, it will quit with an error. This
343is done so that bc(1) can report problems when **stdout** is redirected to a
344file.
345
346If there are scripts that depend on the behavior of other bc(1) implementations,
347it is recommended that those scripts be changed to redirect **stdout** to
348**/dev/null**.
349
350# STDERR
351
352Any error output is written to **stderr**.
353
354**Note**: Unlike other bc(1) implementations, this bc(1) will issue a fatal
355error (see the **EXIT STATUS** section) if it cannot write to **stderr**, so if
356**stderr** is closed, as in **bc <file> 2>&-**, it will quit with an error. This
357is done so that bc(1) can exit with an error code when **stderr** is redirected
358to a file.
359
360If there are scripts that depend on the behavior of other bc(1) implementations,
361it is recommended that those scripts be changed to redirect **stderr** to
362**/dev/null**.
363
364# SYNTAX
365
366The syntax for bc(1) programs is mostly C-like, with some differences. This
367bc(1) follows the POSIX standard
368(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), which is a
369much more thorough resource for the language this bc(1) accepts. This section is
370meant to be a summary and a listing of all the extensions to the standard.
371
372In the sections below, **E** means expression, **S** means statement, and **I**
373means identifier.
374
375Identifiers (**I**) start with a lowercase letter and can be followed by any
376number (up to **BC_NAME_MAX-1**) of lowercase letters (**a-z**), digits
377(**0-9**), and underscores (**\_**). The regex is **\[a-z\]\[a-z0-9\_\]\***.
378Identifiers with more than one character (letter) are a
379**non-portable extension**.
380
381**ibase** is a global variable determining how to interpret constant numbers. It
382is the "input" base, or the number base used for interpreting input numbers.
383**ibase** is initially **10**. If the **-s** (**-\-standard**) and **-w**
384(**-\-warn**) flags were not given on the command line, the max allowable value
385for **ibase** is **36**. Otherwise, it is **16**. The min allowable value for
386**ibase** is **2**. The max allowable value for **ibase** can be queried in
387bc(1) programs with the **maxibase()** built-in function.
388
389**obase** is a global variable determining how to output results. It is the
390"output" base, or the number base used for outputting numbers. **obase** is
391initially **10**. The max allowable value for **obase** is **BC_BASE_MAX** and
392can be queried in bc(1) programs with the **maxobase()** built-in function. The
393min allowable value for **obase** is **2**. Values are output in the specified
394base.
395
396The *scale* of an expression is the number of digits in the result of the
397expression right of the decimal point, and **scale** is a global variable that
398sets the precision of any operations, with exceptions. **scale** is initially
399**0**. **scale** cannot be negative. The max allowable value for **scale** is
400**BC_SCALE_MAX** and can be queried in bc(1) programs with the **maxscale()**
401built-in function.
402
403bc(1) has both *global* variables and *local* variables. All *local*
404variables are local to the function; they are parameters or are introduced in
405the **auto** list of a function (see the **FUNCTIONS** section). If a variable
406is accessed which is not a parameter or in the **auto** list, it is assumed to
407be *global*. If a parent function has a *local* variable version of a variable
408that a child function considers *global*, the value of that *global* variable in
409the child function is the value of the variable in the parent function, not the
410value of the actual *global* variable.
411
412All of the above applies to arrays as well.
413
414The value of a statement that is an expression (i.e., any of the named
415expressions or operands) is printed unless the lowest precedence operator is an
416assignment operator *and* the expression is notsurrounded by parentheses.
417
418The value that is printed is also assigned to the special variable **last**. A
419single dot (**.**) may also be used as a synonym for **last**. These are
420**non-portable extensions**.
421
422Either semicolons or newlines may separate statements.
423
424## Comments
425
426There are two kinds of comments:
427
4281.	Block comments are enclosed in **/\*** and **\*/**.
4292.	Line comments go from **#** until, and not including, the next newline. This
430	is a **non-portable extension**.
431
432## Named Expressions
433
434The following are named expressions in bc(1):
435
4361.	Variables: **I**
4372.	Array Elements: **I[E]**
4383.	**ibase**
4394.	**obase**
4405.	**scale**
4416.	**last** or a single dot (**.**)
442
443Number 6 is a **non-portable extension**.
444
445Variables and arrays do not interfere; users can have arrays named the same as
446variables. This also applies to functions (see the **FUNCTIONS** section), so a
447user can have a variable, array, and function that all have the same name, and
448they will not shadow each other, whether inside of functions or not.
449
450Named expressions are required as the operand of **increment**/**decrement**
451operators  and as the left side of **assignment** operators (see the *Operators*
452subsection).
453
454## Operands
455
456The following are valid operands in bc(1):
457
4581.	Numbers (see the *Numbers* subsection below).
4592.	Array indices (**I[E]**).
4603.	**(E)**: The value of **E** (used to change precedence).
4614.	**sqrt(E)**: The square root of **E**. **E** must be non-negative.
4625.	**length(E)**: The number of significant decimal digits in **E**. Returns
463	**1** for **0** with no decimal places. If given a string, the length of the
464	string is returned. Passing a string to **length(E)** is a **non-portable
465	extension**.
4666.	**length(I[])**: The number of elements in the array **I**. This is a
467	**non-portable extension**.
4687.	**scale(E)**: The *scale* of **E**.
4698.	**abs(E)**: The absolute value of **E**. This is a **non-portable
470	extension**.
4719.	**modexp(E, E, E)**: Modular exponentiation, where the first expression is
472	the base, the second is the exponent, and the third is the modulus. All
473	three values must be integers. The second argument must be non-negative. The
474	third argument must be non-zero. This is a **non-portable extension**.
47510.	**divmod(E, E, I[])**: Division and modulus in one operation. This is for
476	optimization. The first expression is the dividend, and the second is the
477	divisor, which must be non-zero. The return value is the quotient, and the
478	modulus is stored in index **0** of the provided array (the last argument).
479	This is a **non-portable extension**.
48011.	**asciify(E)**: If **E** is a string, returns a string that is the first
481	letter of its argument. If it is a number, calculates the number mod **256**
482	and returns that number as a one-character string. This is a **non-portable
483	extension**.
48412.	**I()**, **I(E)**, **I(E, E)**, and so on, where **I** is an identifier for
485	a non-**void** function (see the *Void Functions* subsection of the
486	**FUNCTIONS** section). The **E** argument(s) may also be arrays of the form
487	**I[]**, which will automatically be turned into array references (see the
488	*Array References* subsection of the **FUNCTIONS** section) if the
489	corresponding parameter in the function definition is an array reference.
49013.	**read()**: Reads a line from **stdin** and uses that as an expression. The
491	result of that expression is the result of the **read()** operand. This is a
492	**non-portable extension**.
49314.	**maxibase()**: The max allowable **ibase**. This is a **non-portable
494	extension**.
49515.	**maxobase()**: The max allowable **obase**. This is a **non-portable
496	extension**.
49716.	**maxscale()**: The max allowable **scale**. This is a **non-portable
498	extension**.
49917.	**line_length()**: The line length set with **BC_LINE_LENGTH** (see the
500	**ENVIRONMENT VARIABLES** section). This is a **non-portable extension**.
50118.	**global_stacks()**: **0** if global stacks are not enabled with the **-g**
502	or **-\-global-stacks** options, non-zero otherwise. See the **OPTIONS**
503	section. This is a **non-portable extension**.
50419.	**leading_zero()**: **0** if leading zeroes are not enabled with the **-z**
505	or **--leading-zeroes** options, non-zero otherwise. See the **OPTIONS**
506	section. This is a **non-portable extension**.
507
508## Numbers
509
510Numbers are strings made up of digits, uppercase letters, and at most **1**
511period for a radix. Numbers can have up to **BC_NUM_MAX** digits. Uppercase
512letters are equal to **9** + their position in the alphabet (i.e., **A** equals
513**10**, or **9+1**). If a digit or letter makes no sense with the current value
514of **ibase**, they are set to the value of the highest valid digit in **ibase**.
515
516Single-character numbers (i.e., **A** alone) take the value that they would have
517if they were valid digits, regardless of the value of **ibase**. This means that
518**A** alone always equals decimal **10** and **Z** alone always equals decimal
519**35**.
520
521## Operators
522
523The following arithmetic and logical operators can be used. They are listed in
524order of decreasing precedence. Operators in the same group have the same
525precedence.
526
527**++** **-\-**
528
529:   Type: Prefix and Postfix
530
531    Associativity: None
532
533    Description: **increment**, **decrement**
534
535**-** **!**
536
537:   Type: Prefix
538
539    Associativity: None
540
541    Description: **negation**, **boolean not**
542
543**\^**
544
545:   Type: Binary
546
547    Associativity: Right
548
549    Description: **power**
550
551**\*** **/** **%**
552
553:   Type: Binary
554
555    Associativity: Left
556
557    Description: **multiply**, **divide**, **modulus**
558
559**+** **-**
560
561:   Type: Binary
562
563    Associativity: Left
564
565    Description: **add**, **subtract**
566
567**=** **+=** **-=** **\*=** **/=** **%=** **\^=**
568
569:   Type: Binary
570
571    Associativity: Right
572
573    Description: **assignment**
574
575**==** **\<=** **\>=** **!=** **\<** **\>**
576
577:   Type: Binary
578
579    Associativity: Left
580
581    Description: **relational**
582
583**&&**
584
585:   Type: Binary
586
587    Associativity: Left
588
589    Description: **boolean and**
590
591**||**
592
593:   Type: Binary
594
595    Associativity: Left
596
597    Description: **boolean or**
598
599The operators will be described in more detail below.
600
601**++** **-\-**
602
603:   The prefix and postfix **increment** and **decrement** operators behave
604    exactly like they would in C. They require a named expression (see the
605    *Named Expressions* subsection) as an operand.
606
607    The prefix versions of these operators are more efficient; use them where
608    possible.
609
610**-**
611
612:   The **negation** operator returns **0** if a user attempts to negate any
613    expression with the value **0**. Otherwise, a copy of the expression with
614    its sign flipped is returned.
615
616**!**
617
618:   The **boolean not** operator returns **1** if the expression is **0**, or
619    **0** otherwise.
620
621    This is a **non-portable extension**.
622
623**\^**
624
625:   The **power** operator (not the **exclusive or** operator, as it would be in
626    C) takes two expressions and raises the first to the power of the value of
627    the second. The *scale* of the result is equal to **scale**.
628
629    The second expression must be an integer (no *scale*), and if it is
630    negative, the first value must be non-zero.
631
632**\***
633
634:   The **multiply** operator takes two expressions, multiplies them, and
635    returns the product. If **a** is the *scale* of the first expression and
636    **b** is the *scale* of the second expression, the *scale* of the result is
637    equal to **min(a+b,max(scale,a,b))** where **min()** and **max()** return
638    the obvious values.
639
640**/**
641
642:   The **divide** operator takes two expressions, divides them, and returns the
643    quotient. The *scale* of the result shall be the value of **scale**.
644
645    The second expression must be non-zero.
646
647**%**
648
649:   The **modulus** operator takes two expressions, **a** and **b**, and
650    evaluates them by 1) Computing **a/b** to current **scale** and 2) Using the
651    result of step 1 to calculate **a-(a/b)\*b** to *scale*
652    **max(scale+scale(b),scale(a))**.
653
654    The second expression must be non-zero.
655
656**+**
657
658:   The **add** operator takes two expressions, **a** and **b**, and returns the
659    sum, with a *scale* equal to the max of the *scale*s of **a** and **b**.
660
661**-**
662
663:   The **subtract** operator takes two expressions, **a** and **b**, and
664    returns the difference, with a *scale* equal to the max of the *scale*s of
665    **a** and **b**.
666
667**=** **+=** **-=** **\*=** **/=** **%=** **\^=**
668
669:   The **assignment** operators take two expressions, **a** and **b** where
670    **a** is a named expression (see the *Named Expressions* subsection).
671
672    For **=**, **b** is copied and the result is assigned to **a**. For all
673    others, **a** and **b** are applied as operands to the corresponding
674    arithmetic operator and the result is assigned to **a**.
675
676**==** **\<=** **\>=** **!=** **\<** **\>**
677
678:   The **relational** operators compare two expressions, **a** and **b**, and
679    if the relation holds, according to C language semantics, the result is
680    **1**. Otherwise, it is **0**.
681
682    Note that unlike in C, these operators have a lower precedence than the
683    **assignment** operators, which means that **a=b\>c** is interpreted as
684    **(a=b)\>c**.
685
686    Also, unlike the standard
687    (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
688    requires, these operators can appear anywhere any other expressions can be
689    used. This allowance is a **non-portable extension**.
690
691**&&**
692
693:   The **boolean and** operator takes two expressions and returns **1** if both
694    expressions are non-zero, **0** otherwise.
695
696    This is *not* a short-circuit operator.
697
698    This is a **non-portable extension**.
699
700**||**
701
702:   The **boolean or** operator takes two expressions and returns **1** if one
703    of the expressions is non-zero, **0** otherwise.
704
705    This is *not* a short-circuit operator.
706
707    This is a **non-portable extension**.
708
709## Statements
710
711The following items are statements:
712
7131.	**E**
7142.	**{** **S** **;** ... **;** **S** **}**
7153.	**if** **(** **E** **)** **S**
7164.	**if** **(** **E** **)** **S** **else** **S**
7175.	**while** **(** **E** **)** **S**
7186.	**for** **(** **E** **;** **E** **;** **E** **)** **S**
7197.	An empty statement
7208.	**break**
7219.	**continue**
72210.	**quit**
72311.	**halt**
72412.	**limits**
72513.	A string of characters, enclosed in double quotes
72614.	**print** **E** **,** ... **,** **E**
72715.	**stream** **E** **,** ... **,** **E**
72816.	**I()**, **I(E)**, **I(E, E)**, and so on, where **I** is an identifier for
729	a **void** function (see the *Void Functions* subsection of the
730	**FUNCTIONS** section). The **E** argument(s) may also be arrays of the form
731	**I[]**, which will automatically be turned into array references (see the
732	*Array References* subsection of the **FUNCTIONS** section) if the
733	corresponding parameter in the function definition is an array reference.
734
735Numbers 4, 9, 11, 12, 14, 15, and 16 are **non-portable extensions**.
736
737Also, as a **non-portable extension**, any or all of the expressions in the
738header of a for loop may be omitted. If the condition (second expression) is
739omitted, it is assumed to be a constant **1**.
740
741The **break** statement causes a loop to stop iterating and resume execution
742immediately following a loop. This is only allowed in loops.
743
744The **continue** statement causes a loop iteration to stop early and returns to
745the start of the loop, including testing the loop condition. This is only
746allowed in loops.
747
748The **if** **else** statement does the same thing as in C.
749
750The **quit** statement causes bc(1) to quit, even if it is on a branch that will
751not be executed (it is a compile-time command).
752
753The **halt** statement causes bc(1) to quit, if it is executed. (Unlike **quit**
754if it is on a branch of an **if** statement that is not executed, bc(1) does not
755quit.)
756
757The **limits** statement prints the limits that this bc(1) is subject to. This
758is like the **quit** statement in that it is a compile-time command.
759
760An expression by itself is evaluated and printed, followed by a newline.
761
762## Strings
763
764If strings appear as a statement by themselves, they are printed without a
765trailing newline.
766
767In addition to appearing as a lone statement by themselves, strings can be
768assigned to variables and array elements. They can also be passed to functions
769in variable parameters.
770
771If any statement that expects a string is given a variable that had a string
772assigned to it, the statement acts as though it had received a string.
773
774If any math operation is attempted on a string or a variable or array element
775that has been assigned a string, an error is raised, and bc(1) resets (see the
776**RESET** section).
777
778Assigning strings to variables and array elements and passing them to functions
779are **non-portable extensions**.
780
781## Print Statement
782
783The "expressions" in a **print** statement may also be strings. If they are, there
784are backslash escape sequences that are interpreted specially. What those
785sequences are, and what they cause to be printed, are shown below:
786
787**\\a**:   **\\a**
788
789**\\b**:   **\\b**
790
791**\\\\**:   **\\**
792
793**\\e**:   **\\**
794
795**\\f**:   **\\f**
796
797**\\n**:   **\\n**
798
799**\\q**:   **"**
800
801**\\r**:   **\\r**
802
803**\\t**:   **\\t**
804
805Any other character following a backslash causes the backslash and character to
806be printed as-is.
807
808Any non-string expression in a print statement shall be assigned to **last**,
809like any other expression that is printed.
810
811## Stream Statement
812
813The "expressions in a **stream** statement may also be strings.
814
815If a **stream** statement is given a string, it prints the string as though the
816string had appeared as its own statement. In other words, the **stream**
817statement prints strings normally, without a newline.
818
819If a **stream** statement is given a number, a copy of it is truncated and its
820absolute value is calculated. The result is then printed as though **obase** is
821**256** and each digit is interpreted as an 8-bit ASCII character, making it a
822byte stream.
823
824## Order of Evaluation
825
826All expressions in a statment are evaluated left to right, except as necessary
827to maintain order of operations. This means, for example, assuming that **i** is
828equal to **0**, in the expression
829
830    a[i++] = i++
831
832the first (or 0th) element of **a** is set to **1**, and **i** is equal to **2**
833at the end of the expression.
834
835This includes function arguments. Thus, assuming **i** is equal to **0**, this
836means that in the expression
837
838    x(i++, i++)
839
840the first argument passed to **x()** is **0**, and the second argument is **1**,
841while **i** is equal to **2** before the function starts executing.
842
843# FUNCTIONS
844
845Function definitions are as follows:
846
847```
848define I(I,...,I){
849	auto I,...,I
850	S;...;S
851	return(E)
852}
853```
854
855Any **I** in the parameter list or **auto** list may be replaced with **I[]** to
856make a parameter or **auto** var an array, and any **I** in the parameter list
857may be replaced with **\*I[]** to make a parameter an array reference. Callers
858of functions that take array references should not put an asterisk in the call;
859they must be called with just **I[]** like normal array parameters and will be
860automatically converted into references.
861
862As a **non-portable extension**, the opening brace of a **define** statement may
863appear on the next line.
864
865As a **non-portable extension**, the return statement may also be in one of the
866following forms:
867
8681.	**return**
8692.	**return** **(** **)**
8703.	**return** **E**
871
872The first two, or not specifying a **return** statement, is equivalent to
873**return (0)**, unless the function is a **void** function (see the *Void
874Functions* subsection below).
875
876## Void Functions
877
878Functions can also be **void** functions, defined as follows:
879
880```
881define void I(I,...,I){
882	auto I,...,I
883	S;...;S
884	return
885}
886```
887
888They can only be used as standalone expressions, where such an expression would
889be printed alone, except in a print statement.
890
891Void functions can only use the first two **return** statements listed above.
892They can also omit the return statement entirely.
893
894The word "void" is not treated as a keyword; it is still possible to have
895variables, arrays, and functions named **void**. The word "void" is only
896treated specially right after the **define** keyword.
897
898This is a **non-portable extension**.
899
900## Array References
901
902For any array in the parameter list, if the array is declared in the form
903
904```
905*I[]
906```
907
908it is a **reference**. Any changes to the array in the function are reflected,
909when the function returns, to the array that was passed in.
910
911Other than this, all function arguments are passed by value.
912
913This is a **non-portable extension**.
914
915# LIBRARY
916
917All of the functions below  are available when the **-l** or **-\-mathlib**
918command-line flags are given.
919
920## Standard Library
921
922The standard
923(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) defines the
924following functions for the math library:
925
926**s(x)**
927
928:   Returns the sine of **x**, which is assumed to be in radians.
929
930    This is a transcendental function (see the *Transcendental Functions*
931    subsection below).
932
933**c(x)**
934
935:   Returns the cosine of **x**, which is assumed to be in radians.
936
937    This is a transcendental function (see the *Transcendental Functions*
938    subsection below).
939
940**a(x)**
941
942:   Returns the arctangent of **x**, in radians.
943
944    This is a transcendental function (see the *Transcendental Functions*
945    subsection below).
946
947**l(x)**
948
949:   Returns the natural logarithm of **x**.
950
951    This is a transcendental function (see the *Transcendental Functions*
952    subsection below).
953
954**e(x)**
955
956:   Returns the mathematical constant **e** raised to the power of **x**.
957
958    This is a transcendental function (see the *Transcendental Functions*
959    subsection below).
960
961**j(x, n)**
962
963:   Returns the bessel integer order **n** (truncated) of **x**.
964
965    This is a transcendental function (see the *Transcendental Functions*
966    subsection below).
967
968## Transcendental Functions
969
970All transcendental functions can return slightly inaccurate results, up to 1 ULP
971(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and
972the  article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains
973why it is impossible and unnecessary to calculate exact results for the
974transcendental functions.
975
976Because of the possible inaccuracy, I recommend that users call those functions
977with the precision (**scale**) set to at least 1 higher than is necessary. If
978exact results are *absolutely* required, users can double the precision
979(**scale**) and then truncate.
980
981The transcendental functions in the standard math library are:
982
983* **s(x)**
984* **c(x)**
985* **a(x)**
986* **l(x)**
987* **e(x)**
988* **j(x, n)**
989
990# RESET
991
992When bc(1) encounters an error or a signal that it has a non-default handler
993for, it resets. This means that several things happen.
994
995First, any functions that are executing are stopped and popped off the stack.
996The behavior is not unlike that of exceptions in programming languages. Then
997the execution point is set so that any code waiting to execute (after all
998functions returned) is skipped.
999
1000Thus, when bc(1) resets, it skips any remaining code waiting to be executed.
1001Then, if it is interactive mode, and the error was not a fatal error (see the
1002**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
1003appropriate return code.
1004
1005Note that this reset behavior is different from the GNU bc(1), which attempts to
1006start executing the statement right after the one that caused an error.
1007
1008# PERFORMANCE
1009
1010Most bc(1) implementations use **char** types to calculate the value of **1**
1011decimal digit at a time, but that can be slow. This bc(1) does something
1012different.
1013
1014It uses large integers to calculate more than **1** decimal digit at a time. If
1015built in a environment where **BC_LONG_BIT** (see the **LIMITS** section) is
1016**64**, then each integer has **9** decimal digits. If built in an environment
1017where **BC_LONG_BIT** is **32** then each integer has **4** decimal digits. This
1018value (the number of decimal digits per large integer) is called
1019**BC_BASE_DIGS**.
1020
1021The actual values of **BC_LONG_BIT** and **BC_BASE_DIGS** can be queried with
1022the **limits** statement.
1023
1024In addition, this bc(1) uses an even larger integer for overflow checking. This
1025integer type depends on the value of **BC_LONG_BIT**, but is always at least
1026twice as large as the integer type used to store digits.
1027
1028# LIMITS
1029
1030The following are the limits on bc(1):
1031
1032**BC_LONG_BIT**
1033
1034:   The number of bits in the **long** type in the environment where bc(1) was
1035    built. This determines how many decimal digits can be stored in a single
1036    large integer (see the **PERFORMANCE** section).
1037
1038**BC_BASE_DIGS**
1039
1040:   The number of decimal digits per large integer (see the **PERFORMANCE**
1041    section). Depends on **BC_LONG_BIT**.
1042
1043**BC_BASE_POW**
1044
1045:   The max decimal number that each large integer can store (see
1046    **BC_BASE_DIGS**) plus **1**. Depends on **BC_BASE_DIGS**.
1047
1048**BC_OVERFLOW_MAX**
1049
1050:   The max number that the overflow type (see the **PERFORMANCE** section) can
1051    hold. Depends on **BC_LONG_BIT**.
1052
1053**BC_BASE_MAX**
1054
1055:   The maximum output base. Set at **BC_BASE_POW**.
1056
1057**BC_DIM_MAX**
1058
1059:   The maximum size of arrays. Set at **SIZE_MAX-1**.
1060
1061**BC_SCALE_MAX**
1062
1063:   The maximum **scale**. Set at **BC_OVERFLOW_MAX-1**.
1064
1065**BC_STRING_MAX**
1066
1067:   The maximum length of strings. Set at **BC_OVERFLOW_MAX-1**.
1068
1069**BC_NAME_MAX**
1070
1071:   The maximum length of identifiers. Set at **BC_OVERFLOW_MAX-1**.
1072
1073**BC_NUM_MAX**
1074
1075:   The maximum length of a number (in decimal digits), which includes digits
1076    after the decimal point. Set at **BC_OVERFLOW_MAX-1**.
1077
1078Exponent
1079
1080:   The maximum allowable exponent (positive or negative). Set at
1081    **BC_OVERFLOW_MAX**.
1082
1083Number of vars
1084
1085:   The maximum number of vars/arrays. Set at **SIZE_MAX-1**.
1086
1087The actual values can be queried with the **limits** statement.
1088
1089These limits are meant to be effectively non-existent; the limits are so large
1090(at least on 64-bit machines) that there should not be any point at which they
1091become a problem. In fact, memory should be exhausted before these limits should
1092be hit.
1093
1094# ENVIRONMENT VARIABLES
1095
1096bc(1) recognizes the following environment variables:
1097
1098**POSIXLY_CORRECT**
1099
1100:   If this variable exists (no matter the contents), bc(1) behaves as if
1101    the **-s** option was given.
1102
1103**BC_ENV_ARGS**
1104
1105:   This is another way to give command-line arguments to bc(1). They should be
1106    in the same format as all other command-line arguments. These are always
1107    processed first, so any files given in **BC_ENV_ARGS** will be processed
1108    before arguments and files given on the command-line. This gives the user
1109    the ability to set up "standard" options and files to be used at every
1110    invocation. The most useful thing for such files to contain would be useful
1111    functions that the user might want every time bc(1) runs.
1112
1113    The code that parses **BC_ENV_ARGS** will correctly handle quoted arguments,
1114    but it does not understand escape sequences. For example, the string
1115    **"/home/gavin/some bc file.bc"** will be correctly parsed, but the string
1116    **"/home/gavin/some \"bc\" file.bc"** will include the backslashes.
1117
1118    The quote parsing will handle either kind of quotes, **'** or **"**. Thus,
1119    if you have a file with any number of single quotes in the name, you can use
1120    double quotes as the outside quotes, as in **"some 'bc' file.bc"**, and vice
1121    versa if you have a file with double quotes. However, handling a file with
1122    both kinds of quotes in **BC_ENV_ARGS** is not supported due to the
1123    complexity of the parsing, though such files are still supported on the
1124    command-line where the parsing is done by the shell.
1125
1126**BC_LINE_LENGTH**
1127
1128:   If this environment variable exists and contains an integer that is greater
1129    than **1** and is less than **UINT16_MAX** (**2\^16-1**), bc(1) will output
1130    lines to that length, including the backslash (**\\**). The default line
1131    length is **70**.
1132
1133    The special value of **0** will disable line length checking and print
1134    numbers without regard to line length and without backslashes and newlines.
1135
1136**BC_BANNER**
1137
1138:   If this environment variable exists and contains an integer, then a non-zero
1139    value activates the copyright banner when bc(1) is in interactive mode,
1140    while zero deactivates it.
1141
1142    If bc(1) is not in interactive mode (see the **INTERACTIVE MODE** section),
1143    then this environment variable has no effect because bc(1) does not print
1144    the banner when not in interactive mode.
1145
1146    This environment variable overrides the default, which can be queried with
1147    the **-h** or **-\-help** options.
1148
1149**BC_SIGINT_RESET**
1150
1151:   If bc(1) is not in interactive mode (see the **INTERACTIVE MODE** section),
1152    then this environment variable has no effect because bc(1) exits on
1153    **SIGINT** when not in interactive mode.
1154
1155    However, when bc(1) is in interactive mode, then if this environment
1156    variable exists and contains an integer, a non-zero value makes bc(1) reset
1157    on **SIGINT**, rather than exit, and zero makes bc(1) exit. If this
1158    environment variable exists and is *not* an integer, then bc(1) will exit on
1159    **SIGINT**.
1160
1161    This environment variable overrides the default, which can be queried with
1162    the **-h** or **-\-help** options.
1163
1164**BC_TTY_MODE**
1165
1166:   If TTY mode is *not* available (see the **TTY MODE** section), then this
1167    environment variable has no effect.
1168
1169    However, when TTY mode is available, then if this environment variable
1170    exists and contains an integer, then a non-zero value makes bc(1) use TTY
1171    mode, and zero makes bc(1) not use TTY mode.
1172
1173    This environment variable overrides the default, which can be queried with
1174    the **-h** or **-\-help** options.
1175
1176**BC_PROMPT**
1177
1178:   If TTY mode is *not* available (see the **TTY MODE** section), then this
1179    environment variable has no effect.
1180
1181    However, when TTY mode is available, then if this environment variable
1182    exists and contains an integer, a non-zero value makes bc(1) use a prompt,
1183    and zero or a non-integer makes bc(1) not use a prompt. If this environment
1184    variable does not exist and **BC_TTY_MODE** does, then the value of the
1185    **BC_TTY_MODE** environment variable is used.
1186
1187    This environment variable and the **BC_TTY_MODE** environment variable
1188    override the default, which can be queried with the **-h** or **-\-help**
1189    options.
1190
1191**BC_EXPR_EXIT**
1192
1193:   If any expressions or expression files are given on the command-line with
1194    **-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
1195    variable exists and contains an integer, a non-zero value makes bc(1) exit
1196    after executing the expressions and expression files, and a zero value makes
1197    bc(1) not exit.
1198
1199    This environment variable overrides the default, which can be queried with
1200    the **-h** or **-\-help** options.
1201
1202# EXIT STATUS
1203
1204bc(1) returns the following exit statuses:
1205
1206**0**
1207
1208:   No error.
1209
1210**1**
1211
1212:   A math error occurred. This follows standard practice of using **1** for
1213    expected errors, since math errors will happen in the process of normal
1214    execution.
1215
1216    Math errors include divide by **0**, taking the square root of a negative
1217    number, attempting to convert a negative number to a hardware integer,
1218    overflow when converting a number to a hardware integer, overflow when
1219    calculating the size of a number, and attempting to use a non-integer where
1220    an integer is required.
1221
1222    Converting to a hardware integer happens for the second operand of the power
1223    (**\^**) operator and the corresponding assignment operator.
1224
1225**2**
1226
1227:   A parse error occurred.
1228
1229    Parse errors include unexpected **EOF**, using an invalid character, failing
1230    to find the end of a string or comment, using a token where it is invalid,
1231    giving an invalid expression, giving an invalid print statement, giving an
1232    invalid function definition, attempting to assign to an expression that is
1233    not a named expression (see the *Named Expressions* subsection of the
1234    **SYNTAX** section), giving an invalid **auto** list, having a duplicate
1235    **auto**/function parameter, failing to find the end of a code block,
1236    attempting to return a value from a **void** function, attempting to use a
1237    variable as a reference, and using any extensions when the option **-s** or
1238    any equivalents were given.
1239
1240**3**
1241
1242:   A runtime error occurred.
1243
1244    Runtime errors include assigning an invalid number to any global (**ibase**,
1245    **obase**, or **scale**), giving a bad expression to a **read()** call,
1246    calling **read()** inside of a **read()** call, type errors, passing the
1247    wrong number of arguments to functions, attempting to call an undefined
1248    function, and attempting to use a **void** function call as a value in an
1249    expression.
1250
1251**4**
1252
1253:   A fatal error occurred.
1254
1255    Fatal errors include memory allocation errors, I/O errors, failing to open
1256    files, attempting to use files that do not have only ASCII characters (bc(1)
1257    only accepts ASCII characters), attempting to open a directory as a file,
1258    and giving invalid command-line options.
1259
1260The exit status **4** is special; when a fatal error occurs, bc(1) always exits
1261and returns **4**, no matter what mode bc(1) is in.
1262
1263The other statuses will only be returned when bc(1) is not in interactive mode
1264(see the **INTERACTIVE MODE** section), since bc(1) resets its state (see the
1265**RESET** section) and accepts more input when one of those errors occurs in
1266interactive mode. This is also the case when interactive mode is forced by the
1267**-i** flag or **-\-interactive** option.
1268
1269These exit statuses allow bc(1) to be used in shell scripting with error
1270checking, and its normal behavior can be forced by using the **-i** flag or
1271**-\-interactive** option.
1272
1273# INTERACTIVE MODE
1274
1275Per the standard
1276(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), bc(1) has
1277an interactive mode and a non-interactive mode. Interactive mode is turned on
1278automatically when both **stdin** and **stdout** are hooked to a terminal, but
1279the **-i** flag and **-\-interactive** option can turn it on in other
1280situations.
1281
1282In interactive mode, bc(1) attempts to recover from errors (see the **RESET**
1283section), and in normal execution, flushes **stdout** as soon as execution is
1284done for the current input. bc(1) may also reset on **SIGINT** instead of exit,
1285depending on the contents of, or default for, the **BC_SIGINT_RESET**
1286environment variable (see the **ENVIRONMENT VARIABLES** section).
1287
1288# TTY MODE
1289
1290If **stdin**, **stdout**, and **stderr** are all connected to a TTY, then "TTY
1291mode" is considered to be available, and thus, bc(1) can turn on TTY mode,
1292subject to some settings.
1293
1294If there is the environment variable **BC_TTY_MODE** in the environment (see the
1295**ENVIRONMENT VARIABLES** section), then if that environment variable contains a
1296non-zero integer, bc(1) will turn on TTY mode when **stdin**, **stdout**, and
1297**stderr** are all connected to a TTY. If the **BC_TTY_MODE** environment
1298variable exists but is *not* a non-zero integer, then bc(1) will not turn TTY
1299mode on.
1300
1301If the environment variable **BC_TTY_MODE** does *not* exist, the default
1302setting is used. The default setting can be queried with the **-h** or
1303**-\-help** options.
1304
1305TTY mode is different from interactive mode because interactive mode is required
1306in the bc(1) standard
1307(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html), and
1308interactive mode requires only **stdin** and **stdout** to be connected to a
1309terminal.
1310
1311## Prompt
1312
1313If TTY mode is available, then a prompt can be enabled. Like TTY mode itself, it
1314can be turned on or off with an environment variable: **BC_PROMPT** (see the
1315**ENVIRONMENT VARIABLES** section).
1316
1317If the environment variable **BC_PROMPT** exists and is a non-zero integer, then
1318the prompt is turned on when **stdin**, **stdout**, and **stderr** are connected
1319to a TTY and the **-P** and **-\-no-prompt** options were not used. The read
1320prompt will be turned on under the same conditions, except that the **-R** and
1321**-\-no-read-prompt** options must also not be used.
1322
1323However, if **BC_PROMPT** does not exist, the prompt can be enabled or disabled
1324with the **BC_TTY_MODE** environment variable, the **-P** and **-\-no-prompt**
1325options, and the **-R** and **-\-no-read-prompt** options. See the **ENVIRONMENT
1326VARIABLES** and **OPTIONS** sections for more details.
1327
1328# SIGNAL HANDLING
1329
1330Sending a **SIGINT** will cause bc(1) to do one of two things.
1331
1332If bc(1) is not in interactive mode (see the **INTERACTIVE MODE** section), or
1333the **BC_SIGINT_RESET** environment variable (see the **ENVIRONMENT VARIABLES**
1334section), or its default, is either not an integer or it is zero, bc(1) will
1335exit.
1336
1337However, if bc(1) is in interactive mode, and the **BC_SIGINT_RESET** or its
1338default is an integer and non-zero, then bc(1) will stop executing the current
1339input and reset (see the **RESET** section) upon receiving a **SIGINT**.
1340
1341Note that "current input" can mean one of two things. If bc(1) is processing
1342input from **stdin** in interactive mode, it will ask for more input. If bc(1)
1343is processing input from a file in interactive mode, it will stop processing the
1344file and start processing the next file, if one exists, or ask for input from
1345**stdin** if no other file exists.
1346
1347This means that if a **SIGINT** is sent to bc(1) as it is executing a file, it
1348can seem as though bc(1) did not respond to the signal since it will immediately
1349start executing the next file. This is by design; most files that users execute
1350when interacting with bc(1) have function definitions, which are quick to parse.
1351If a file takes a long time to execute, there may be a bug in that file. The
1352rest of the files could still be executed without problem, allowing the user to
1353continue.
1354
1355**SIGTERM** and **SIGQUIT** cause bc(1) to clean up and exit, and it uses the
1356default handler for all other signals.
1357
1358# LOCALES
1359
1360This bc(1) ships with support for adding error messages for different locales
1361and thus, supports **LC_MESSAGES**.
1362
1363# SEE ALSO
1364
1365dc(1)
1366
1367# STANDARDS
1368
1369bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
1370at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The
1371flags **-efghiqsvVw**, all long options, and the extensions noted above are
1372extensions to that specification.
1373
1374Note that the specification explicitly says that bc(1) only accepts numbers that
1375use a period (**.**) as a radix point, regardless of the value of
1376**LC_NUMERIC**.
1377
1378This bc(1) supports error messages for different locales, and thus, it supports
1379**LC_MESSAGES**.
1380
1381# BUGS
1382
1383None are known. Report bugs at https://git.yzena.com/gavin/bc.
1384
1385# AUTHORS
1386
1387Gavin D. Howard <gavin@yzena.com> and contributors.
1388