xref: /freebsd/contrib/bc/manuals/dc/A.1.md (revision 3078531de10dcae44b253a35125c949ff4235284)
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
33dc - arbitrary-precision decimal reverse-Polish notation calculator
34
35# SYNOPSIS
36
37**dc** [**-hiPRvVx**] [**-\-version**] [**-\-help**] [**-\-interactive**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-extended-register**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*]
38
39# DESCRIPTION
40
41dc(1) is an arbitrary-precision calculator. It uses a stack (reverse Polish
42notation) to store numbers and results of computations. Arithmetic operations
43pop arguments off of the stack and push the results.
44
45If no files are given on the command-line, then dc(1) reads from **stdin** (see
46the **STDIN** section). Otherwise, those files are processed, and dc(1) will
47then exit.
48
49If a user wants to set up a standard environment, they can use **DC_ENV_ARGS**
50(see the **ENVIRONMENT VARIABLES** section). For example, if a user wants the
51**scale** always set to **10**, they can set **DC_ENV_ARGS** to **-e 10k**, and
52this dc(1) will always start with a **scale** of **10**.
53
54# OPTIONS
55
56The following are the options that dc(1) accepts.
57
58**-h**, **-\-help**
59
60:   Prints a usage message and quits.
61
62**-v**, **-V**, **-\-version**
63
64:   Print the version information (copyright header) and exit.
65
66**-i**, **-\-interactive**
67
68:   Forces interactive mode. (See the **INTERACTIVE MODE** section.)
69
70    This is a **non-portable extension**.
71
72**-L**, **-\-no-line-length**
73
74:   Disables line length checking and prints numbers without backslashes and
75    newlines. In other words, this option sets **BC_LINE_LENGTH** to **0** (see
76    the **ENVIRONMENT VARIABLES** section).
77
78    This is a **non-portable extension**.
79
80**-P**, **-\-no-prompt**
81
82:   Disables the prompt in TTY mode. (The prompt is only enabled in TTY mode.
83    See the **TTY MODE** section.) This is mostly for those users that do not
84    want a prompt or are not used to having them in dc(1). Most of those users
85    would want to put this option in **DC_ENV_ARGS**.
86
87    These options override the **DC_PROMPT** and **DC_TTY_MODE** environment
88    variables (see the **ENVIRONMENT VARIABLES** section).
89
90    This is a **non-portable extension**.
91
92**-R**, **-\-no-read-prompt**
93
94:   Disables the read prompt in TTY mode. (The read prompt is only enabled in
95    TTY mode. See the **TTY MODE** section.) This is mostly for those users that
96    do not want a read prompt or are not used to having them in dc(1). Most of
97    those users would want to put this option in **BC_ENV_ARGS** (see the
98    **ENVIRONMENT VARIABLES** section). This option is also useful in hash bang
99    lines of dc(1) scripts that prompt for user input.
100
101    This option does not disable the regular prompt because the read prompt is
102    only used when the **?** command is used.
103
104    These options *do* override the **DC_PROMPT** and **DC_TTY_MODE**
105    environment variables (see the **ENVIRONMENT VARIABLES** section), but only
106    for the read prompt.
107
108    This is a **non-portable extension**.
109
110**-x** **-\-extended-register**
111
112:   Enables extended register mode. See the *Extended Register Mode* subsection
113    of the **REGISTERS** section for more information.
114
115    This is a **non-portable extension**.
116
117**-z**, **-\-leading-zeroes**
118
119:   Makes dc(1) print all numbers greater than **-1** and less than **1**, and
120    not equal to **0**, with a leading zero.
121
122    This can be set for individual numbers with the **plz(x)**, plznl(x)**,
123    **pnlz(x)**, and **pnlznl(x)** functions in the extended math library (see
124    the **LIBRARY** section).
125
126    This is a **non-portable extension**.
127
128**-e** *expr*, **-\-expression**=*expr*
129
130:   Evaluates *expr*. If multiple expressions are given, they are evaluated in
131    order. If files are given as well (see below), the expressions and files are
132    evaluated in the order given. This means that if a file is given before an
133    expression, the file is read in and evaluated first.
134
135    If this option is given on the command-line (i.e., not in **DC_ENV_ARGS**,
136    see the **ENVIRONMENT VARIABLES** section), then after processing all
137    expressions and files, dc(1) will exit, unless **-** (**stdin**) was given
138    as an argument at least once to **-f** or **-\-file**, whether on the
139    command-line or in **DC_ENV_ARGS**. However, if any other **-e**,
140    **-\-expression**, **-f**, or **-\-file** arguments are given after **-f-**
141    or equivalent is given, dc(1) will give a fatal error and exit.
142
143    This is a **non-portable extension**.
144
145**-f** *file*, **-\-file**=*file*
146
147:   Reads in *file* and evaluates it, line by line, as though it were read
148    through **stdin**. If expressions are also given (see above), the
149    expressions are evaluated in the order given.
150
151    If this option is given on the command-line (i.e., not in **DC_ENV_ARGS**,
152    see the **ENVIRONMENT VARIABLES** section), then after processing all
153    expressions and files, dc(1) will exit, unless **-** (**stdin**) was given
154    as an argument at least once to **-f** or **-\-file**. However, if any other
155    **-e**, **-\-expression**, **-f**, or **-\-file** arguments are given after
156    **-f-** or equivalent is given, dc(1) will give a fatal error and exit.
157
158    This is a **non-portable extension**.
159
160**-I** *ibase*, **-\-ibase**=*ibase*
161
162:   Sets the builtin variable **ibase** to the value *ibase* assuming that
163    *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
164
165    If multiple instances of this option are given, the last is used.
166
167    This is a **non-portable extension**.
168
169**-O** *obase*, **-\-obase**=*obase*
170
171:   Sets the builtin variable **obase** to the value *obase* assuming that
172    *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
173
174    If multiple instances of this option are given, the last is used.
175
176    This is a **non-portable extension**.
177
178**-S** *scale*, **-\-scale**=*scale*
179
180:   Sets the builtin variable **scale** to the value *scale* assuming that
181    *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
182
183    If multiple instances of this option are given, the last is used.
184
185    This is a **non-portable extension**.
186
187**-E** *seed*, **-\-seed**=*seed*
188
189:   Sets the builtin variable **seed** to the value *seed* assuming that *seed*
190    is in base 10. It is a fatal error if *seed* is not a valid number.
191
192    If multiple instances of this option are given, the last is used.
193
194    This is a **non-portable extension**.
195
196All long options are **non-portable extensions**.
197
198# STDIN
199
200If no files are given on the command-line and no files or expressions are given
201by the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
202reads from **stdin**.
203
204However, there is a caveat to this.
205
206First, **stdin** is evaluated a line at a time. The only exception to this is if
207a string has been finished, but not ended. This means that, except for escaped
208brackets, all brackets must be balanced before dc(1) parses and executes.
209
210# STDOUT
211
212Any non-error output is written to **stdout**. In addition, if history (see the
213**HISTORY** section) and the prompt (see the **TTY MODE** section) are enabled,
214both are output to **stdout**.
215
216**Note**: Unlike other dc(1) implementations, this dc(1) will issue a fatal
217error (see the **EXIT STATUS** section) if it cannot write to **stdout**, so if
218**stdout** is closed, as in **dc <file> >&-**, it will quit with an error. This
219is done so that dc(1) can report problems when **stdout** is redirected to a
220file.
221
222If there are scripts that depend on the behavior of other dc(1) implementations,
223it is recommended that those scripts be changed to redirect **stdout** to
224**/dev/null**.
225
226# STDERR
227
228Any error output is written to **stderr**.
229
230**Note**: Unlike other dc(1) implementations, this dc(1) will issue a fatal
231error (see the **EXIT STATUS** section) if it cannot write to **stderr**, so if
232**stderr** is closed, as in **dc <file> 2>&-**, it will quit with an error. This
233is done so that dc(1) can exit with an error code when **stderr** is redirected
234to a file.
235
236If there are scripts that depend on the behavior of other dc(1) implementations,
237it is recommended that those scripts be changed to redirect **stderr** to
238**/dev/null**.
239
240# SYNTAX
241
242Each item in the input source code, either a number (see the **NUMBERS**
243section) or a command (see the **COMMANDS** section), is processed and executed,
244in order. Input is processed immediately when entered.
245
246**ibase** is a register (see the **REGISTERS** section) that determines how to
247interpret constant numbers. It is the "input" base, or the number base used for
248interpreting input numbers. **ibase** is initially **10**. The max allowable
249value for **ibase** is **16**. The min allowable value for **ibase** is **2**.
250The max allowable value for **ibase** can be queried in dc(1) programs with the
251**T** command.
252
253**obase** is a register (see the **REGISTERS** section) that determines how to
254output results. It is the "output" base, or the number base used for outputting
255numbers. **obase** is initially **10**. The max allowable value for **obase** is
256**DC_BASE_MAX** and can be queried with the **U** command. The min allowable
257value for **obase** is **0**. If **obase** is **0**, values are output in
258scientific notation, and if **obase** is **1**, values are output in engineering
259notation. Otherwise, values are output in the specified base.
260
261Outputting in scientific and engineering notations are **non-portable
262extensions**.
263
264The *scale* of an expression is the number of digits in the result of the
265expression right of the decimal point, and **scale** is a register (see the
266**REGISTERS** section) that sets the precision of any operations (with
267exceptions). **scale** is initially **0**. **scale** cannot be negative. The max
268allowable value for **scale** can be queried in dc(1) programs with the **V**
269command.
270
271**seed** is a register containing the current seed for the pseudo-random number
272generator. If the current value of **seed** is queried and stored, then if it is
273assigned to **seed** later, the pseudo-random number generator is guaranteed to
274produce the same sequence of pseudo-random numbers that were generated after the
275value of **seed** was first queried.
276
277Multiple values assigned to **seed** can produce the same sequence of
278pseudo-random numbers. Likewise, when a value is assigned to **seed**, it is not
279guaranteed that querying **seed** immediately after will return the same value.
280In addition, the value of **seed** will change after any call to the **'**
281command or the **"** command that does not get receive a value of **0** or
282**1**. The maximum integer returned by the **'** command can be queried with the
283**W** command.
284
285**Note**: The values returned by the pseudo-random number generator with the
286**'** and **"** commands are guaranteed to **NOT** be cryptographically secure.
287This is a consequence of using a seeded pseudo-random number generator. However,
288they *are* guaranteed to be reproducible with identical **seed** values. This
289means that the pseudo-random values from dc(1) should only be used where a
290reproducible stream of pseudo-random numbers is *ESSENTIAL*. In any other case,
291use a non-seeded pseudo-random number generator.
292
293The pseudo-random number generator, **seed**, and all associated operations are
294**non-portable extensions**.
295
296## Comments
297
298Comments go from **#** until, and not including, the next newline. This is a
299**non-portable extension**.
300
301# NUMBERS
302
303Numbers are strings made up of digits, uppercase letters up to **F**, and at
304most **1** period for a radix. Numbers can have up to **DC_NUM_MAX** digits.
305Uppercase letters are equal to **9** + their position in the alphabet (i.e.,
306**A** equals **10**, or **9+1**). If a digit or letter makes no sense with the
307current value of **ibase**, they are set to the value of the highest valid digit
308in **ibase**.
309
310Single-character numbers (i.e., **A** alone) take the value that they would have
311if they were valid digits, regardless of the value of **ibase**. This means that
312**A** alone always equals decimal **10** and **F** alone always equals decimal
313**15**.
314
315In addition, dc(1) accepts numbers in scientific notation. These have the form
316**\<number\>e\<integer\>**. The exponent (the portion after the **e**) must be
317an integer. An example is **1.89237e9**, which is equal to **1892370000**.
318Negative exponents are also allowed, so **4.2890e_3** is equal to **0.0042890**.
319
320**WARNING**: Both the number and the exponent in scientific notation are
321interpreted according to the current **ibase**, but the number is still
322multiplied by **10\^exponent** regardless of the current **ibase**. For example,
323if **ibase** is **16** and dc(1) is given the number string **FFeA**, the
324resulting decimal number will be **2550000000000**, and if dc(1) is given the
325number string **10e_4**, the resulting decimal number will be **0.0016**.
326
327Accepting input as scientific notation is a **non-portable extension**.
328
329# COMMANDS
330
331The valid commands are listed below.
332
333## Printing
334
335These commands are used for printing.
336
337Note that both scientific notation and engineering notation are available for
338printing numbers. Scientific notation is activated by assigning **0** to
339**obase** using **0o**, and engineering notation is activated by assigning **1**
340to **obase** using **1o**. To deactivate them, just assign a different value to
341**obase**.
342
343Printing numbers in scientific notation and/or engineering notation is a
344**non-portable extension**.
345
346**p**
347
348:   Prints the value on top of the stack, whether number or string, and prints a
349    newline after.
350
351    This does not alter the stack.
352
353**n**
354
355:   Prints the value on top of the stack, whether number or string, and pops it
356    off of the stack.
357
358**P**
359
360:   Pops a value off the stack.
361
362    If the value is a number, it is truncated and the absolute value of the
363    result is printed as though **obase** is **256** and each digit is
364    interpreted as an 8-bit ASCII character, making it a byte stream.
365
366    If the value is a string, it is printed without a trailing newline.
367
368    This is a **non-portable extension**.
369
370**f**
371
372:   Prints the entire contents of the stack, in order from newest to oldest,
373    without altering anything.
374
375    Users should use this command when they get lost.
376
377## Arithmetic
378
379These are the commands used for arithmetic.
380
381**+**
382
383:   The top two values are popped off the stack, added, and the result is pushed
384    onto the stack. The *scale* of the result is equal to the max *scale* of
385    both operands.
386
387**-**
388
389:   The top two values are popped off the stack, subtracted, and the result is
390    pushed onto the stack. The *scale* of the result is equal to the max
391    *scale* of both operands.
392
393**\***
394
395:   The top two values are popped off the stack, multiplied, and the result is
396    pushed onto the stack. If **a** is the *scale* of the first expression and
397    **b** is the *scale* of the second expression, the *scale* of the result
398    is equal to **min(a+b,max(scale,a,b))** where **min()** and **max()** return
399    the obvious values.
400
401**/**
402
403:   The top two values are popped off the stack, divided, and the result is
404    pushed onto the stack. The *scale* of the result is equal to **scale**.
405
406    The first value popped off of the stack must be non-zero.
407
408**%**
409
410:   The top two values are popped off the stack, remaindered, and the result is
411    pushed onto the stack.
412
413    Remaindering is equivalent to 1) Computing **a/b** to current **scale**, and
414    2) Using the result of step 1 to calculate **a-(a/b)\*b** to *scale*
415    **max(scale+scale(b),scale(a))**.
416
417    The first value popped off of the stack must be non-zero.
418
419**~**
420
421:   The top two values are popped off the stack, divided and remaindered, and
422    the results (divided first, remainder second) are pushed onto the stack.
423    This is equivalent to **x y / x y %** except that **x** and **y** are only
424    evaluated once.
425
426    The first value popped off of the stack must be non-zero.
427
428    This is a **non-portable extension**.
429
430**\^**
431
432:   The top two values are popped off the stack, the second is raised to the
433    power of the first, and the result is pushed onto the stack. The *scale* of
434    the result is equal to **scale**.
435
436    The first value popped off of the stack must be an integer, and if that
437    value is negative, the second value popped off of the stack must be
438    non-zero.
439
440**v**
441
442:   The top value is popped off the stack, its square root is computed, and the
443    result is pushed onto the stack. The *scale* of the result is equal to
444    **scale**.
445
446    The value popped off of the stack must be non-negative.
447
448**\_**
449
450:   If this command *immediately* precedes a number (i.e., no spaces or other
451    commands), then that number is input as a negative number.
452
453    Otherwise, the top value on the stack is popped and copied, and the copy is
454    negated and pushed onto the stack. This behavior without a number is a
455    **non-portable extension**.
456
457**b**
458
459:   The top value is popped off the stack, and if it is zero, it is pushed back
460    onto the stack. Otherwise, its absolute value is pushed onto the stack.
461
462    This is a **non-portable extension**.
463
464**|**
465
466:   The top three values are popped off the stack, a modular exponentiation is
467    computed, and the result is pushed onto the stack.
468
469    The first value popped is used as the reduction modulus and must be an
470    integer and non-zero. The second value popped is used as the exponent and
471    must be an integer and non-negative. The third value popped is the base and
472    must be an integer.
473
474    This is a **non-portable extension**.
475
476**\$**
477
478:   The top value is popped off the stack and copied, and the copy is truncated
479    and pushed onto the stack.
480
481    This is a **non-portable extension**.
482
483**\@**
484
485:   The top two values are popped off the stack, and the precision of the second
486    is set to the value of the first, whether by truncation or extension.
487
488    The first value popped off of the stack must be an integer and non-negative.
489
490    This is a **non-portable extension**.
491
492**H**
493
494:   The top two values are popped off the stack, and the second is shifted left
495    (radix shifted right) to the value of the first.
496
497    The first value popped off of the stack must be an integer and non-negative.
498
499    This is a **non-portable extension**.
500
501**h**
502
503:   The top two values are popped off the stack, and the second is shifted right
504    (radix shifted left) to the value of the first.
505
506    The first value popped off of the stack must be an integer and non-negative.
507
508    This is a **non-portable extension**.
509
510**G**
511
512:   The top two values are popped off of the stack, they are compared, and a
513    **1** is pushed if they are equal, or **0** otherwise.
514
515    This is a **non-portable extension**.
516
517**N**
518
519:   The top value is popped off of the stack, and if it a **0**, a **1** is
520    pushed; otherwise, a **0** is pushed.
521
522    This is a **non-portable extension**.
523
524**(**
525
526:   The top two values are popped off of the stack, they are compared, and a
527    **1** is pushed if the first is less than the second, or **0** otherwise.
528
529    This is a **non-portable extension**.
530
531**{**
532
533:   The top two values are popped off of the stack, they are compared, and a
534    **1** is pushed if the first is less than or equal to the second, or **0**
535    otherwise.
536
537    This is a **non-portable extension**.
538
539**)**
540
541:   The top two values are popped off of the stack, they are compared, and a
542    **1** is pushed if the first is greater than the second, or **0** otherwise.
543
544    This is a **non-portable extension**.
545
546**}**
547
548:   The top two values are popped off of the stack, they are compared, and a
549    **1** is pushed if the first is greater than or equal to the second, or
550    **0** otherwise.
551
552    This is a **non-portable extension**.
553
554**M**
555
556:   The top two values are popped off of the stack. If they are both non-zero, a
557    **1** is pushed onto the stack. If either of them is zero, or both of them
558    are, then a **0** is pushed onto the stack.
559
560    This is like the **&&** operator in bc(1), and it is *not* a short-circuit
561    operator.
562
563    This is a **non-portable extension**.
564
565**m**
566
567:   The top two values are popped off of the stack. If at least one of them is
568    non-zero, a **1** is pushed onto the stack. If both of them are zero, then a
569    **0** is pushed onto the stack.
570
571    This is like the **||** operator in bc(1), and it is *not* a short-circuit
572    operator.
573
574    This is a **non-portable extension**.
575
576## Pseudo-Random Number Generator
577
578dc(1) has a built-in pseudo-random number generator. These commands query the
579pseudo-random number generator. (See Parameters for more information about the
580**seed** value that controls the pseudo-random number generator.)
581
582The pseudo-random number generator is guaranteed to **NOT** be
583cryptographically secure.
584
585**'**
586
587:   Generates an integer between 0 and **DC_RAND_MAX**, inclusive (see the
588    **LIMITS** section).
589
590    The generated integer is made as unbiased as possible, subject to the
591    limitations of the pseudo-random number generator.
592
593    This is a **non-portable extension**.
594
595**"**
596
597:   Pops a value off of the stack, which is used as an **exclusive** upper bound
598    on the integer that will be generated. If the bound is negative or is a
599    non-integer, an error is raised, and dc(1) resets (see the **RESET**
600    section) while **seed** remains unchanged. If the bound is larger than
601    **DC_RAND_MAX**, the higher bound is honored by generating several
602    pseudo-random integers, multiplying them by appropriate powers of
603    **DC_RAND_MAX+1**, and adding them together. Thus, the size of integer that
604    can be generated with this command is unbounded. Using this command will
605    change the value of **seed**, unless the operand is **0** or **1**. In that
606    case, **0** is pushed onto the stack, and **seed** is *not* changed.
607
608    The generated integer is made as unbiased as possible, subject to the
609    limitations of the pseudo-random number generator.
610
611    This is a **non-portable extension**.
612
613## Stack Control
614
615These commands control the stack.
616
617**c**
618
619:   Removes all items from ("clears") the stack.
620
621**d**
622
623:   Copies the item on top of the stack ("duplicates") and pushes the copy onto
624    the stack.
625
626**r**
627
628:   Swaps ("reverses") the two top items on the stack.
629
630**R**
631
632:   Pops ("removes") the top value from the stack.
633
634## Register Control
635
636These commands control registers (see the **REGISTERS** section).
637
638**s**_r_
639
640:   Pops the value off the top of the stack and stores it into register *r*.
641
642**l**_r_
643
644:   Copies the value in register *r* and pushes it onto the stack. This does not
645    alter the contents of *r*.
646
647**S**_r_
648
649:   Pops the value off the top of the (main) stack and pushes it onto the stack
650    of register *r*. The previous value of the register becomes inaccessible.
651
652**L**_r_
653
654:   Pops the value off the top of the stack for register *r* and push it onto
655    the main stack. The previous value in the stack for register *r*, if any, is
656    now accessible via the **l**_r_ command.
657
658## Parameters
659
660These commands control the values of **ibase**, **obase**, **scale**, and
661**seed**. Also see the **SYNTAX** section.
662
663**i**
664
665:   Pops the value off of the top of the stack and uses it to set **ibase**,
666    which must be between **2** and **16**, inclusive.
667
668    If the value on top of the stack has any *scale*, the *scale* is ignored.
669
670**o**
671
672:   Pops the value off of the top of the stack and uses it to set **obase**,
673    which must be between **0** and **DC_BASE_MAX**, inclusive (see the
674    **LIMITS** section and the **NUMBERS** section).
675
676    If the value on top of the stack has any *scale*, the *scale* is ignored.
677
678**k**
679
680:   Pops the value off of the top of the stack and uses it to set **scale**,
681    which must be non-negative.
682
683    If the value on top of the stack has any *scale*, the *scale* is ignored.
684
685**j**
686
687:   Pops the value off of the top of the stack and uses it to set **seed**. The
688    meaning of **seed** is dependent on the current pseudo-random number
689    generator but is guaranteed to not change except for new major versions.
690
691    The *scale* and sign of the value may be significant.
692
693    If a previously used **seed** value is used again, the pseudo-random number
694    generator is guaranteed to produce the same sequence of pseudo-random
695    numbers as it did when the **seed** value was previously used.
696
697    The exact value assigned to **seed** is not guaranteed to be returned if the
698    **J** command is used. However, if **seed** *does* return a different value,
699    both values, when assigned to **seed**, are guaranteed to produce the same
700    sequence of pseudo-random numbers. This means that certain values assigned
701    to **seed** will not produce unique sequences of pseudo-random numbers.
702
703    There is no limit to the length (number of significant decimal digits) or
704    *scale* of the value that can be assigned to **seed**.
705
706    This is a **non-portable extension**.
707
708**I**
709
710:   Pushes the current value of **ibase** onto the main stack.
711
712**O**
713
714:   Pushes the current value of **obase** onto the main stack.
715
716**K**
717
718:   Pushes the current value of **scale** onto the main stack.
719
720**J**
721
722:   Pushes the current value of **seed** onto the main stack.
723
724    This is a **non-portable extension**.
725
726**T**
727
728:   Pushes the maximum allowable value of **ibase** onto the main stack.
729
730    This is a **non-portable extension**.
731
732**U**
733
734:   Pushes the maximum allowable value of **obase** onto the main stack.
735
736    This is a **non-portable extension**.
737
738**V**
739
740:   Pushes the maximum allowable value of **scale** onto the main stack.
741
742    This is a **non-portable extension**.
743
744**W**
745
746:   Pushes the maximum (inclusive) integer that can be generated with the **'**
747    pseudo-random number generator command.
748
749    This is a **non-portable extension**.
750
751## Strings
752
753The following commands control strings.
754
755dc(1) can work with both numbers and strings, and registers (see the
756**REGISTERS** section) can hold both strings and numbers. dc(1) always knows
757whether the contents of a register are a string or a number.
758
759While arithmetic operations have to have numbers, and will print an error if
760given a string, other commands accept strings.
761
762Strings can also be executed as macros. For example, if the string **[1pR]** is
763executed as a macro, then the code **1pR** is executed, meaning that the **1**
764will be printed with a newline after and then popped from the stack.
765
766**\[**_characters_**\]**
767
768:   Makes a string containing *characters* and pushes it onto the stack.
769
770    If there are brackets (**\[** and **\]**) in the string, then they must be
771    balanced. Unbalanced brackets can be escaped using a backslash (**\\**)
772    character.
773
774    If there is a backslash character in the string, the character after it
775    (even another backslash) is put into the string verbatim, but the (first)
776    backslash is not.
777
778**a**
779
780:   The value on top of the stack is popped.
781
782    If it is a number, it is truncated and its absolute value is taken. The
783    result mod **256** is calculated. If that result is **0**, push an empty
784    string; otherwise, push a one-character string where the character is the
785    result of the mod interpreted as an ASCII character.
786
787    If it is a string, then a new string is made. If the original string is
788    empty, the new string is empty. If it is not, then the first character of
789    the original string is used to create the new string as a one-character
790    string. The new string is then pushed onto the stack.
791
792    This is a **non-portable extension**.
793
794**x**
795
796:   Pops a value off of the top of the stack.
797
798    If it is a number, it is pushed back onto the stack.
799
800    If it is a string, it is executed as a macro.
801
802    This behavior is the norm whenever a macro is executed, whether by this
803    command or by the conditional execution commands below.
804
805**\>**_r_
806
807:   Pops two values off of the stack that must be numbers and compares them. If
808    the first value is greater than the second, then the contents of register
809    *r* are executed.
810
811    For example, **0 1>a** will execute the contents of register **a**, and
812    **1 0>a** will not.
813
814    If either or both of the values are not numbers, dc(1) will raise an error
815    and reset (see the **RESET** section).
816
817**>**_r_**e**_s_
818
819:   Like the above, but will execute register *s* if the comparison fails.
820
821    If either or both of the values are not numbers, dc(1) will raise an error
822    and reset (see the **RESET** section).
823
824    This is a **non-portable extension**.
825
826**!\>**_r_
827
828:   Pops two values off of the stack that must be numbers and compares them. If
829    the first value is not greater than the second (less than or equal to), then
830    the contents of register *r* are executed.
831
832    If either or both of the values are not numbers, dc(1) will raise an error
833    and reset (see the **RESET** section).
834
835**!\>**_r_**e**_s_
836
837:   Like the above, but will execute register *s* if the comparison fails.
838
839    If either or both of the values are not numbers, dc(1) will raise an error
840    and reset (see the **RESET** section).
841
842    This is a **non-portable extension**.
843
844**\<**_r_
845
846:   Pops two values off of the stack that must be numbers and compares them. If
847    the first value is less than the second, then the contents of register *r*
848    are executed.
849
850    If either or both of the values are not numbers, dc(1) will raise an error
851    and reset (see the **RESET** section).
852
853**\<**_r_**e**_s_
854
855:   Like the above, but will execute register *s* if the comparison fails.
856
857    If either or both of the values are not numbers, dc(1) will raise an error
858    and reset (see the **RESET** section).
859
860    This is a **non-portable extension**.
861
862**!\<**_r_
863
864:   Pops two values off of the stack that must be numbers and compares them. If
865    the first value is not less than the second (greater than or equal to), then
866    the contents of register *r* are executed.
867
868    If either or both of the values are not numbers, dc(1) will raise an error
869    and reset (see the **RESET** section).
870
871**!\<**_r_**e**_s_
872
873:   Like the above, but will execute register *s* if the comparison fails.
874
875    If either or both of the values are not numbers, dc(1) will raise an error
876    and reset (see the **RESET** section).
877
878    This is a **non-portable extension**.
879
880**=**_r_
881
882:   Pops two values off of the stack that must be numbers and compares them. If
883    the first value is equal to the second, then the contents of register *r*
884    are executed.
885
886    If either or both of the values are not numbers, dc(1) will raise an error
887    and reset (see the **RESET** section).
888
889**=**_r_**e**_s_
890
891:   Like the above, but will execute register *s* if the comparison fails.
892
893    If either or both of the values are not numbers, dc(1) will raise an error
894    and reset (see the **RESET** section).
895
896    This is a **non-portable extension**.
897
898**!=**_r_
899
900:   Pops two values off of the stack that must be numbers and compares them. If
901    the first value is not equal to the second, then the contents of register
902    *r* are executed.
903
904    If either or both of the values are not numbers, dc(1) will raise an error
905    and reset (see the **RESET** section).
906
907**!=**_r_**e**_s_
908
909:   Like the above, but will execute register *s* if the comparison fails.
910
911    If either or both of the values are not numbers, dc(1) will raise an error
912    and reset (see the **RESET** section).
913
914    This is a **non-portable extension**.
915
916**?**
917
918:   Reads a line from the **stdin** and executes it. This is to allow macros to
919    request input from users.
920
921**q**
922
923:   During execution of a macro, this exits the execution of that macro and the
924    execution of the macro that executed it. If there are no macros, or only one
925    macro executing, dc(1) exits.
926
927**Q**
928
929:   Pops a value from the stack which must be non-negative and is used the
930    number of macro executions to pop off of the execution stack. If the number
931    of levels to pop is greater than the number of executing macros, dc(1)
932    exits.
933
934**,**
935
936:   Pushes the depth of the execution stack onto the stack. The execution stack
937    is the stack of string executions. The number that is pushed onto the stack
938    is exactly as many as is needed to make dc(1) exit with the **Q** command,
939    so the sequence **,Q** will make dc(1) exit.
940
941## Status
942
943These commands query status of the stack or its top value.
944
945**Z**
946
947:   Pops a value off of the stack.
948
949    If it is a number, calculates the number of significant decimal digits it
950    has and pushes the result. It will push **1** if the argument is **0** with
951    no decimal places.
952
953    If it is a string, pushes the number of characters the string has.
954
955**X**
956
957:   Pops a value off of the stack.
958
959    If it is a number, pushes the *scale* of the value onto the stack.
960
961    If it is a string, pushes **0**.
962
963**z**
964
965:   Pushes the current depth of the stack (before execution of this command)
966    onto the stack.
967
968**y**_r_
969
970:   Pushes the current stack depth of the register *r* onto the main stack.
971
972    Because each register has a depth of **1** (with the value **0** in the top
973    item) when dc(1) starts, dc(1) requires that each register's stack must
974    always have at least one item; dc(1) will give an error and reset otherwise
975    (see the **RESET** section). This means that this command will never push
976    **0**.
977
978    This is a **non-portable extension**.
979
980## Arrays
981
982These commands manipulate arrays.
983
984**:**_r_
985
986:   Pops the top two values off of the stack. The second value will be stored in
987    the array *r* (see the **REGISTERS** section), indexed by the first value.
988
989**;**_r_
990
991:   Pops the value on top of the stack and uses it as an index into the array
992    *r*. The selected value is then pushed onto the stack.
993
994**Y**_r_
995
996:   Pushes the length of the array *r* onto the stack.
997
998    This is a **non-portable extension**.
999
1000## Global Settings
1001
1002These commands retrieve global settings. These are the only commands that
1003require multiple specific characters, and all of them begin with the letter
1004**g**. Only the characters below are allowed after the character **g**; any
1005other character produces a parse error (see the **ERRORS** section).
1006
1007**gl**
1008
1009:   Pushes the line length set by **DC_LINE_LENGTH** (see the **ENVIRONMENT
1010    VARIABLES** section) onto the stack.
1011
1012**gz**
1013
1014:   Pushes **0** onto the stack if the leading zero setting has not been enabled
1015    with the **-z** or **-\-leading-zeroes** options (see the **OPTIONS**
1016    section), non-zero otherwise.
1017
1018# REGISTERS
1019
1020Registers are names that can store strings, numbers, and arrays. (Number/string
1021registers do not interfere with array registers.)
1022
1023Each register is also its own stack, so the current register value is the top of
1024the stack for the register. All registers, when first referenced, have one value
1025(**0**) in their stack, and it is a runtime error to attempt to pop that item
1026off of the register stack.
1027
1028In non-extended register mode, a register name is just the single character that
1029follows any command that needs a register name. The only exceptions are: a
1030newline (**'\\n'**) and a left bracket (**'['**); it is a parse error for a
1031newline or a left bracket to be used as a register name.
1032
1033## Extended Register Mode
1034
1035Unlike most other dc(1) implentations, this dc(1) provides nearly unlimited
1036amounts of registers, if extended register mode is enabled.
1037
1038If extended register mode is enabled (**-x** or **-\-extended-register**
1039command-line arguments are given), then normal single character registers are
1040used *unless* the character immediately following a command that needs a
1041register name is a space (according to **isspace()**) and not a newline
1042(**'\\n'**).
1043
1044In that case, the register name is found according to the regex
1045**\[a-z\]\[a-z0-9\_\]\*** (like bc(1) identifiers), and it is a parse error if
1046the next non-space characters do not match that regex.
1047
1048# RESET
1049
1050When dc(1) encounters an error or a signal that it has a non-default handler
1051for, it resets. This means that several things happen.
1052
1053First, any macros that are executing are stopped and popped off the stack.
1054The behavior is not unlike that of exceptions in programming languages. Then
1055the execution point is set so that any code waiting to execute (after all
1056macros returned) is skipped.
1057
1058Thus, when dc(1) resets, it skips any remaining code waiting to be executed.
1059Then, if it is interactive mode, and the error was not a fatal error (see the
1060**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
1061appropriate return code.
1062
1063# PERFORMANCE
1064
1065Most dc(1) implementations use **char** types to calculate the value of **1**
1066decimal digit at a time, but that can be slow. This dc(1) does something
1067different.
1068
1069It uses large integers to calculate more than **1** decimal digit at a time. If
1070built in a environment where **DC_LONG_BIT** (see the **LIMITS** section) is
1071**64**, then each integer has **9** decimal digits. If built in an environment
1072where **DC_LONG_BIT** is **32** then each integer has **4** decimal digits. This
1073value (the number of decimal digits per large integer) is called
1074**DC_BASE_DIGS**.
1075
1076In addition, this dc(1) uses an even larger integer for overflow checking. This
1077integer type depends on the value of **DC_LONG_BIT**, but is always at least
1078twice as large as the integer type used to store digits.
1079
1080# LIMITS
1081
1082The following are the limits on dc(1):
1083
1084**DC_LONG_BIT**
1085
1086:   The number of bits in the **long** type in the environment where dc(1) was
1087    built. This determines how many decimal digits can be stored in a single
1088    large integer (see the **PERFORMANCE** section).
1089
1090**DC_BASE_DIGS**
1091
1092:   The number of decimal digits per large integer (see the **PERFORMANCE**
1093    section). Depends on **DC_LONG_BIT**.
1094
1095**DC_BASE_POW**
1096
1097:   The max decimal number that each large integer can store (see
1098    **DC_BASE_DIGS**) plus **1**. Depends on **DC_BASE_DIGS**.
1099
1100**DC_OVERFLOW_MAX**
1101
1102:   The max number that the overflow type (see the **PERFORMANCE** section) can
1103    hold. Depends on **DC_LONG_BIT**.
1104
1105**DC_BASE_MAX**
1106
1107:   The maximum output base. Set at **DC_BASE_POW**.
1108
1109**DC_DIM_MAX**
1110
1111:   The maximum size of arrays. Set at **SIZE_MAX-1**.
1112
1113**DC_SCALE_MAX**
1114
1115:   The maximum **scale**. Set at **DC_OVERFLOW_MAX-1**.
1116
1117**DC_STRING_MAX**
1118
1119:   The maximum length of strings. Set at **DC_OVERFLOW_MAX-1**.
1120
1121**DC_NAME_MAX**
1122
1123:   The maximum length of identifiers. Set at **DC_OVERFLOW_MAX-1**.
1124
1125**DC_NUM_MAX**
1126
1127:   The maximum length of a number (in decimal digits), which includes digits
1128    after the decimal point. Set at **DC_OVERFLOW_MAX-1**.
1129
1130**DC_RAND_MAX**
1131
1132:   The maximum integer (inclusive) returned by the **'** command, if dc(1). Set
1133    at **2\^DC_LONG_BIT-1**.
1134
1135Exponent
1136
1137:   The maximum allowable exponent (positive or negative). Set at
1138    **DC_OVERFLOW_MAX**.
1139
1140Number of vars
1141
1142:   The maximum number of vars/arrays. Set at **SIZE_MAX-1**.
1143
1144These limits are meant to be effectively non-existent; the limits are so large
1145(at least on 64-bit machines) that there should not be any point at which they
1146become a problem. In fact, memory should be exhausted before these limits should
1147be hit.
1148
1149# ENVIRONMENT VARIABLES
1150
1151dc(1) recognizes the following environment variables:
1152
1153**DC_ENV_ARGS**
1154
1155:   This is another way to give command-line arguments to dc(1). They should be
1156    in the same format as all other command-line arguments. These are always
1157    processed first, so any files given in **DC_ENV_ARGS** will be processed
1158    before arguments and files given on the command-line. This gives the user
1159    the ability to set up "standard" options and files to be used at every
1160    invocation. The most useful thing for such files to contain would be useful
1161    functions that the user might want every time dc(1) runs. Another use would
1162    be to use the **-e** option to set **scale** to a value other than **0**.
1163
1164    The code that parses **DC_ENV_ARGS** will correctly handle quoted arguments,
1165    but it does not understand escape sequences. For example, the string
1166    **"/home/gavin/some dc file.dc"** will be correctly parsed, but the string
1167    **"/home/gavin/some \"dc\" file.dc"** will include the backslashes.
1168
1169    The quote parsing will handle either kind of quotes, **'** or **"**. Thus,
1170    if you have a file with any number of single quotes in the name, you can use
1171    double quotes as the outside quotes, as in **"some 'dc' file.dc"**, and vice
1172    versa if you have a file with double quotes. However, handling a file with
1173    both kinds of quotes in **DC_ENV_ARGS** is not supported due to the
1174    complexity of the parsing, though such files are still supported on the
1175    command-line where the parsing is done by the shell.
1176
1177**DC_LINE_LENGTH**
1178
1179:   If this environment variable exists and contains an integer that is greater
1180    than **1** and is less than **UINT16_MAX** (**2\^16-1**), dc(1) will output
1181    lines to that length, including the backslash newline combo. The default
1182    line length is **70**.
1183
1184    The special value of **0** will disable line length checking and print
1185    numbers without regard to line length and without backslashes and newlines.
1186
1187**DC_SIGINT_RESET**
1188
1189:   If dc(1) is not in interactive mode (see the **INTERACTIVE MODE** section),
1190    then this environment variable has no effect because dc(1) exits on
1191    **SIGINT** when not in interactive mode.
1192
1193    However, when dc(1) is in interactive mode, then if this environment
1194    variable exists and contains an integer, a non-zero value makes dc(1) reset
1195    on **SIGINT**, rather than exit, and zero makes dc(1) exit. If this
1196    environment variable exists and is *not* an integer, then dc(1) will exit on
1197    **SIGINT**.
1198
1199    This environment variable overrides the default, which can be queried with
1200    the **-h** or **-\-help** options.
1201
1202**DC_TTY_MODE**
1203
1204:   If TTY mode is *not* available (see the **TTY MODE** section), then this
1205    environment variable has no effect.
1206
1207    However, when TTY mode is available, then if this environment variable
1208    exists and contains an integer, then a non-zero value makes dc(1) use TTY
1209    mode, and zero makes dc(1) not use TTY mode.
1210
1211    This environment variable overrides the default, which can be queried with
1212    the **-h** or **-\-help** options.
1213
1214**DC_PROMPT**
1215
1216:   If TTY mode is *not* available (see the **TTY MODE** section), then this
1217    environment variable has no effect.
1218
1219    However, when TTY mode is available, then if this environment variable
1220    exists and contains an integer, a non-zero value makes dc(1) use a prompt,
1221    and zero or a non-integer makes dc(1) not use a prompt. If this environment
1222    variable does not exist and **DC_TTY_MODE** does, then the value of the
1223    **DC_TTY_MODE** environment variable is used.
1224
1225    This environment variable and the **DC_TTY_MODE** environment variable
1226    override the default, which can be queried with the **-h** or **-\-help**
1227    options.
1228
1229**DC_EXPR_EXIT**
1230
1231:   If any expressions or expression files are given on the command-line with
1232    **-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
1233    variable exists and contains an integer, a non-zero value makes dc(1) exit
1234    after executing the expressions and expression files, and a zero value makes
1235    dc(1) not exit.
1236
1237    This environment variable overrides the default, which can be queried with
1238    the **-h** or **-\-help** options.
1239
1240# EXIT STATUS
1241
1242dc(1) returns the following exit statuses:
1243
1244**0**
1245
1246:   No error.
1247
1248**1**
1249
1250:   A math error occurred. This follows standard practice of using **1** for
1251    expected errors, since math errors will happen in the process of normal
1252    execution.
1253
1254    Math errors include divide by **0**, taking the square root of a negative
1255    number, using a negative number as a bound for the pseudo-random number
1256    generator, attempting to convert a negative number to a hardware integer,
1257    overflow when converting a number to a hardware integer, overflow when
1258    calculating the size of a number, and attempting to use a non-integer where
1259    an integer is required.
1260
1261    Converting to a hardware integer happens for the second operand of the power
1262    (**\^**), places (**\@**), left shift (**H**), and right shift (**h**)
1263    operators.
1264
1265**2**
1266
1267:   A parse error occurred.
1268
1269    Parse errors include unexpected **EOF**, using an invalid character, failing
1270    to find the end of a string or comment, and using a token where it is
1271    invalid.
1272
1273**3**
1274
1275:   A runtime error occurred.
1276
1277    Runtime errors include assigning an invalid number to any global (**ibase**,
1278    **obase**, or **scale**), giving a bad expression to a **read()** call,
1279    calling **read()** inside of a **read()** call, type errors (including
1280    attempting to execute a number), and attempting an operation when the stack
1281    has too few elements.
1282
1283**4**
1284
1285:   A fatal error occurred.
1286
1287    Fatal errors include memory allocation errors, I/O errors, failing to open
1288    files, attempting to use files that do not have only ASCII characters (dc(1)
1289    only accepts ASCII characters), attempting to open a directory as a file,
1290    and giving invalid command-line options.
1291
1292The exit status **4** is special; when a fatal error occurs, dc(1) always exits
1293and returns **4**, no matter what mode dc(1) is in.
1294
1295The other statuses will only be returned when dc(1) is not in interactive mode
1296(see the **INTERACTIVE MODE** section), since dc(1) resets its state (see the
1297**RESET** section) and accepts more input when one of those errors occurs in
1298interactive mode. This is also the case when interactive mode is forced by the
1299**-i** flag or **-\-interactive** option.
1300
1301These exit statuses allow dc(1) to be used in shell scripting with error
1302checking, and its normal behavior can be forced by using the **-i** flag or
1303**-\-interactive** option.
1304
1305# INTERACTIVE MODE
1306
1307Like bc(1), dc(1) has an interactive mode and a non-interactive mode.
1308Interactive mode is turned on automatically when both **stdin** and **stdout**
1309are hooked to a terminal, but the **-i** flag and **-\-interactive** option can
1310turn it on in other situations.
1311
1312In interactive mode, dc(1) attempts to recover from errors (see the **RESET**
1313section), and in normal execution, flushes **stdout** as soon as execution is
1314done for the current input. dc(1) may also reset on **SIGINT** instead of exit,
1315depending on the contents of, or default for, the **DC_SIGINT_RESET**
1316environment variable (see the **ENVIRONMENT VARIABLES** section).
1317
1318# TTY MODE
1319
1320If **stdin**, **stdout**, and **stderr** are all connected to a TTY, then "TTY
1321mode" is considered to be available, and thus, dc(1) can turn on TTY mode,
1322subject to some settings.
1323
1324If there is the environment variable **DC_TTY_MODE** in the environment (see the
1325**ENVIRONMENT VARIABLES** section), then if that environment variable contains a
1326non-zero integer, dc(1) will turn on TTY mode when **stdin**, **stdout**, and
1327**stderr** are all connected to a TTY. If the **DC_TTY_MODE** environment
1328variable exists but is *not* a non-zero integer, then dc(1) will not turn TTY
1329mode on.
1330
1331If the environment variable **DC_TTY_MODE** does *not* exist, the default
1332setting is used. The default setting can be queried with the **-h** or
1333**-\-help** options.
1334
1335TTY mode is different from interactive mode because interactive mode is required
1336in the bc(1) specification at
1337https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html , and
1338interactive mode requires only **stdin** and **stdout** to be connected to a
1339terminal.
1340
1341## Command-Line History
1342
1343Command-line history is only enabled if TTY mode is, i.e., that **stdin**,
1344**stdout**, and **stderr** are connected to a TTY and the **DC_TTY_MODE**
1345environment variable (see the **ENVIRONMENT VARIABLES** section) and its default
1346do not disable TTY mode. See the **COMMAND LINE HISTORY** section for more
1347information.
1348
1349## Prompt
1350
1351If TTY mode is available, then a prompt can be enabled. Like TTY mode itself, it
1352can be turned on or off with an environment variable: **DC_PROMPT** (see the
1353**ENVIRONMENT VARIABLES** section).
1354
1355If the environment variable **DC_PROMPT** exists and is a non-zero integer, then
1356the prompt is turned on when **stdin**, **stdout**, and **stderr** are connected
1357to a TTY and the **-P** and **-\-no-prompt** options were not used. The read
1358prompt will be turned on under the same conditions, except that the **-R** and
1359**-\-no-read-prompt** options must also not be used.
1360
1361However, if **DC_PROMPT** does not exist, the prompt can be enabled or disabled
1362with the **DC_TTY_MODE** environment variable, the **-P** and **-\-no-prompt**
1363options, and the **-R** and **-\-no-read-prompt** options. See the **ENVIRONMENT
1364VARIABLES** and **OPTIONS** sections for more details.
1365
1366# SIGNAL HANDLING
1367
1368Sending a **SIGINT** will cause dc(1) to do one of two things.
1369
1370If dc(1) is not in interactive mode (see the **INTERACTIVE MODE** section), or
1371the **DC_SIGINT_RESET** environment variable (see the **ENVIRONMENT VARIABLES**
1372section), or its default, is either not an integer or it is zero, dc(1) will
1373exit.
1374
1375However, if dc(1) is in interactive mode, and the **DC_SIGINT_RESET** or its
1376default is an integer and non-zero, then dc(1) will stop executing the current
1377input and reset (see the **RESET** section) upon receiving a **SIGINT**.
1378
1379Note that "current input" can mean one of two things. If dc(1) is processing
1380input from **stdin** in interactive mode, it will ask for more input. If dc(1)
1381is processing input from a file in interactive mode, it will stop processing the
1382file and start processing the next file, if one exists, or ask for input from
1383**stdin** if no other file exists.
1384
1385This means that if a **SIGINT** is sent to dc(1) as it is executing a file, it
1386can seem as though dc(1) did not respond to the signal since it will immediately
1387start executing the next file. This is by design; most files that users execute
1388when interacting with dc(1) have function definitions, which are quick to parse.
1389If a file takes a long time to execute, there may be a bug in that file. The
1390rest of the files could still be executed without problem, allowing the user to
1391continue.
1392
1393**SIGTERM** and **SIGQUIT** cause dc(1) to clean up and exit, and it uses the
1394default handler for all other signals. The one exception is **SIGHUP**; in that
1395case, and only when dc(1) is in TTY mode (see the **TTY MODE** section), a
1396**SIGHUP** will cause dc(1) to clean up and exit.
1397
1398# COMMAND LINE HISTORY
1399
1400dc(1) supports interactive command-line editing.
1401
1402If dc(1) can be in TTY mode (see the **TTY MODE** section), history can be
1403enabled. This means that command-line history can only be enabled when
1404**stdin**, **stdout**, and **stderr** are all connected to a TTY.
1405
1406Like TTY mode itself, it can be turned on or off with the environment variable
1407**DC_TTY_MODE** (see the **ENVIRONMENT VARIABLES** section).
1408
1409**Note**: tabs are converted to 8 spaces.
1410
1411# LOCALES
1412
1413This dc(1) ships with support for adding error messages for different locales
1414and thus, supports **LC_MESSAGES**.
1415
1416# SEE ALSO
1417
1418bc(1)
1419
1420# STANDARDS
1421
1422The dc(1) utility operators are compliant with the operators in the IEEE Std
14231003.1-2017 (“POSIX.1-2017”) specification at
1424https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1).
1425
1426# BUGS
1427
1428None are known. Report bugs at https://git.yzena.com/gavin/bc.
1429
1430# AUTHOR
1431
1432Gavin D. Howard <gavin@yzena.com> and contributors.
1433