xref: /freebsd/contrib/bc/manuals/dc/H.1.md (revision 12e0d316644a4f80f5f1f78cf07bd93def43b1ca)
13aa99676SStefan Eßer<!---
23aa99676SStefan Eßer
33aa99676SStefan EßerSPDX-License-Identifier: BSD-2-Clause
43aa99676SStefan Eßer
5a970610aSStefan EßerCopyright (c) 2018-2024 Gavin D. Howard and contributors.
63aa99676SStefan Eßer
73aa99676SStefan EßerRedistribution and use in source and binary forms, with or without
83aa99676SStefan Eßermodification, are permitted provided that the following conditions are met:
93aa99676SStefan Eßer
103aa99676SStefan Eßer* Redistributions of source code must retain the above copyright notice, this
113aa99676SStefan Eßer  list of conditions and the following disclaimer.
123aa99676SStefan Eßer
133aa99676SStefan Eßer* Redistributions in binary form must reproduce the above copyright notice,
143aa99676SStefan Eßer  this list of conditions and the following disclaimer in the documentation
153aa99676SStefan Eßer  and/or other materials provided with the distribution.
163aa99676SStefan Eßer
173aa99676SStefan EßerTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
183aa99676SStefan EßerAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
193aa99676SStefan EßerIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
203aa99676SStefan EßerARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
213aa99676SStefan EßerLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
223aa99676SStefan EßerCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
233aa99676SStefan EßerSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
243aa99676SStefan EßerINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
253aa99676SStefan EßerCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
263aa99676SStefan EßerARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
273aa99676SStefan EßerPOSSIBILITY OF SUCH DAMAGE.
283aa99676SStefan Eßer
293aa99676SStefan Eßer-->
303aa99676SStefan Eßer
313aa99676SStefan Eßer# Name
323aa99676SStefan Eßer
3350696a6eSStefan Eßerdc - arbitrary-precision decimal reverse-Polish notation calculator
343aa99676SStefan Eßer
353aa99676SStefan Eßer# SYNOPSIS
363aa99676SStefan Eßer
37d101cdd6SStefan Eßer**dc** [**-cChiPRvVx**] [**-\-version**] [**-\-help**] [**-\-digit-clamp**] [**-\-no-digit-clamp**] [**-\-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*]
383aa99676SStefan Eßer
393aa99676SStefan Eßer# DESCRIPTION
403aa99676SStefan Eßer
413aa99676SStefan Eßerdc(1) is an arbitrary-precision calculator. It uses a stack (reverse Polish
423aa99676SStefan Eßernotation) to store numbers and results of computations. Arithmetic operations
433aa99676SStefan Eßerpop arguments off of the stack and push the results.
443aa99676SStefan Eßer
4544d4804dSStefan EßerIf no files are given on the command-line, then dc(1) reads from **stdin** (see
4644d4804dSStefan Eßerthe **STDIN** section). Otherwise, those files are processed, and dc(1) will
4744d4804dSStefan Eßerthen exit.
483aa99676SStefan Eßer
4944d4804dSStefan EßerIf a user wants to set up a standard environment, they can use **DC_ENV_ARGS**
5044d4804dSStefan Eßer(see the **ENVIRONMENT VARIABLES** section). For example, if a user wants the
5144d4804dSStefan Eßer**scale** always set to **10**, they can set **DC_ENV_ARGS** to **-e 10k**, and
5244d4804dSStefan Eßerthis dc(1) will always start with a **scale** of **10**.
533aa99676SStefan Eßer
543aa99676SStefan Eßer# OPTIONS
553aa99676SStefan Eßer
563aa99676SStefan EßerThe following are the options that dc(1) accepts.
573aa99676SStefan Eßer
58d101cdd6SStefan Eßer**-C**, **-\-no-digit-clamp**
593aa99676SStefan Eßer
60d101cdd6SStefan Eßer:   Disables clamping of digits greater than or equal to the current **ibase**
61d101cdd6SStefan Eßer    when parsing numbers.
623aa99676SStefan Eßer
63d101cdd6SStefan Eßer    This means that the value added to a number from a digit is always that
64d101cdd6SStefan Eßer    digit's value multiplied by the value of ibase raised to the power of the
65d101cdd6SStefan Eßer    digit's position, which starts from 0 at the least significant digit.
663aa99676SStefan Eßer
67d101cdd6SStefan Eßer    If this and/or the **-c** or **-\-digit-clamp** options are given multiple
68d101cdd6SStefan Eßer    times, the last one given is used.
693aa99676SStefan Eßer
70d101cdd6SStefan Eßer    This option overrides the **DC_DIGIT_CLAMP** environment variable (see the
71d101cdd6SStefan Eßer    **ENVIRONMENT VARIABLES** section) and the default, which can be queried
72d101cdd6SStefan Eßer    with the **-h** or **-\-help** options.
733aa99676SStefan Eßer
743aa99676SStefan Eßer    This is a **non-portable extension**.
753aa99676SStefan Eßer
76d101cdd6SStefan Eßer**-c**, **-\-digit-clamp**
77d43fa8efSStefan Eßer
78d101cdd6SStefan Eßer:   Enables clamping of digits greater than or equal to the current **ibase**
79d101cdd6SStefan Eßer    when parsing numbers.
80d101cdd6SStefan Eßer
81d101cdd6SStefan Eßer    This means that digits that the value added to a number from a digit that is
82d101cdd6SStefan Eßer    greater than or equal to the ibase is the value of ibase minus 1 all
83d101cdd6SStefan Eßer    multiplied by the value of ibase raised to the power of the digit's
84d101cdd6SStefan Eßer    position, which starts from 0 at the least significant digit.
85d101cdd6SStefan Eßer
86d101cdd6SStefan Eßer    If this and/or the **-C** or **-\-no-digit-clamp** options are given
87d101cdd6SStefan Eßer    multiple times, the last one given is used.
88d101cdd6SStefan Eßer
89d101cdd6SStefan Eßer    This option overrides the **DC_DIGIT_CLAMP** environment variable (see the
90d101cdd6SStefan Eßer    **ENVIRONMENT VARIABLES** section) and the default, which can be queried
91d101cdd6SStefan Eßer    with the **-h** or **-\-help** options.
92d43fa8efSStefan Eßer
93d43fa8efSStefan Eßer    This is a **non-portable extension**.
94d43fa8efSStefan Eßer
95d101cdd6SStefan Eßer**-E** *seed*, **-\-seed**=*seed*
963aa99676SStefan Eßer
97d101cdd6SStefan Eßer:   Sets the builtin variable **seed** to the value *seed* assuming that *seed*
98d101cdd6SStefan Eßer    is in base 10. It is a fatal error if *seed* is not a valid number.
993aa99676SStefan Eßer
100d101cdd6SStefan Eßer    If multiple instances of this option are given, the last is used.
101d43fa8efSStefan Eßer
102d43fa8efSStefan Eßer    This is a **non-portable extension**.
103d43fa8efSStefan Eßer
104028616d0SStefan Eßer**-e** *expr*, **-\-expression**=*expr*
1053aa99676SStefan Eßer
1063aa99676SStefan Eßer:   Evaluates *expr*. If multiple expressions are given, they are evaluated in
1073aa99676SStefan Eßer    order. If files are given as well (see below), the expressions and files are
1083aa99676SStefan Eßer    evaluated in the order given. This means that if a file is given before an
1093aa99676SStefan Eßer    expression, the file is read in and evaluated first.
1103aa99676SStefan Eßer
1119a995fe1SStefan Eßer    If this option is given on the command-line (i.e., not in **DC_ENV_ARGS**,
1129a995fe1SStefan Eßer    see the **ENVIRONMENT VARIABLES** section), then after processing all
1139a995fe1SStefan Eßer    expressions and files, dc(1) will exit, unless **-** (**stdin**) was given
114028616d0SStefan Eßer    as an argument at least once to **-f** or **-\-file**, whether on the
1159a995fe1SStefan Eßer    command-line or in **DC_ENV_ARGS**. However, if any other **-e**,
116028616d0SStefan Eßer    **-\-expression**, **-f**, or **-\-file** arguments are given after **-f-**
117028616d0SStefan Eßer    or equivalent is given, dc(1) will give a fatal error and exit.
1183aa99676SStefan Eßer
1193aa99676SStefan Eßer    This is a **non-portable extension**.
1203aa99676SStefan Eßer
121028616d0SStefan Eßer**-f** *file*, **-\-file**=*file*
1223aa99676SStefan Eßer
1233aa99676SStefan Eßer:   Reads in *file* and evaluates it, line by line, as though it were read
1243aa99676SStefan Eßer    through **stdin**. If expressions are also given (see above), the
1253aa99676SStefan Eßer    expressions are evaluated in the order given.
1263aa99676SStefan Eßer
1279a995fe1SStefan Eßer    If this option is given on the command-line (i.e., not in **DC_ENV_ARGS**,
1289a995fe1SStefan Eßer    see the **ENVIRONMENT VARIABLES** section), then after processing all
1299a995fe1SStefan Eßer    expressions and files, dc(1) will exit, unless **-** (**stdin**) was given
130028616d0SStefan Eßer    as an argument at least once to **-f** or **-\-file**. However, if any other
131028616d0SStefan Eßer    **-e**, **-\-expression**, **-f**, or **-\-file** arguments are given after
1329a995fe1SStefan Eßer    **-f-** or equivalent is given, dc(1) will give a fatal error and exit.
1333aa99676SStefan Eßer
1343aa99676SStefan Eßer    This is a **non-portable extension**.
1353aa99676SStefan Eßer
136d101cdd6SStefan Eßer**-h**, **-\-help**
137d101cdd6SStefan Eßer
138d101cdd6SStefan Eßer:   Prints a usage message and exits.
139d101cdd6SStefan Eßer
14078bc019dSStefan Eßer**-I** *ibase*, **-\-ibase**=*ibase*
14178bc019dSStefan Eßer
14278bc019dSStefan Eßer:   Sets the builtin variable **ibase** to the value *ibase* assuming that
14378bc019dSStefan Eßer    *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number.
14478bc019dSStefan Eßer
14578bc019dSStefan Eßer    If multiple instances of this option are given, the last is used.
14678bc019dSStefan Eßer
14778bc019dSStefan Eßer    This is a **non-portable extension**.
14878bc019dSStefan Eßer
149d101cdd6SStefan Eßer**-i**, **-\-interactive**
150d101cdd6SStefan Eßer
151d101cdd6SStefan Eßer:   Forces interactive mode. (See the **INTERACTIVE MODE** section.)
152d101cdd6SStefan Eßer
153d101cdd6SStefan Eßer    This is a **non-portable extension**.
154d101cdd6SStefan Eßer
155d101cdd6SStefan Eßer**-L**, **-\-no-line-length**
156d101cdd6SStefan Eßer
157d101cdd6SStefan Eßer:   Disables line length checking and prints numbers without backslashes and
158d101cdd6SStefan Eßer    newlines. In other words, this option sets **BC_LINE_LENGTH** to **0** (see
159d101cdd6SStefan Eßer    the **ENVIRONMENT VARIABLES** section).
160d101cdd6SStefan Eßer
161d101cdd6SStefan Eßer    This is a **non-portable extension**.
162d101cdd6SStefan Eßer
16378bc019dSStefan Eßer**-O** *obase*, **-\-obase**=*obase*
16478bc019dSStefan Eßer
16578bc019dSStefan Eßer:   Sets the builtin variable **obase** to the value *obase* assuming that
16678bc019dSStefan Eßer    *obase* is in base 10. It is a fatal error if *obase* is not a valid number.
16778bc019dSStefan Eßer
16878bc019dSStefan Eßer    If multiple instances of this option are given, the last is used.
16978bc019dSStefan Eßer
17078bc019dSStefan Eßer    This is a **non-portable extension**.
17178bc019dSStefan Eßer
172d101cdd6SStefan Eßer**-P**, **-\-no-prompt**
173d101cdd6SStefan Eßer
174d101cdd6SStefan Eßer:   Disables the prompt in TTY mode. (The prompt is only enabled in TTY mode.
175d101cdd6SStefan Eßer    See the **TTY MODE** section.) This is mostly for those users that do not
176d101cdd6SStefan Eßer    want a prompt or are not used to having them in dc(1). Most of those users
177d101cdd6SStefan Eßer    would want to put this option in **DC_ENV_ARGS**.
178d101cdd6SStefan Eßer
179d101cdd6SStefan Eßer    These options override the **DC_PROMPT** and **DC_TTY_MODE** environment
180d101cdd6SStefan Eßer    variables (see the **ENVIRONMENT VARIABLES** section).
181d101cdd6SStefan Eßer
182d101cdd6SStefan Eßer    This is a **non-portable extension**.
183d101cdd6SStefan Eßer
184d101cdd6SStefan Eßer**-R**, **-\-no-read-prompt**
185d101cdd6SStefan Eßer
186d101cdd6SStefan Eßer:   Disables the read prompt in TTY mode. (The read prompt is only enabled in
187d101cdd6SStefan Eßer    TTY mode. See the **TTY MODE** section.) This is mostly for those users that
188d101cdd6SStefan Eßer    do not want a read prompt or are not used to having them in dc(1). Most of
189d101cdd6SStefan Eßer    those users would want to put this option in **BC_ENV_ARGS** (see the
190d101cdd6SStefan Eßer    **ENVIRONMENT VARIABLES** section). This option is also useful in hash bang
191d101cdd6SStefan Eßer    lines of dc(1) scripts that prompt for user input.
192d101cdd6SStefan Eßer
193d101cdd6SStefan Eßer    This option does not disable the regular prompt because the read prompt is
194d101cdd6SStefan Eßer    only used when the **?** command is used.
195d101cdd6SStefan Eßer
196d101cdd6SStefan Eßer    These options *do* override the **DC_PROMPT** and **DC_TTY_MODE**
197d101cdd6SStefan Eßer    environment variables (see the **ENVIRONMENT VARIABLES** section), but only
198d101cdd6SStefan Eßer    for the read prompt.
199d101cdd6SStefan Eßer
200d101cdd6SStefan Eßer    This is a **non-portable extension**.
201d101cdd6SStefan Eßer
20278bc019dSStefan Eßer**-S** *scale*, **-\-scale**=*scale*
20378bc019dSStefan Eßer
20478bc019dSStefan Eßer:   Sets the builtin variable **scale** to the value *scale* assuming that
20578bc019dSStefan Eßer    *scale* is in base 10. It is a fatal error if *scale* is not a valid number.
20678bc019dSStefan Eßer
20778bc019dSStefan Eßer    If multiple instances of this option are given, the last is used.
20878bc019dSStefan Eßer
20978bc019dSStefan Eßer    This is a **non-portable extension**.
21078bc019dSStefan Eßer
211d101cdd6SStefan Eßer**-v**, **-V**, **-\-version**
21278bc019dSStefan Eßer
213d101cdd6SStefan Eßer:   Print the version information (copyright header) and exits.
21478bc019dSStefan Eßer
215d101cdd6SStefan Eßer**-x** **-\-extended-register**
216d101cdd6SStefan Eßer
217d101cdd6SStefan Eßer:   Enables extended register mode. See the *Extended Register Mode* subsection
218d101cdd6SStefan Eßer    of the **REGISTERS** section for more information.
219d101cdd6SStefan Eßer
220d101cdd6SStefan Eßer    This is a **non-portable extension**.
221d101cdd6SStefan Eßer
222d101cdd6SStefan Eßer**-z**, **-\-leading-zeroes**
223d101cdd6SStefan Eßer
224d101cdd6SStefan Eßer:   Makes dc(1) print all numbers greater than **-1** and less than **1**, and
225d101cdd6SStefan Eßer    not equal to **0**, with a leading zero.
226d101cdd6SStefan Eßer
22778bc019dSStefan Eßer    This is a **non-portable extension**.
22878bc019dSStefan Eßer
2293aa99676SStefan EßerAll long options are **non-portable extensions**.
2303aa99676SStefan Eßer
23144d4804dSStefan Eßer# STDIN
23244d4804dSStefan Eßer
23344d4804dSStefan EßerIf no files are given on the command-line and no files or expressions are given
23444d4804dSStefan Eßerby the **-f**, **-\-file**, **-e**, or **-\-expression** options, then dc(1)
23578bc019dSStefan Eßerreads from **stdin**.
23644d4804dSStefan Eßer
23744d4804dSStefan EßerHowever, there is a caveat to this.
23844d4804dSStefan Eßer
23944d4804dSStefan EßerFirst, **stdin** is evaluated a line at a time. The only exception to this is if
24044d4804dSStefan Eßera string has been finished, but not ended. This means that, except for escaped
24144d4804dSStefan Eßerbrackets, all brackets must be balanced before dc(1) parses and executes.
24244d4804dSStefan Eßer
2433aa99676SStefan Eßer# STDOUT
2443aa99676SStefan Eßer
2459a995fe1SStefan EßerAny non-error output is written to **stdout**. In addition, if history (see the
2469a995fe1SStefan Eßer**HISTORY** section) and the prompt (see the **TTY MODE** section) are enabled,
2479a995fe1SStefan Eßerboth are output to **stdout**.
2483aa99676SStefan Eßer
2493aa99676SStefan Eßer**Note**: Unlike other dc(1) implementations, this dc(1) will issue a fatal
2503aa99676SStefan Eßererror (see the **EXIT STATUS** section) if it cannot write to **stdout**, so if
2513aa99676SStefan Eßer**stdout** is closed, as in **dc <file> >&-**, it will quit with an error. This
2523aa99676SStefan Eßeris done so that dc(1) can report problems when **stdout** is redirected to a
2533aa99676SStefan Eßerfile.
2543aa99676SStefan Eßer
2553aa99676SStefan EßerIf there are scripts that depend on the behavior of other dc(1) implementations,
2563aa99676SStefan Eßerit is recommended that those scripts be changed to redirect **stdout** to
2573aa99676SStefan Eßer**/dev/null**.
2583aa99676SStefan Eßer
2593aa99676SStefan Eßer# STDERR
2603aa99676SStefan Eßer
2613aa99676SStefan EßerAny error output is written to **stderr**.
2623aa99676SStefan Eßer
2633aa99676SStefan Eßer**Note**: Unlike other dc(1) implementations, this dc(1) will issue a fatal
2643aa99676SStefan Eßererror (see the **EXIT STATUS** section) if it cannot write to **stderr**, so if
2653aa99676SStefan Eßer**stderr** is closed, as in **dc <file> 2>&-**, it will quit with an error. This
2663aa99676SStefan Eßeris done so that dc(1) can exit with an error code when **stderr** is redirected
2673aa99676SStefan Eßerto a file.
2683aa99676SStefan Eßer
2693aa99676SStefan EßerIf there are scripts that depend on the behavior of other dc(1) implementations,
2703aa99676SStefan Eßerit is recommended that those scripts be changed to redirect **stderr** to
2713aa99676SStefan Eßer**/dev/null**.
2723aa99676SStefan Eßer
2733aa99676SStefan Eßer# SYNTAX
2743aa99676SStefan Eßer
2753aa99676SStefan EßerEach item in the input source code, either a number (see the **NUMBERS**
2763aa99676SStefan Eßersection) or a command (see the **COMMANDS** section), is processed and executed,
2773aa99676SStefan Eßerin order. Input is processed immediately when entered.
2783aa99676SStefan Eßer
2793aa99676SStefan Eßer**ibase** is a register (see the **REGISTERS** section) that determines how to
2803aa99676SStefan Eßerinterpret constant numbers. It is the "input" base, or the number base used for
2813aa99676SStefan Eßerinterpreting input numbers. **ibase** is initially **10**. The max allowable
2823aa99676SStefan Eßervalue for **ibase** is **16**. The min allowable value for **ibase** is **2**.
2833aa99676SStefan EßerThe max allowable value for **ibase** can be queried in dc(1) programs with the
2843aa99676SStefan Eßer**T** command.
2853aa99676SStefan Eßer
2863aa99676SStefan Eßer**obase** is a register (see the **REGISTERS** section) that determines how to
2873aa99676SStefan Eßeroutput results. It is the "output" base, or the number base used for outputting
2883aa99676SStefan Eßernumbers. **obase** is initially **10**. The max allowable value for **obase** is
2893aa99676SStefan Eßer**DC_BASE_MAX** and can be queried with the **U** command. The min allowable
2903aa99676SStefan Eßervalue for **obase** is **0**. If **obase** is **0**, values are output in
2913aa99676SStefan Eßerscientific notation, and if **obase** is **1**, values are output in engineering
2923aa99676SStefan Eßernotation. Otherwise, values are output in the specified base.
2933aa99676SStefan Eßer
2943aa99676SStefan EßerOutputting in scientific and engineering notations are **non-portable
2953aa99676SStefan Eßerextensions**.
2963aa99676SStefan Eßer
2973aa99676SStefan EßerThe *scale* of an expression is the number of digits in the result of the
2983aa99676SStefan Eßerexpression right of the decimal point, and **scale** is a register (see the
2993aa99676SStefan Eßer**REGISTERS** section) that sets the precision of any operations (with
3003aa99676SStefan Eßerexceptions). **scale** is initially **0**. **scale** cannot be negative. The max
3013aa99676SStefan Eßerallowable value for **scale** can be queried in dc(1) programs with the **V**
3023aa99676SStefan Eßercommand.
3033aa99676SStefan Eßer
3043aa99676SStefan Eßer**seed** is a register containing the current seed for the pseudo-random number
3053aa99676SStefan Eßergenerator. If the current value of **seed** is queried and stored, then if it is
3063aa99676SStefan Eßerassigned to **seed** later, the pseudo-random number generator is guaranteed to
3073aa99676SStefan Eßerproduce the same sequence of pseudo-random numbers that were generated after the
3083aa99676SStefan Eßervalue of **seed** was first queried.
3093aa99676SStefan Eßer
3103aa99676SStefan EßerMultiple values assigned to **seed** can produce the same sequence of
3113aa99676SStefan Eßerpseudo-random numbers. Likewise, when a value is assigned to **seed**, it is not
3123aa99676SStefan Eßerguaranteed that querying **seed** immediately after will return the same value.
3133aa99676SStefan EßerIn addition, the value of **seed** will change after any call to the **'**
3143aa99676SStefan Eßercommand or the **"** command that does not get receive a value of **0** or
3153aa99676SStefan Eßer**1**. The maximum integer returned by the **'** command can be queried with the
3163aa99676SStefan Eßer**W** command.
3173aa99676SStefan Eßer
3183aa99676SStefan Eßer**Note**: The values returned by the pseudo-random number generator with the
3193aa99676SStefan Eßer**'** and **"** commands are guaranteed to **NOT** be cryptographically secure.
3203aa99676SStefan EßerThis is a consequence of using a seeded pseudo-random number generator. However,
32110328f8bSStefan Eßerthey *are* guaranteed to be reproducible with identical **seed** values. This
3229a995fe1SStefan Eßermeans that the pseudo-random values from dc(1) should only be used where a
32310328f8bSStefan Eßerreproducible stream of pseudo-random numbers is *ESSENTIAL*. In any other case,
32410328f8bSStefan Eßeruse a non-seeded pseudo-random number generator.
3253aa99676SStefan Eßer
3263aa99676SStefan EßerThe pseudo-random number generator, **seed**, and all associated operations are
3273aa99676SStefan Eßer**non-portable extensions**.
3283aa99676SStefan Eßer
3293aa99676SStefan Eßer## Comments
3303aa99676SStefan Eßer
3313aa99676SStefan EßerComments go from **#** until, and not including, the next newline. This is a
3323aa99676SStefan Eßer**non-portable extension**.
3333aa99676SStefan Eßer
3343aa99676SStefan Eßer# NUMBERS
3353aa99676SStefan Eßer
3363aa99676SStefan EßerNumbers are strings made up of digits, uppercase letters up to **F**, and at
3373aa99676SStefan Eßermost **1** period for a radix. Numbers can have up to **DC_NUM_MAX** digits.
338d101cdd6SStefan EßerUppercase letters are equal to **9** plus their position in the alphabet (i.e.,
339d101cdd6SStefan Eßer**A** equals **10**, or **9+1**).
3403aa99676SStefan Eßer
341d101cdd6SStefan EßerIf a digit or letter makes no sense with the current value of **ibase** (i.e.,
342d101cdd6SStefan Eßerthey are greater than or equal to the current value of **ibase**), then the
343d101cdd6SStefan Eßerbehavior depends on the existence of the **-c**/**-\-digit-clamp** or
344d101cdd6SStefan Eßer**-C**/**-\-no-digit-clamp** options (see the **OPTIONS** section), the
345d101cdd6SStefan Eßerexistence and setting of the **DC_DIGIT_CLAMP** environment variable (see the
346d101cdd6SStefan Eßer**ENVIRONMENT VARIABLES** section), or the default, which can be queried with
347d101cdd6SStefan Eßerthe **-h**/**-\-help** option.
348d101cdd6SStefan Eßer
349d101cdd6SStefan EßerIf clamping is off, then digits or letters that are greater than or equal to the
350d101cdd6SStefan Eßercurrent value of **ibase** are not changed. Instead, their given value is
351d101cdd6SStefan Eßermultiplied by the appropriate power of **ibase** and added into the number. This
352d101cdd6SStefan Eßermeans that, with an **ibase** of **3**, the number **AB** is equal to
353d101cdd6SStefan Eßer**3\^1\*A+3\^0\*B**, which is **3** times **10** plus **11**, or **41**.
354d101cdd6SStefan Eßer
355d101cdd6SStefan EßerIf clamping is on, then digits or letters that are greater than or equal to the
356d101cdd6SStefan Eßercurrent value of **ibase** are set to the value of the highest valid digit in
357d101cdd6SStefan Eßer**ibase** before being multiplied by the appropriate power of **ibase** and
358d101cdd6SStefan Eßeradded into the number. This means that, with an **ibase** of **3**, the number
359d101cdd6SStefan Eßer**AB** is equal to **3\^1\*2+3\^0\*2**, which is **3** times **2** plus **2**,
360d101cdd6SStefan Eßeror **8**.
361d101cdd6SStefan Eßer
362d101cdd6SStefan EßerThere is one exception to clamping: single-character numbers (i.e., **A**
363d101cdd6SStefan Eßeralone). Such numbers are never clamped and always take the value they would have
364d101cdd6SStefan Eßerin the highest possible **ibase**. This means that **A** alone always equals
365d101cdd6SStefan Eßerdecimal **10** and **Z** alone always equals decimal **35**. This behavior is
366d101cdd6SStefan Eßermandated by the standard for bc(1) (see the STANDARDS section) and is meant to
367d101cdd6SStefan Eßerprovide an easy way to set the current **ibase** (with the **i** command)
368d101cdd6SStefan Eßerregardless of the current value of **ibase**.
369d101cdd6SStefan Eßer
370d101cdd6SStefan EßerIf clamping is on, and the clamped value of a character is needed, use a leading
371d101cdd6SStefan Eßerzero, i.e., for **A**, use **0A**.
3723aa99676SStefan Eßer
3733aa99676SStefan EßerIn addition, dc(1) accepts numbers in scientific notation. These have the form
37450696a6eSStefan Eßer**\<number\>e\<integer\>**. The exponent (the portion after the **e**) must be
37550696a6eSStefan Eßeran integer. An example is **1.89237e9**, which is equal to **1892370000**.
37650696a6eSStefan EßerNegative exponents are also allowed, so **4.2890e_3** is equal to **0.0042890**.
3773aa99676SStefan Eßer
3783aa99676SStefan Eßer**WARNING**: Both the number and the exponent in scientific notation are
3793aa99676SStefan Eßerinterpreted according to the current **ibase**, but the number is still
3803aa99676SStefan Eßermultiplied by **10\^exponent** regardless of the current **ibase**. For example,
3813aa99676SStefan Eßerif **ibase** is **16** and dc(1) is given the number string **FFeA**, the
3823aa99676SStefan Eßerresulting decimal number will be **2550000000000**, and if dc(1) is given the
3833aa99676SStefan Eßernumber string **10e_4**, the resulting decimal number will be **0.0016**.
3843aa99676SStefan Eßer
3853aa99676SStefan EßerAccepting input as scientific notation is a **non-portable extension**.
3863aa99676SStefan Eßer
3873aa99676SStefan Eßer# COMMANDS
3883aa99676SStefan Eßer
3893aa99676SStefan EßerThe valid commands are listed below.
3903aa99676SStefan Eßer
3913aa99676SStefan Eßer## Printing
3923aa99676SStefan Eßer
3933aa99676SStefan EßerThese commands are used for printing.
3943aa99676SStefan Eßer
3953aa99676SStefan EßerNote that both scientific notation and engineering notation are available for
3963aa99676SStefan Eßerprinting numbers. Scientific notation is activated by assigning **0** to
3973aa99676SStefan Eßer**obase** using **0o**, and engineering notation is activated by assigning **1**
3983aa99676SStefan Eßerto **obase** using **1o**. To deactivate them, just assign a different value to
3993aa99676SStefan Eßer**obase**.
4003aa99676SStefan Eßer
4013aa99676SStefan EßerPrinting numbers in scientific notation and/or engineering notation is a
4023aa99676SStefan Eßer**non-portable extension**.
4033aa99676SStefan Eßer
4043aa99676SStefan Eßer**p**
4053aa99676SStefan Eßer
4063aa99676SStefan Eßer:   Prints the value on top of the stack, whether number or string, and prints a
4073aa99676SStefan Eßer    newline after.
4083aa99676SStefan Eßer
4093aa99676SStefan Eßer    This does not alter the stack.
4103aa99676SStefan Eßer
4113aa99676SStefan Eßer**n**
4123aa99676SStefan Eßer
4133aa99676SStefan Eßer:   Prints the value on top of the stack, whether number or string, and pops it
4143aa99676SStefan Eßer    off of the stack.
4153aa99676SStefan Eßer
4163aa99676SStefan Eßer**P**
4173aa99676SStefan Eßer
4183aa99676SStefan Eßer:   Pops a value off the stack.
4193aa99676SStefan Eßer
4203aa99676SStefan Eßer    If the value is a number, it is truncated and the absolute value of the
42144d4804dSStefan Eßer    result is printed as though **obase** is **256** and each digit is
42244d4804dSStefan Eßer    interpreted as an 8-bit ASCII character, making it a byte stream.
4233aa99676SStefan Eßer
4243aa99676SStefan Eßer    If the value is a string, it is printed without a trailing newline.
4253aa99676SStefan Eßer
4263aa99676SStefan Eßer    This is a **non-portable extension**.
4273aa99676SStefan Eßer
4283aa99676SStefan Eßer**f**
4293aa99676SStefan Eßer
4303aa99676SStefan Eßer:   Prints the entire contents of the stack, in order from newest to oldest,
4313aa99676SStefan Eßer    without altering anything.
4323aa99676SStefan Eßer
4333aa99676SStefan Eßer    Users should use this command when they get lost.
4343aa99676SStefan Eßer
4353aa99676SStefan Eßer## Arithmetic
4363aa99676SStefan Eßer
4373aa99676SStefan EßerThese are the commands used for arithmetic.
4383aa99676SStefan Eßer
4393aa99676SStefan Eßer**+**
4403aa99676SStefan Eßer
4413aa99676SStefan Eßer:   The top two values are popped off the stack, added, and the result is pushed
4423aa99676SStefan Eßer    onto the stack. The *scale* of the result is equal to the max *scale* of
4433aa99676SStefan Eßer    both operands.
4443aa99676SStefan Eßer
4453aa99676SStefan Eßer**-**
4463aa99676SStefan Eßer
4473aa99676SStefan Eßer:   The top two values are popped off the stack, subtracted, and the result is
4483aa99676SStefan Eßer    pushed onto the stack. The *scale* of the result is equal to the max
4493aa99676SStefan Eßer    *scale* of both operands.
4503aa99676SStefan Eßer
4513aa99676SStefan Eßer**\***
4523aa99676SStefan Eßer
4533aa99676SStefan Eßer:   The top two values are popped off the stack, multiplied, and the result is
4543aa99676SStefan Eßer    pushed onto the stack. If **a** is the *scale* of the first expression and
4553aa99676SStefan Eßer    **b** is the *scale* of the second expression, the *scale* of the result
4563aa99676SStefan Eßer    is equal to **min(a+b,max(scale,a,b))** where **min()** and **max()** return
4573aa99676SStefan Eßer    the obvious values.
4583aa99676SStefan Eßer
4593aa99676SStefan Eßer**/**
4603aa99676SStefan Eßer
4613aa99676SStefan Eßer:   The top two values are popped off the stack, divided, and the result is
4623aa99676SStefan Eßer    pushed onto the stack. The *scale* of the result is equal to **scale**.
4633aa99676SStefan Eßer
4643aa99676SStefan Eßer    The first value popped off of the stack must be non-zero.
4653aa99676SStefan Eßer
4663aa99676SStefan Eßer**%**
4673aa99676SStefan Eßer
4683aa99676SStefan Eßer:   The top two values are popped off the stack, remaindered, and the result is
4693aa99676SStefan Eßer    pushed onto the stack.
4703aa99676SStefan Eßer
4713aa99676SStefan Eßer    Remaindering is equivalent to 1) Computing **a/b** to current **scale**, and
4723aa99676SStefan Eßer    2) Using the result of step 1 to calculate **a-(a/b)\*b** to *scale*
4733aa99676SStefan Eßer    **max(scale+scale(b),scale(a))**.
4743aa99676SStefan Eßer
4753aa99676SStefan Eßer    The first value popped off of the stack must be non-zero.
4763aa99676SStefan Eßer
4773aa99676SStefan Eßer**~**
4783aa99676SStefan Eßer
4793aa99676SStefan Eßer:   The top two values are popped off the stack, divided and remaindered, and
4803aa99676SStefan Eßer    the results (divided first, remainder second) are pushed onto the stack.
4813aa99676SStefan Eßer    This is equivalent to **x y / x y %** except that **x** and **y** are only
4823aa99676SStefan Eßer    evaluated once.
4833aa99676SStefan Eßer
4843aa99676SStefan Eßer    The first value popped off of the stack must be non-zero.
4853aa99676SStefan Eßer
4863aa99676SStefan Eßer    This is a **non-portable extension**.
4873aa99676SStefan Eßer
4883aa99676SStefan Eßer**\^**
4893aa99676SStefan Eßer
4903aa99676SStefan Eßer:   The top two values are popped off the stack, the second is raised to the
49150696a6eSStefan Eßer    power of the first, and the result is pushed onto the stack. The *scale* of
49250696a6eSStefan Eßer    the result is equal to **scale**.
4933aa99676SStefan Eßer
4943aa99676SStefan Eßer    The first value popped off of the stack must be an integer, and if that
4953aa99676SStefan Eßer    value is negative, the second value popped off of the stack must be
4963aa99676SStefan Eßer    non-zero.
4973aa99676SStefan Eßer
4983aa99676SStefan Eßer**v**
4993aa99676SStefan Eßer
5003aa99676SStefan Eßer:   The top value is popped off the stack, its square root is computed, and the
5013aa99676SStefan Eßer    result is pushed onto the stack. The *scale* of the result is equal to
5023aa99676SStefan Eßer    **scale**.
5033aa99676SStefan Eßer
5043aa99676SStefan Eßer    The value popped off of the stack must be non-negative.
5053aa99676SStefan Eßer
5063aa99676SStefan Eßer**\_**
5073aa99676SStefan Eßer
5083aa99676SStefan Eßer:   If this command *immediately* precedes a number (i.e., no spaces or other
5093aa99676SStefan Eßer    commands), then that number is input as a negative number.
5103aa99676SStefan Eßer
5113aa99676SStefan Eßer    Otherwise, the top value on the stack is popped and copied, and the copy is
5123aa99676SStefan Eßer    negated and pushed onto the stack. This behavior without a number is a
5133aa99676SStefan Eßer    **non-portable extension**.
5143aa99676SStefan Eßer
5153aa99676SStefan Eßer**b**
5163aa99676SStefan Eßer
5173aa99676SStefan Eßer:   The top value is popped off the stack, and if it is zero, it is pushed back
5183aa99676SStefan Eßer    onto the stack. Otherwise, its absolute value is pushed onto the stack.
5193aa99676SStefan Eßer
5203aa99676SStefan Eßer    This is a **non-portable extension**.
5213aa99676SStefan Eßer
5223aa99676SStefan Eßer**|**
5233aa99676SStefan Eßer
5243aa99676SStefan Eßer:   The top three values are popped off the stack, a modular exponentiation is
5253aa99676SStefan Eßer    computed, and the result is pushed onto the stack.
5263aa99676SStefan Eßer
5273aa99676SStefan Eßer    The first value popped is used as the reduction modulus and must be an
5283aa99676SStefan Eßer    integer and non-zero. The second value popped is used as the exponent and
5293aa99676SStefan Eßer    must be an integer and non-negative. The third value popped is the base and
5303aa99676SStefan Eßer    must be an integer.
5313aa99676SStefan Eßer
5323aa99676SStefan Eßer    This is a **non-portable extension**.
5333aa99676SStefan Eßer
5343aa99676SStefan Eßer**\$**
5353aa99676SStefan Eßer
5363aa99676SStefan Eßer:   The top value is popped off the stack and copied, and the copy is truncated
5373aa99676SStefan Eßer    and pushed onto the stack.
5383aa99676SStefan Eßer
5393aa99676SStefan Eßer    This is a **non-portable extension**.
5403aa99676SStefan Eßer
5413aa99676SStefan Eßer**\@**
5423aa99676SStefan Eßer
5433aa99676SStefan Eßer:   The top two values are popped off the stack, and the precision of the second
5443aa99676SStefan Eßer    is set to the value of the first, whether by truncation or extension.
5453aa99676SStefan Eßer
5463aa99676SStefan Eßer    The first value popped off of the stack must be an integer and non-negative.
5473aa99676SStefan Eßer
5483aa99676SStefan Eßer    This is a **non-portable extension**.
5493aa99676SStefan Eßer
5503aa99676SStefan Eßer**H**
5513aa99676SStefan Eßer
5523aa99676SStefan Eßer:   The top two values are popped off the stack, and the second is shifted left
5533aa99676SStefan Eßer    (radix shifted right) to the value of the first.
5543aa99676SStefan Eßer
5553aa99676SStefan Eßer    The first value popped off of the stack must be an integer and non-negative.
5563aa99676SStefan Eßer
5573aa99676SStefan Eßer    This is a **non-portable extension**.
5583aa99676SStefan Eßer
5593aa99676SStefan Eßer**h**
5603aa99676SStefan Eßer
5613aa99676SStefan Eßer:   The top two values are popped off the stack, and the second is shifted right
5623aa99676SStefan Eßer    (radix shifted left) to the value of the first.
5633aa99676SStefan Eßer
5643aa99676SStefan Eßer    The first value popped off of the stack must be an integer and non-negative.
5653aa99676SStefan Eßer
5663aa99676SStefan Eßer    This is a **non-portable extension**.
5673aa99676SStefan Eßer
5683aa99676SStefan Eßer**G**
5693aa99676SStefan Eßer
5703aa99676SStefan Eßer:   The top two values are popped off of the stack, they are compared, and a
5713aa99676SStefan Eßer    **1** is pushed if they are equal, or **0** otherwise.
5723aa99676SStefan Eßer
5733aa99676SStefan Eßer    This is a **non-portable extension**.
5743aa99676SStefan Eßer
5753aa99676SStefan Eßer**N**
5763aa99676SStefan Eßer
5773aa99676SStefan Eßer:   The top value is popped off of the stack, and if it a **0**, a **1** is
5783aa99676SStefan Eßer    pushed; otherwise, a **0** is pushed.
5793aa99676SStefan Eßer
5803aa99676SStefan Eßer    This is a **non-portable extension**.
5813aa99676SStefan Eßer
5823aa99676SStefan Eßer**(**
5833aa99676SStefan Eßer
5843aa99676SStefan Eßer:   The top two values are popped off of the stack, they are compared, and a
5853aa99676SStefan Eßer    **1** is pushed if the first is less than the second, or **0** otherwise.
5863aa99676SStefan Eßer
5873aa99676SStefan Eßer    This is a **non-portable extension**.
5883aa99676SStefan Eßer
5893aa99676SStefan Eßer**{**
5903aa99676SStefan Eßer
5913aa99676SStefan Eßer:   The top two values are popped off of the stack, they are compared, and a
5923aa99676SStefan Eßer    **1** is pushed if the first is less than or equal to the second, or **0**
5933aa99676SStefan Eßer    otherwise.
5943aa99676SStefan Eßer
5953aa99676SStefan Eßer    This is a **non-portable extension**.
5963aa99676SStefan Eßer
5973aa99676SStefan Eßer**)**
5983aa99676SStefan Eßer
5993aa99676SStefan Eßer:   The top two values are popped off of the stack, they are compared, and a
6003aa99676SStefan Eßer    **1** is pushed if the first is greater than the second, or **0** otherwise.
6013aa99676SStefan Eßer
6023aa99676SStefan Eßer    This is a **non-portable extension**.
6033aa99676SStefan Eßer
6043aa99676SStefan Eßer**}**
6053aa99676SStefan Eßer
6063aa99676SStefan Eßer:   The top two values are popped off of the stack, they are compared, and a
6073aa99676SStefan Eßer    **1** is pushed if the first is greater than or equal to the second, or
6083aa99676SStefan Eßer    **0** otherwise.
6093aa99676SStefan Eßer
6103aa99676SStefan Eßer    This is a **non-portable extension**.
6113aa99676SStefan Eßer
6123aa99676SStefan Eßer**M**
6133aa99676SStefan Eßer
6143aa99676SStefan Eßer:   The top two values are popped off of the stack. If they are both non-zero, a
6153aa99676SStefan Eßer    **1** is pushed onto the stack. If either of them is zero, or both of them
6163aa99676SStefan Eßer    are, then a **0** is pushed onto the stack.
6173aa99676SStefan Eßer
6183aa99676SStefan Eßer    This is like the **&&** operator in bc(1), and it is *not* a short-circuit
6193aa99676SStefan Eßer    operator.
6203aa99676SStefan Eßer
6213aa99676SStefan Eßer    This is a **non-portable extension**.
6223aa99676SStefan Eßer
6233aa99676SStefan Eßer**m**
6243aa99676SStefan Eßer
6253aa99676SStefan Eßer:   The top two values are popped off of the stack. If at least one of them is
6263aa99676SStefan Eßer    non-zero, a **1** is pushed onto the stack. If both of them are zero, then a
6273aa99676SStefan Eßer    **0** is pushed onto the stack.
6283aa99676SStefan Eßer
6293aa99676SStefan Eßer    This is like the **||** operator in bc(1), and it is *not* a short-circuit
6303aa99676SStefan Eßer    operator.
6313aa99676SStefan Eßer
6323aa99676SStefan Eßer    This is a **non-portable extension**.
6333aa99676SStefan Eßer
6343aa99676SStefan Eßer## Pseudo-Random Number Generator
6353aa99676SStefan Eßer
6363aa99676SStefan Eßerdc(1) has a built-in pseudo-random number generator. These commands query the
6373aa99676SStefan Eßerpseudo-random number generator. (See Parameters for more information about the
6383aa99676SStefan Eßer**seed** value that controls the pseudo-random number generator.)
6393aa99676SStefan Eßer
6403aa99676SStefan EßerThe pseudo-random number generator is guaranteed to **NOT** be
6413aa99676SStefan Eßercryptographically secure.
6423aa99676SStefan Eßer
6433aa99676SStefan Eßer**'**
6443aa99676SStefan Eßer
6453aa99676SStefan Eßer:   Generates an integer between 0 and **DC_RAND_MAX**, inclusive (see the
6463aa99676SStefan Eßer    **LIMITS** section).
6473aa99676SStefan Eßer
6483aa99676SStefan Eßer    The generated integer is made as unbiased as possible, subject to the
6493aa99676SStefan Eßer    limitations of the pseudo-random number generator.
6503aa99676SStefan Eßer
6513aa99676SStefan Eßer    This is a **non-portable extension**.
6523aa99676SStefan Eßer
6533aa99676SStefan Eßer**"**
6543aa99676SStefan Eßer
6553aa99676SStefan Eßer:   Pops a value off of the stack, which is used as an **exclusive** upper bound
6563aa99676SStefan Eßer    on the integer that will be generated. If the bound is negative or is a
6573aa99676SStefan Eßer    non-integer, an error is raised, and dc(1) resets (see the **RESET**
6583aa99676SStefan Eßer    section) while **seed** remains unchanged. If the bound is larger than
6593aa99676SStefan Eßer    **DC_RAND_MAX**, the higher bound is honored by generating several
6603aa99676SStefan Eßer    pseudo-random integers, multiplying them by appropriate powers of
6613aa99676SStefan Eßer    **DC_RAND_MAX+1**, and adding them together. Thus, the size of integer that
6623aa99676SStefan Eßer    can be generated with this command is unbounded. Using this command will
6633aa99676SStefan Eßer    change the value of **seed**, unless the operand is **0** or **1**. In that
6643aa99676SStefan Eßer    case, **0** is pushed onto the stack, and **seed** is *not* changed.
6653aa99676SStefan Eßer
6663aa99676SStefan Eßer    The generated integer is made as unbiased as possible, subject to the
6673aa99676SStefan Eßer    limitations of the pseudo-random number generator.
6683aa99676SStefan Eßer
6693aa99676SStefan Eßer    This is a **non-portable extension**.
6703aa99676SStefan Eßer
6713aa99676SStefan Eßer## Stack Control
6723aa99676SStefan Eßer
6733aa99676SStefan EßerThese commands control the stack.
6743aa99676SStefan Eßer
6753aa99676SStefan Eßer**c**
6763aa99676SStefan Eßer
6773aa99676SStefan Eßer:   Removes all items from ("clears") the stack.
6783aa99676SStefan Eßer
6793aa99676SStefan Eßer**d**
6803aa99676SStefan Eßer
6813aa99676SStefan Eßer:   Copies the item on top of the stack ("duplicates") and pushes the copy onto
6823aa99676SStefan Eßer    the stack.
6833aa99676SStefan Eßer
6843aa99676SStefan Eßer**r**
6853aa99676SStefan Eßer
6863aa99676SStefan Eßer:   Swaps ("reverses") the two top items on the stack.
6873aa99676SStefan Eßer
6883aa99676SStefan Eßer**R**
6893aa99676SStefan Eßer
6903aa99676SStefan Eßer:   Pops ("removes") the top value from the stack.
6913aa99676SStefan Eßer
6923aa99676SStefan Eßer## Register Control
6933aa99676SStefan Eßer
6943aa99676SStefan EßerThese commands control registers (see the **REGISTERS** section).
6953aa99676SStefan Eßer
6967e5c51e5SStefan Eßer**s**_r_
6973aa99676SStefan Eßer
6983aa99676SStefan Eßer:   Pops the value off the top of the stack and stores it into register *r*.
6993aa99676SStefan Eßer
7007e5c51e5SStefan Eßer**l**_r_
7013aa99676SStefan Eßer
7023aa99676SStefan Eßer:   Copies the value in register *r* and pushes it onto the stack. This does not
7033aa99676SStefan Eßer    alter the contents of *r*.
7043aa99676SStefan Eßer
7057e5c51e5SStefan Eßer**S**_r_
7063aa99676SStefan Eßer
7073aa99676SStefan Eßer:   Pops the value off the top of the (main) stack and pushes it onto the stack
7083aa99676SStefan Eßer    of register *r*. The previous value of the register becomes inaccessible.
7093aa99676SStefan Eßer
7107e5c51e5SStefan Eßer**L**_r_
7113aa99676SStefan Eßer
7123aa99676SStefan Eßer:   Pops the value off the top of the stack for register *r* and push it onto
7133aa99676SStefan Eßer    the main stack. The previous value in the stack for register *r*, if any, is
7147e5c51e5SStefan Eßer    now accessible via the **l**_r_ command.
7153aa99676SStefan Eßer
7163aa99676SStefan Eßer## Parameters
7173aa99676SStefan Eßer
7183aa99676SStefan EßerThese commands control the values of **ibase**, **obase**, **scale**, and
7193aa99676SStefan Eßer**seed**. Also see the **SYNTAX** section.
7203aa99676SStefan Eßer
7213aa99676SStefan Eßer**i**
7223aa99676SStefan Eßer
7233aa99676SStefan Eßer:   Pops the value off of the top of the stack and uses it to set **ibase**,
7243aa99676SStefan Eßer    which must be between **2** and **16**, inclusive.
7253aa99676SStefan Eßer
7263aa99676SStefan Eßer    If the value on top of the stack has any *scale*, the *scale* is ignored.
7273aa99676SStefan Eßer
7283aa99676SStefan Eßer**o**
7293aa99676SStefan Eßer
7303aa99676SStefan Eßer:   Pops the value off of the top of the stack and uses it to set **obase**,
7313aa99676SStefan Eßer    which must be between **0** and **DC_BASE_MAX**, inclusive (see the
7323aa99676SStefan Eßer    **LIMITS** section and the **NUMBERS** section).
7333aa99676SStefan Eßer
7343aa99676SStefan Eßer    If the value on top of the stack has any *scale*, the *scale* is ignored.
7353aa99676SStefan Eßer
7363aa99676SStefan Eßer**k**
7373aa99676SStefan Eßer
7383aa99676SStefan Eßer:   Pops the value off of the top of the stack and uses it to set **scale**,
7393aa99676SStefan Eßer    which must be non-negative.
7403aa99676SStefan Eßer
7413aa99676SStefan Eßer    If the value on top of the stack has any *scale*, the *scale* is ignored.
7423aa99676SStefan Eßer
7433aa99676SStefan Eßer**j**
7443aa99676SStefan Eßer
7453aa99676SStefan Eßer:   Pops the value off of the top of the stack and uses it to set **seed**. The
7463aa99676SStefan Eßer    meaning of **seed** is dependent on the current pseudo-random number
7473aa99676SStefan Eßer    generator but is guaranteed to not change except for new major versions.
7483aa99676SStefan Eßer
7493aa99676SStefan Eßer    The *scale* and sign of the value may be significant.
7503aa99676SStefan Eßer
7513aa99676SStefan Eßer    If a previously used **seed** value is used again, the pseudo-random number
7523aa99676SStefan Eßer    generator is guaranteed to produce the same sequence of pseudo-random
7533aa99676SStefan Eßer    numbers as it did when the **seed** value was previously used.
7543aa99676SStefan Eßer
7553aa99676SStefan Eßer    The exact value assigned to **seed** is not guaranteed to be returned if the
7563aa99676SStefan Eßer    **J** command is used. However, if **seed** *does* return a different value,
7573aa99676SStefan Eßer    both values, when assigned to **seed**, are guaranteed to produce the same
7583aa99676SStefan Eßer    sequence of pseudo-random numbers. This means that certain values assigned
7593aa99676SStefan Eßer    to **seed** will not produce unique sequences of pseudo-random numbers.
7603aa99676SStefan Eßer
7613aa99676SStefan Eßer    There is no limit to the length (number of significant decimal digits) or
7623aa99676SStefan Eßer    *scale* of the value that can be assigned to **seed**.
7633aa99676SStefan Eßer
7643aa99676SStefan Eßer    This is a **non-portable extension**.
7653aa99676SStefan Eßer
7663aa99676SStefan Eßer**I**
7673aa99676SStefan Eßer
7683aa99676SStefan Eßer:   Pushes the current value of **ibase** onto the main stack.
7693aa99676SStefan Eßer
7703aa99676SStefan Eßer**O**
7713aa99676SStefan Eßer
7723aa99676SStefan Eßer:   Pushes the current value of **obase** onto the main stack.
7733aa99676SStefan Eßer
7743aa99676SStefan Eßer**K**
7753aa99676SStefan Eßer
7763aa99676SStefan Eßer:   Pushes the current value of **scale** onto the main stack.
7773aa99676SStefan Eßer
7783aa99676SStefan Eßer**J**
7793aa99676SStefan Eßer
7803aa99676SStefan Eßer:   Pushes the current value of **seed** onto the main stack.
7813aa99676SStefan Eßer
7823aa99676SStefan Eßer    This is a **non-portable extension**.
7833aa99676SStefan Eßer
7843aa99676SStefan Eßer**T**
7853aa99676SStefan Eßer
7863aa99676SStefan Eßer:   Pushes the maximum allowable value of **ibase** onto the main stack.
7873aa99676SStefan Eßer
7883aa99676SStefan Eßer    This is a **non-portable extension**.
7893aa99676SStefan Eßer
7903aa99676SStefan Eßer**U**
7913aa99676SStefan Eßer
7923aa99676SStefan Eßer:   Pushes the maximum allowable value of **obase** onto the main stack.
7933aa99676SStefan Eßer
7943aa99676SStefan Eßer    This is a **non-portable extension**.
7953aa99676SStefan Eßer
7963aa99676SStefan Eßer**V**
7973aa99676SStefan Eßer
7983aa99676SStefan Eßer:   Pushes the maximum allowable value of **scale** onto the main stack.
7993aa99676SStefan Eßer
8003aa99676SStefan Eßer    This is a **non-portable extension**.
8013aa99676SStefan Eßer
8023aa99676SStefan Eßer**W**
8033aa99676SStefan Eßer
8043aa99676SStefan Eßer:   Pushes the maximum (inclusive) integer that can be generated with the **'**
8053aa99676SStefan Eßer    pseudo-random number generator command.
8063aa99676SStefan Eßer
8073aa99676SStefan Eßer    This is a **non-portable extension**.
8083aa99676SStefan Eßer
8093aa99676SStefan Eßer## Strings
8103aa99676SStefan Eßer
8113aa99676SStefan EßerThe following commands control strings.
8123aa99676SStefan Eßer
8133aa99676SStefan Eßerdc(1) can work with both numbers and strings, and registers (see the
8143aa99676SStefan Eßer**REGISTERS** section) can hold both strings and numbers. dc(1) always knows
8153aa99676SStefan Eßerwhether the contents of a register are a string or a number.
8163aa99676SStefan Eßer
8173aa99676SStefan EßerWhile arithmetic operations have to have numbers, and will print an error if
8183aa99676SStefan Eßergiven a string, other commands accept strings.
8193aa99676SStefan Eßer
8203aa99676SStefan EßerStrings can also be executed as macros. For example, if the string **[1pR]** is
8213aa99676SStefan Eßerexecuted as a macro, then the code **1pR** is executed, meaning that the **1**
8223aa99676SStefan Eßerwill be printed with a newline after and then popped from the stack.
8233aa99676SStefan Eßer
8243aa99676SStefan Eßer**\[**_characters_**\]**
8253aa99676SStefan Eßer
8263aa99676SStefan Eßer:   Makes a string containing *characters* and pushes it onto the stack.
8273aa99676SStefan Eßer
8283aa99676SStefan Eßer    If there are brackets (**\[** and **\]**) in the string, then they must be
8293aa99676SStefan Eßer    balanced. Unbalanced brackets can be escaped using a backslash (**\\**)
8303aa99676SStefan Eßer    character.
8313aa99676SStefan Eßer
8323aa99676SStefan Eßer    If there is a backslash character in the string, the character after it
8333aa99676SStefan Eßer    (even another backslash) is put into the string verbatim, but the (first)
8343aa99676SStefan Eßer    backslash is not.
8353aa99676SStefan Eßer
8363aa99676SStefan Eßer**a**
8373aa99676SStefan Eßer
8383aa99676SStefan Eßer:   The value on top of the stack is popped.
8393aa99676SStefan Eßer
8403aa99676SStefan Eßer    If it is a number, it is truncated and its absolute value is taken. The
84144d4804dSStefan Eßer    result mod **256** is calculated. If that result is **0**, push an empty
84244d4804dSStefan Eßer    string; otherwise, push a one-character string where the character is the
84344d4804dSStefan Eßer    result of the mod interpreted as an ASCII character.
8443aa99676SStefan Eßer
8453aa99676SStefan Eßer    If it is a string, then a new string is made. If the original string is
8463aa99676SStefan Eßer    empty, the new string is empty. If it is not, then the first character of
8473aa99676SStefan Eßer    the original string is used to create the new string as a one-character
8483aa99676SStefan Eßer    string. The new string is then pushed onto the stack.
8493aa99676SStefan Eßer
8503aa99676SStefan Eßer    This is a **non-portable extension**.
8513aa99676SStefan Eßer
8523aa99676SStefan Eßer**x**
8533aa99676SStefan Eßer
8543aa99676SStefan Eßer:   Pops a value off of the top of the stack.
8553aa99676SStefan Eßer
8563aa99676SStefan Eßer    If it is a number, it is pushed back onto the stack.
8573aa99676SStefan Eßer
8583aa99676SStefan Eßer    If it is a string, it is executed as a macro.
8593aa99676SStefan Eßer
8603aa99676SStefan Eßer    This behavior is the norm whenever a macro is executed, whether by this
8613aa99676SStefan Eßer    command or by the conditional execution commands below.
8623aa99676SStefan Eßer
8637e5c51e5SStefan Eßer**\>**_r_
8643aa99676SStefan Eßer
8653aa99676SStefan Eßer:   Pops two values off of the stack that must be numbers and compares them. If
8663aa99676SStefan Eßer    the first value is greater than the second, then the contents of register
8673aa99676SStefan Eßer    *r* are executed.
8683aa99676SStefan Eßer
8693aa99676SStefan Eßer    For example, **0 1>a** will execute the contents of register **a**, and
8703aa99676SStefan Eßer    **1 0>a** will not.
8713aa99676SStefan Eßer
8723aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
8733aa99676SStefan Eßer    and reset (see the **RESET** section).
8743aa99676SStefan Eßer
8757e5c51e5SStefan Eßer**>**_r_**e**_s_
8763aa99676SStefan Eßer
8773aa99676SStefan Eßer:   Like the above, but will execute register *s* if the comparison fails.
8783aa99676SStefan Eßer
8793aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
8803aa99676SStefan Eßer    and reset (see the **RESET** section).
8813aa99676SStefan Eßer
8823aa99676SStefan Eßer    This is a **non-portable extension**.
8833aa99676SStefan Eßer
8847e5c51e5SStefan Eßer**!\>**_r_
8853aa99676SStefan Eßer
8863aa99676SStefan Eßer:   Pops two values off of the stack that must be numbers and compares them. If
8873aa99676SStefan Eßer    the first value is not greater than the second (less than or equal to), then
8883aa99676SStefan Eßer    the contents of register *r* are executed.
8893aa99676SStefan Eßer
8903aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
8913aa99676SStefan Eßer    and reset (see the **RESET** section).
8923aa99676SStefan Eßer
8937e5c51e5SStefan Eßer**!\>**_r_**e**_s_
8943aa99676SStefan Eßer
8953aa99676SStefan Eßer:   Like the above, but will execute register *s* if the comparison fails.
8963aa99676SStefan Eßer
8973aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
8983aa99676SStefan Eßer    and reset (see the **RESET** section).
8993aa99676SStefan Eßer
9003aa99676SStefan Eßer    This is a **non-portable extension**.
9013aa99676SStefan Eßer
9027e5c51e5SStefan Eßer**\<**_r_
9033aa99676SStefan Eßer
9043aa99676SStefan Eßer:   Pops two values off of the stack that must be numbers and compares them. If
9053aa99676SStefan Eßer    the first value is less than the second, then the contents of register *r*
9063aa99676SStefan Eßer    are executed.
9073aa99676SStefan Eßer
9083aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
9093aa99676SStefan Eßer    and reset (see the **RESET** section).
9103aa99676SStefan Eßer
9117e5c51e5SStefan Eßer**\<**_r_**e**_s_
9123aa99676SStefan Eßer
9133aa99676SStefan Eßer:   Like the above, but will execute register *s* if the comparison fails.
9143aa99676SStefan Eßer
9153aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
9163aa99676SStefan Eßer    and reset (see the **RESET** section).
9173aa99676SStefan Eßer
9183aa99676SStefan Eßer    This is a **non-portable extension**.
9193aa99676SStefan Eßer
9207e5c51e5SStefan Eßer**!\<**_r_
9213aa99676SStefan Eßer
9223aa99676SStefan Eßer:   Pops two values off of the stack that must be numbers and compares them. If
9233aa99676SStefan Eßer    the first value is not less than the second (greater than or equal to), then
9243aa99676SStefan Eßer    the contents of register *r* are executed.
9253aa99676SStefan Eßer
9263aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
9273aa99676SStefan Eßer    and reset (see the **RESET** section).
9283aa99676SStefan Eßer
9297e5c51e5SStefan Eßer**!\<**_r_**e**_s_
9303aa99676SStefan Eßer
9313aa99676SStefan Eßer:   Like the above, but will execute register *s* if the comparison fails.
9323aa99676SStefan Eßer
9333aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
9343aa99676SStefan Eßer    and reset (see the **RESET** section).
9353aa99676SStefan Eßer
9363aa99676SStefan Eßer    This is a **non-portable extension**.
9373aa99676SStefan Eßer
9387e5c51e5SStefan Eßer**=**_r_
9393aa99676SStefan Eßer
9403aa99676SStefan Eßer:   Pops two values off of the stack that must be numbers and compares them. If
9413aa99676SStefan Eßer    the first value is equal to the second, then the contents of register *r*
9423aa99676SStefan Eßer    are executed.
9433aa99676SStefan Eßer
9443aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
9453aa99676SStefan Eßer    and reset (see the **RESET** section).
9463aa99676SStefan Eßer
9477e5c51e5SStefan Eßer**=**_r_**e**_s_
9483aa99676SStefan Eßer
9493aa99676SStefan Eßer:   Like the above, but will execute register *s* if the comparison fails.
9503aa99676SStefan Eßer
9513aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
9523aa99676SStefan Eßer    and reset (see the **RESET** section).
9533aa99676SStefan Eßer
9543aa99676SStefan Eßer    This is a **non-portable extension**.
9553aa99676SStefan Eßer
9567e5c51e5SStefan Eßer**!=**_r_
9573aa99676SStefan Eßer
9583aa99676SStefan Eßer:   Pops two values off of the stack that must be numbers and compares them. If
9593aa99676SStefan Eßer    the first value is not equal to the second, then the contents of register
9603aa99676SStefan Eßer    *r* are executed.
9613aa99676SStefan Eßer
9623aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
9633aa99676SStefan Eßer    and reset (see the **RESET** section).
9643aa99676SStefan Eßer
9657e5c51e5SStefan Eßer**!=**_r_**e**_s_
9663aa99676SStefan Eßer
9673aa99676SStefan Eßer:   Like the above, but will execute register *s* if the comparison fails.
9683aa99676SStefan Eßer
9693aa99676SStefan Eßer    If either or both of the values are not numbers, dc(1) will raise an error
9703aa99676SStefan Eßer    and reset (see the **RESET** section).
9713aa99676SStefan Eßer
9723aa99676SStefan Eßer    This is a **non-portable extension**.
9733aa99676SStefan Eßer
9743aa99676SStefan Eßer**?**
9753aa99676SStefan Eßer
9763aa99676SStefan Eßer:   Reads a line from the **stdin** and executes it. This is to allow macros to
9773aa99676SStefan Eßer    request input from users.
9783aa99676SStefan Eßer
9793aa99676SStefan Eßer**q**
9803aa99676SStefan Eßer
9813aa99676SStefan Eßer:   During execution of a macro, this exits the execution of that macro and the
9823aa99676SStefan Eßer    execution of the macro that executed it. If there are no macros, or only one
9833aa99676SStefan Eßer    macro executing, dc(1) exits.
9843aa99676SStefan Eßer
9853aa99676SStefan Eßer**Q**
9863aa99676SStefan Eßer
9873aa99676SStefan Eßer:   Pops a value from the stack which must be non-negative and is used the
9883aa99676SStefan Eßer    number of macro executions to pop off of the execution stack. If the number
9893aa99676SStefan Eßer    of levels to pop is greater than the number of executing macros, dc(1)
9903aa99676SStefan Eßer    exits.
9913aa99676SStefan Eßer
99244d4804dSStefan Eßer**,**
99344d4804dSStefan Eßer
99444d4804dSStefan Eßer:   Pushes the depth of the execution stack onto the stack. The execution stack
99544d4804dSStefan Eßer    is the stack of string executions. The number that is pushed onto the stack
99644d4804dSStefan Eßer    is exactly as many as is needed to make dc(1) exit with the **Q** command,
99744d4804dSStefan Eßer    so the sequence **,Q** will make dc(1) exit.
99844d4804dSStefan Eßer
999d101cdd6SStefan Eßer    This is a **non-portable extension**.
1000d101cdd6SStefan Eßer
10013aa99676SStefan Eßer## Status
10023aa99676SStefan Eßer
10033aa99676SStefan EßerThese commands query status of the stack or its top value.
10043aa99676SStefan Eßer
10053aa99676SStefan Eßer**Z**
10063aa99676SStefan Eßer
10073aa99676SStefan Eßer:   Pops a value off of the stack.
10083aa99676SStefan Eßer
10093aa99676SStefan Eßer    If it is a number, calculates the number of significant decimal digits it
101044d4804dSStefan Eßer    has and pushes the result. It will push **1** if the argument is **0** with
101144d4804dSStefan Eßer    no decimal places.
10123aa99676SStefan Eßer
10133aa99676SStefan Eßer    If it is a string, pushes the number of characters the string has.
10143aa99676SStefan Eßer
10153aa99676SStefan Eßer**X**
10163aa99676SStefan Eßer
10173aa99676SStefan Eßer:   Pops a value off of the stack.
10183aa99676SStefan Eßer
10193aa99676SStefan Eßer    If it is a number, pushes the *scale* of the value onto the stack.
10203aa99676SStefan Eßer
10213aa99676SStefan Eßer    If it is a string, pushes **0**.
10223aa99676SStefan Eßer
1023d101cdd6SStefan Eßer**u**
1024d101cdd6SStefan Eßer
1025d101cdd6SStefan Eßer:   Pops one value off of the stack. If the value is a number, this pushes **1**
1026d101cdd6SStefan Eßer    onto the stack. Otherwise (if it is a string), it pushes **0**.
1027d101cdd6SStefan Eßer
1028d101cdd6SStefan Eßer    This is a **non-portable extension**.
1029d101cdd6SStefan Eßer
1030d101cdd6SStefan Eßer**t**
1031d101cdd6SStefan Eßer
1032d101cdd6SStefan Eßer:   Pops one value off of the stack. If the value is a string, this pushes **1**
1033d101cdd6SStefan Eßer    onto the stack. Otherwise (if it is a number), it pushes **0**.
1034d101cdd6SStefan Eßer
1035d101cdd6SStefan Eßer    This is a **non-portable extension**.
1036d101cdd6SStefan Eßer
10373aa99676SStefan Eßer**z**
10383aa99676SStefan Eßer
103944d4804dSStefan Eßer:   Pushes the current depth of the stack (before execution of this command)
104044d4804dSStefan Eßer    onto the stack.
104144d4804dSStefan Eßer
104244d4804dSStefan Eßer**y**_r_
104344d4804dSStefan Eßer
104444d4804dSStefan Eßer:   Pushes the current stack depth of the register *r* onto the main stack.
104544d4804dSStefan Eßer
104644d4804dSStefan Eßer    Because each register has a depth of **1** (with the value **0** in the top
104744d4804dSStefan Eßer    item) when dc(1) starts, dc(1) requires that each register's stack must
104844d4804dSStefan Eßer    always have at least one item; dc(1) will give an error and reset otherwise
104944d4804dSStefan Eßer    (see the **RESET** section). This means that this command will never push
105044d4804dSStefan Eßer    **0**.
105144d4804dSStefan Eßer
105244d4804dSStefan Eßer    This is a **non-portable extension**.
10533aa99676SStefan Eßer
10543aa99676SStefan Eßer## Arrays
10553aa99676SStefan Eßer
10563aa99676SStefan EßerThese commands manipulate arrays.
10573aa99676SStefan Eßer
10587e5c51e5SStefan Eßer**:**_r_
10593aa99676SStefan Eßer
10603aa99676SStefan Eßer:   Pops the top two values off of the stack. The second value will be stored in
10613aa99676SStefan Eßer    the array *r* (see the **REGISTERS** section), indexed by the first value.
10623aa99676SStefan Eßer
10637e5c51e5SStefan Eßer**;**_r_
10643aa99676SStefan Eßer
10653aa99676SStefan Eßer:   Pops the value on top of the stack and uses it as an index into the array
10663aa99676SStefan Eßer    *r*. The selected value is then pushed onto the stack.
10673aa99676SStefan Eßer
106844d4804dSStefan Eßer**Y**_r_
106944d4804dSStefan Eßer
107044d4804dSStefan Eßer:   Pushes the length of the array *r* onto the stack.
107144d4804dSStefan Eßer
107244d4804dSStefan Eßer    This is a **non-portable extension**.
107344d4804dSStefan Eßer
1074d43fa8efSStefan Eßer## Global Settings
1075d43fa8efSStefan Eßer
1076d43fa8efSStefan EßerThese commands retrieve global settings. These are the only commands that
1077d43fa8efSStefan Eßerrequire multiple specific characters, and all of them begin with the letter
1078d43fa8efSStefan Eßer**g**. Only the characters below are allowed after the character **g**; any
1079d43fa8efSStefan Eßerother character produces a parse error (see the **ERRORS** section).
1080d43fa8efSStefan Eßer
1081d43fa8efSStefan Eßer**gl**
1082d43fa8efSStefan Eßer
1083d43fa8efSStefan Eßer:   Pushes the line length set by **DC_LINE_LENGTH** (see the **ENVIRONMENT
1084d43fa8efSStefan Eßer    VARIABLES** section) onto the stack.
1085d43fa8efSStefan Eßer
1086103d7cdfSStefan Eßer**gx**
1087103d7cdfSStefan Eßer
1088103d7cdfSStefan Eßer:   Pushes **1** onto the stack if extended register mode is on, **0**
1089103d7cdfSStefan Eßer    otherwise. See the *Extended Register Mode* subsection of the **REGISTERS**
1090103d7cdfSStefan Eßer    section for more information.
1091103d7cdfSStefan Eßer
1092d43fa8efSStefan Eßer**gz**
1093d43fa8efSStefan Eßer
1094d43fa8efSStefan Eßer:   Pushes **0** onto the stack if the leading zero setting has not been enabled
1095d43fa8efSStefan Eßer    with the **-z** or **-\-leading-zeroes** options (see the **OPTIONS**
1096d43fa8efSStefan Eßer    section), non-zero otherwise.
1097d43fa8efSStefan Eßer
10983aa99676SStefan Eßer# REGISTERS
10993aa99676SStefan Eßer
11003aa99676SStefan EßerRegisters are names that can store strings, numbers, and arrays. (Number/string
11013aa99676SStefan Eßerregisters do not interfere with array registers.)
11023aa99676SStefan Eßer
11033aa99676SStefan EßerEach register is also its own stack, so the current register value is the top of
11043aa99676SStefan Eßerthe stack for the register. All registers, when first referenced, have one value
110544d4804dSStefan Eßer(**0**) in their stack, and it is a runtime error to attempt to pop that item
110644d4804dSStefan Eßeroff of the register stack.
11073aa99676SStefan Eßer
11083aa99676SStefan EßerIn non-extended register mode, a register name is just the single character that
110944d4804dSStefan Eßerfollows any command that needs a register name. The only exceptions are: a
111044d4804dSStefan Eßernewline (**'\\n'**) and a left bracket (**'['**); it is a parse error for a
111144d4804dSStefan Eßernewline or a left bracket to be used as a register name.
11123aa99676SStefan Eßer
11133aa99676SStefan Eßer## Extended Register Mode
11143aa99676SStefan Eßer
11153aa99676SStefan EßerUnlike most other dc(1) implentations, this dc(1) provides nearly unlimited
11163aa99676SStefan Eßeramounts of registers, if extended register mode is enabled.
11173aa99676SStefan Eßer
1118028616d0SStefan EßerIf extended register mode is enabled (**-x** or **-\-extended-register**
11193aa99676SStefan Eßercommand-line arguments are given), then normal single character registers are
11203aa99676SStefan Eßerused *unless* the character immediately following a command that needs a
11213aa99676SStefan Eßerregister name is a space (according to **isspace()**) and not a newline
11223aa99676SStefan Eßer(**'\\n'**).
11233aa99676SStefan Eßer
11243aa99676SStefan EßerIn that case, the register name is found according to the regex
11253aa99676SStefan Eßer**\[a-z\]\[a-z0-9\_\]\*** (like bc(1) identifiers), and it is a parse error if
11263aa99676SStefan Eßerthe next non-space characters do not match that regex.
11273aa99676SStefan Eßer
11283aa99676SStefan Eßer# RESET
11293aa99676SStefan Eßer
11303aa99676SStefan EßerWhen dc(1) encounters an error or a signal that it has a non-default handler
11313aa99676SStefan Eßerfor, it resets. This means that several things happen.
11323aa99676SStefan Eßer
1133*12e0d316SStefan EßerFirst, any macros that are executing are stopped and popped off the execution
1134*12e0d316SStefan Eßerstack. The behavior is not unlike that of exceptions in programming languages.
1135*12e0d316SStefan EßerThen the execution point is set so that any code waiting to execute (after all
11363aa99676SStefan Eßermacros returned) is skipped.
11373aa99676SStefan Eßer
1138*12e0d316SStefan EßerHowever, the stack of values is *not* cleared; in interactive mode, users can
1139*12e0d316SStefan Eßerinspect the stack and manipulate it.
1140*12e0d316SStefan Eßer
11413aa99676SStefan EßerThus, when dc(1) resets, it skips any remaining code waiting to be executed.
11423aa99676SStefan EßerThen, if it is interactive mode, and the error was not a fatal error (see the
11433aa99676SStefan Eßer**EXIT STATUS** section), it asks for more input; otherwise, it exits with the
11443aa99676SStefan Eßerappropriate return code.
11453aa99676SStefan Eßer
11463aa99676SStefan Eßer# PERFORMANCE
11473aa99676SStefan Eßer
11483aa99676SStefan EßerMost dc(1) implementations use **char** types to calculate the value of **1**
11493aa99676SStefan Eßerdecimal digit at a time, but that can be slow. This dc(1) does something
11503aa99676SStefan Eßerdifferent.
11513aa99676SStefan Eßer
11523aa99676SStefan EßerIt uses large integers to calculate more than **1** decimal digit at a time. If
11533aa99676SStefan Eßerbuilt in a environment where **DC_LONG_BIT** (see the **LIMITS** section) is
11543aa99676SStefan Eßer**64**, then each integer has **9** decimal digits. If built in an environment
11553aa99676SStefan Eßerwhere **DC_LONG_BIT** is **32** then each integer has **4** decimal digits. This
11563aa99676SStefan Eßervalue (the number of decimal digits per large integer) is called
11573aa99676SStefan Eßer**DC_BASE_DIGS**.
11583aa99676SStefan Eßer
11593aa99676SStefan EßerIn addition, this dc(1) uses an even larger integer for overflow checking. This
11603aa99676SStefan Eßerinteger type depends on the value of **DC_LONG_BIT**, but is always at least
11613aa99676SStefan Eßertwice as large as the integer type used to store digits.
11623aa99676SStefan Eßer
11633aa99676SStefan Eßer# LIMITS
11643aa99676SStefan Eßer
11653aa99676SStefan EßerThe following are the limits on dc(1):
11663aa99676SStefan Eßer
11673aa99676SStefan Eßer**DC_LONG_BIT**
11683aa99676SStefan Eßer
11693aa99676SStefan Eßer:   The number of bits in the **long** type in the environment where dc(1) was
11703aa99676SStefan Eßer    built. This determines how many decimal digits can be stored in a single
11713aa99676SStefan Eßer    large integer (see the **PERFORMANCE** section).
11723aa99676SStefan Eßer
11733aa99676SStefan Eßer**DC_BASE_DIGS**
11743aa99676SStefan Eßer
11753aa99676SStefan Eßer:   The number of decimal digits per large integer (see the **PERFORMANCE**
11763aa99676SStefan Eßer    section). Depends on **DC_LONG_BIT**.
11773aa99676SStefan Eßer
11783aa99676SStefan Eßer**DC_BASE_POW**
11793aa99676SStefan Eßer
11803aa99676SStefan Eßer:   The max decimal number that each large integer can store (see
11813aa99676SStefan Eßer    **DC_BASE_DIGS**) plus **1**. Depends on **DC_BASE_DIGS**.
11823aa99676SStefan Eßer
11833aa99676SStefan Eßer**DC_OVERFLOW_MAX**
11843aa99676SStefan Eßer
11853aa99676SStefan Eßer:   The max number that the overflow type (see the **PERFORMANCE** section) can
11863aa99676SStefan Eßer    hold. Depends on **DC_LONG_BIT**.
11873aa99676SStefan Eßer
11883aa99676SStefan Eßer**DC_BASE_MAX**
11893aa99676SStefan Eßer
11903aa99676SStefan Eßer:   The maximum output base. Set at **DC_BASE_POW**.
11913aa99676SStefan Eßer
11923aa99676SStefan Eßer**DC_DIM_MAX**
11933aa99676SStefan Eßer
11943aa99676SStefan Eßer:   The maximum size of arrays. Set at **SIZE_MAX-1**.
11953aa99676SStefan Eßer
11963aa99676SStefan Eßer**DC_SCALE_MAX**
11973aa99676SStefan Eßer
11983aa99676SStefan Eßer:   The maximum **scale**. Set at **DC_OVERFLOW_MAX-1**.
11993aa99676SStefan Eßer
12003aa99676SStefan Eßer**DC_STRING_MAX**
12013aa99676SStefan Eßer
12023aa99676SStefan Eßer:   The maximum length of strings. Set at **DC_OVERFLOW_MAX-1**.
12033aa99676SStefan Eßer
12043aa99676SStefan Eßer**DC_NAME_MAX**
12053aa99676SStefan Eßer
12063aa99676SStefan Eßer:   The maximum length of identifiers. Set at **DC_OVERFLOW_MAX-1**.
12073aa99676SStefan Eßer
12083aa99676SStefan Eßer**DC_NUM_MAX**
12093aa99676SStefan Eßer
12103aa99676SStefan Eßer:   The maximum length of a number (in decimal digits), which includes digits
12113aa99676SStefan Eßer    after the decimal point. Set at **DC_OVERFLOW_MAX-1**.
12123aa99676SStefan Eßer
12133aa99676SStefan Eßer**DC_RAND_MAX**
12143aa99676SStefan Eßer
12153aa99676SStefan Eßer:   The maximum integer (inclusive) returned by the **'** command, if dc(1). Set
12163aa99676SStefan Eßer    at **2\^DC_LONG_BIT-1**.
12173aa99676SStefan Eßer
12183aa99676SStefan EßerExponent
12193aa99676SStefan Eßer
12203aa99676SStefan Eßer:   The maximum allowable exponent (positive or negative). Set at
12213aa99676SStefan Eßer    **DC_OVERFLOW_MAX**.
12223aa99676SStefan Eßer
12233aa99676SStefan EßerNumber of vars
12243aa99676SStefan Eßer
12253aa99676SStefan Eßer:   The maximum number of vars/arrays. Set at **SIZE_MAX-1**.
12263aa99676SStefan Eßer
12273aa99676SStefan EßerThese limits are meant to be effectively non-existent; the limits are so large
12283aa99676SStefan Eßer(at least on 64-bit machines) that there should not be any point at which they
12293aa99676SStefan Eßerbecome a problem. In fact, memory should be exhausted before these limits should
12303aa99676SStefan Eßerbe hit.
12313aa99676SStefan Eßer
12323aa99676SStefan Eßer# ENVIRONMENT VARIABLES
12333aa99676SStefan Eßer
1234d101cdd6SStefan EßerAs **non-portable extensions**, dc(1) recognizes the following environment
1235d101cdd6SStefan Eßervariables:
12363aa99676SStefan Eßer
12373aa99676SStefan Eßer**DC_ENV_ARGS**
12383aa99676SStefan Eßer
12393aa99676SStefan Eßer:   This is another way to give command-line arguments to dc(1). They should be
12403aa99676SStefan Eßer    in the same format as all other command-line arguments. These are always
12413aa99676SStefan Eßer    processed first, so any files given in **DC_ENV_ARGS** will be processed
12423aa99676SStefan Eßer    before arguments and files given on the command-line. This gives the user
12433aa99676SStefan Eßer    the ability to set up "standard" options and files to be used at every
12443aa99676SStefan Eßer    invocation. The most useful thing for such files to contain would be useful
12453aa99676SStefan Eßer    functions that the user might want every time dc(1) runs. Another use would
12463aa99676SStefan Eßer    be to use the **-e** option to set **scale** to a value other than **0**.
12473aa99676SStefan Eßer
12483aa99676SStefan Eßer    The code that parses **DC_ENV_ARGS** will correctly handle quoted arguments,
12493aa99676SStefan Eßer    but it does not understand escape sequences. For example, the string
12503aa99676SStefan Eßer    **"/home/gavin/some dc file.dc"** will be correctly parsed, but the string
12513aa99676SStefan Eßer    **"/home/gavin/some \"dc\" file.dc"** will include the backslashes.
12523aa99676SStefan Eßer
12533aa99676SStefan Eßer    The quote parsing will handle either kind of quotes, **'** or **"**. Thus,
12543aa99676SStefan Eßer    if you have a file with any number of single quotes in the name, you can use
12559a995fe1SStefan Eßer    double quotes as the outside quotes, as in **"some 'dc' file.dc"**, and vice
12563aa99676SStefan Eßer    versa if you have a file with double quotes. However, handling a file with
12573aa99676SStefan Eßer    both kinds of quotes in **DC_ENV_ARGS** is not supported due to the
12583aa99676SStefan Eßer    complexity of the parsing, though such files are still supported on the
12593aa99676SStefan Eßer    command-line where the parsing is done by the shell.
12603aa99676SStefan Eßer
12613aa99676SStefan Eßer**DC_LINE_LENGTH**
12623aa99676SStefan Eßer
12633aa99676SStefan Eßer:   If this environment variable exists and contains an integer that is greater
12643aa99676SStefan Eßer    than **1** and is less than **UINT16_MAX** (**2\^16-1**), dc(1) will output
12653aa99676SStefan Eßer    lines to that length, including the backslash newline combo. The default
12663aa99676SStefan Eßer    line length is **70**.
12673aa99676SStefan Eßer
1268d43fa8efSStefan Eßer    The special value of **0** will disable line length checking and print
1269d43fa8efSStefan Eßer    numbers without regard to line length and without backslashes and newlines.
1270d43fa8efSStefan Eßer
127144d4804dSStefan Eßer**DC_SIGINT_RESET**
12723aa99676SStefan Eßer
127344d4804dSStefan Eßer:   If dc(1) is not in interactive mode (see the **INTERACTIVE MODE** section),
127444d4804dSStefan Eßer    then this environment variable has no effect because dc(1) exits on
127544d4804dSStefan Eßer    **SIGINT** when not in interactive mode.
127644d4804dSStefan Eßer
127744d4804dSStefan Eßer    However, when dc(1) is in interactive mode, then if this environment
127844d4804dSStefan Eßer    variable exists and contains an integer, a non-zero value makes dc(1) reset
127944d4804dSStefan Eßer    on **SIGINT**, rather than exit, and zero makes dc(1) exit. If this
128044d4804dSStefan Eßer    environment variable exists and is *not* an integer, then dc(1) will exit on
128144d4804dSStefan Eßer    **SIGINT**.
128244d4804dSStefan Eßer
128344d4804dSStefan Eßer    This environment variable overrides the default, which can be queried with
128444d4804dSStefan Eßer    the **-h** or **-\-help** options.
128544d4804dSStefan Eßer
128644d4804dSStefan Eßer**DC_TTY_MODE**
128744d4804dSStefan Eßer
128844d4804dSStefan Eßer:   If TTY mode is *not* available (see the **TTY MODE** section), then this
128944d4804dSStefan Eßer    environment variable has no effect.
129044d4804dSStefan Eßer
129144d4804dSStefan Eßer    However, when TTY mode is available, then if this environment variable
129244d4804dSStefan Eßer    exists and contains an integer, then a non-zero value makes dc(1) use TTY
129344d4804dSStefan Eßer    mode, and zero makes dc(1) not use TTY mode.
129444d4804dSStefan Eßer
129544d4804dSStefan Eßer    This environment variable overrides the default, which can be queried with
129644d4804dSStefan Eßer    the **-h** or **-\-help** options.
129744d4804dSStefan Eßer
129844d4804dSStefan Eßer**DC_PROMPT**
129944d4804dSStefan Eßer
130044d4804dSStefan Eßer:   If TTY mode is *not* available (see the **TTY MODE** section), then this
130144d4804dSStefan Eßer    environment variable has no effect.
130244d4804dSStefan Eßer
130344d4804dSStefan Eßer    However, when TTY mode is available, then if this environment variable
130444d4804dSStefan Eßer    exists and contains an integer, a non-zero value makes dc(1) use a prompt,
130544d4804dSStefan Eßer    and zero or a non-integer makes dc(1) not use a prompt. If this environment
130644d4804dSStefan Eßer    variable does not exist and **DC_TTY_MODE** does, then the value of the
130744d4804dSStefan Eßer    **DC_TTY_MODE** environment variable is used.
130844d4804dSStefan Eßer
130944d4804dSStefan Eßer    This environment variable and the **DC_TTY_MODE** environment variable
131044d4804dSStefan Eßer    override the default, which can be queried with the **-h** or **-\-help**
131144d4804dSStefan Eßer    options.
13123aa99676SStefan Eßer
131310041e99SStefan Eßer**DC_EXPR_EXIT**
131410041e99SStefan Eßer
131510041e99SStefan Eßer:   If any expressions or expression files are given on the command-line with
131610041e99SStefan Eßer    **-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
131710041e99SStefan Eßer    variable exists and contains an integer, a non-zero value makes dc(1) exit
131878bc019dSStefan Eßer    after executing the expressions and expression files, and a zero value makes
131978bc019dSStefan Eßer    dc(1) not exit.
132010041e99SStefan Eßer
132110041e99SStefan Eßer    This environment variable overrides the default, which can be queried with
132210041e99SStefan Eßer    the **-h** or **-\-help** options.
132310041e99SStefan Eßer
1324d101cdd6SStefan Eßer**DC_DIGIT_CLAMP**
1325d101cdd6SStefan Eßer
1326d101cdd6SStefan Eßer:   When parsing numbers and if this environment variable exists and contains an
1327d101cdd6SStefan Eßer    integer, a non-zero value makes dc(1) clamp digits that are greater than or
1328d101cdd6SStefan Eßer    equal to the current **ibase** so that all such digits are considered equal
1329d101cdd6SStefan Eßer    to the **ibase** minus 1, and a zero value disables such clamping so that
1330d101cdd6SStefan Eßer    those digits are always equal to their value, which is multiplied by the
1331d101cdd6SStefan Eßer    power of the **ibase**.
1332d101cdd6SStefan Eßer
1333d101cdd6SStefan Eßer    This never applies to single-digit numbers, as per the bc(1) standard (see
1334d101cdd6SStefan Eßer    the **STANDARDS** section).
1335d101cdd6SStefan Eßer
1336d101cdd6SStefan Eßer    This environment variable overrides the default, which can be queried with
1337d101cdd6SStefan Eßer    the **-h** or **-\-help** options.
1338d101cdd6SStefan Eßer
13393aa99676SStefan Eßer# EXIT STATUS
13403aa99676SStefan Eßer
13413aa99676SStefan Eßerdc(1) returns the following exit statuses:
13423aa99676SStefan Eßer
13433aa99676SStefan Eßer**0**
13443aa99676SStefan Eßer
13453aa99676SStefan Eßer:   No error.
13463aa99676SStefan Eßer
13473aa99676SStefan Eßer**1**
13483aa99676SStefan Eßer
13493aa99676SStefan Eßer:   A math error occurred. This follows standard practice of using **1** for
13503aa99676SStefan Eßer    expected errors, since math errors will happen in the process of normal
13513aa99676SStefan Eßer    execution.
13523aa99676SStefan Eßer
13533aa99676SStefan Eßer    Math errors include divide by **0**, taking the square root of a negative
13543aa99676SStefan Eßer    number, using a negative number as a bound for the pseudo-random number
13553aa99676SStefan Eßer    generator, attempting to convert a negative number to a hardware integer,
135644d4804dSStefan Eßer    overflow when converting a number to a hardware integer, overflow when
135744d4804dSStefan Eßer    calculating the size of a number, and attempting to use a non-integer where
135844d4804dSStefan Eßer    an integer is required.
13593aa99676SStefan Eßer
13603aa99676SStefan Eßer    Converting to a hardware integer happens for the second operand of the power
13613aa99676SStefan Eßer    (**\^**), places (**\@**), left shift (**H**), and right shift (**h**)
13623aa99676SStefan Eßer    operators.
13633aa99676SStefan Eßer
13643aa99676SStefan Eßer**2**
13653aa99676SStefan Eßer
13663aa99676SStefan Eßer:   A parse error occurred.
13673aa99676SStefan Eßer
13683aa99676SStefan Eßer    Parse errors include unexpected **EOF**, using an invalid character, failing
13693aa99676SStefan Eßer    to find the end of a string or comment, and using a token where it is
13703aa99676SStefan Eßer    invalid.
13713aa99676SStefan Eßer
13723aa99676SStefan Eßer**3**
13733aa99676SStefan Eßer
13743aa99676SStefan Eßer:   A runtime error occurred.
13753aa99676SStefan Eßer
137644d4804dSStefan Eßer    Runtime errors include assigning an invalid number to any global (**ibase**,
137744d4804dSStefan Eßer    **obase**, or **scale**), giving a bad expression to a **read()** call,
137844d4804dSStefan Eßer    calling **read()** inside of a **read()** call, type errors (including
137944d4804dSStefan Eßer    attempting to execute a number), and attempting an operation when the stack
138044d4804dSStefan Eßer    has too few elements.
13813aa99676SStefan Eßer
13823aa99676SStefan Eßer**4**
13833aa99676SStefan Eßer
13843aa99676SStefan Eßer:   A fatal error occurred.
13853aa99676SStefan Eßer
13863aa99676SStefan Eßer    Fatal errors include memory allocation errors, I/O errors, failing to open
13873aa99676SStefan Eßer    files, attempting to use files that do not have only ASCII characters (dc(1)
13883aa99676SStefan Eßer    only accepts ASCII characters), attempting to open a directory as a file,
13893aa99676SStefan Eßer    and giving invalid command-line options.
13903aa99676SStefan Eßer
13913aa99676SStefan EßerThe exit status **4** is special; when a fatal error occurs, dc(1) always exits
13923aa99676SStefan Eßerand returns **4**, no matter what mode dc(1) is in.
13933aa99676SStefan Eßer
13943aa99676SStefan EßerThe other statuses will only be returned when dc(1) is not in interactive mode
13953aa99676SStefan Eßer(see the **INTERACTIVE MODE** section), since dc(1) resets its state (see the
13963aa99676SStefan Eßer**RESET** section) and accepts more input when one of those errors occurs in
13973aa99676SStefan Eßerinteractive mode. This is also the case when interactive mode is forced by the
1398028616d0SStefan Eßer**-i** flag or **-\-interactive** option.
13993aa99676SStefan Eßer
14003aa99676SStefan EßerThese exit statuses allow dc(1) to be used in shell scripting with error
14013aa99676SStefan Eßerchecking, and its normal behavior can be forced by using the **-i** flag or
1402028616d0SStefan Eßer**-\-interactive** option.
14033aa99676SStefan Eßer
14043aa99676SStefan Eßer# INTERACTIVE MODE
14053aa99676SStefan Eßer
14063aa99676SStefan EßerLike bc(1), dc(1) has an interactive mode and a non-interactive mode.
14073aa99676SStefan EßerInteractive mode is turned on automatically when both **stdin** and **stdout**
1408028616d0SStefan Eßerare hooked to a terminal, but the **-i** flag and **-\-interactive** option can
140944d4804dSStefan Eßerturn it on in other situations.
14103aa99676SStefan Eßer
14113aa99676SStefan EßerIn interactive mode, dc(1) attempts to recover from errors (see the **RESET**
14123aa99676SStefan Eßersection), and in normal execution, flushes **stdout** as soon as execution is
141344d4804dSStefan Eßerdone for the current input. dc(1) may also reset on **SIGINT** instead of exit,
141444d4804dSStefan Eßerdepending on the contents of, or default for, the **DC_SIGINT_RESET**
141544d4804dSStefan Eßerenvironment variable (see the **ENVIRONMENT VARIABLES** section).
14163aa99676SStefan Eßer
14173aa99676SStefan Eßer# TTY MODE
14183aa99676SStefan Eßer
141944d4804dSStefan EßerIf **stdin**, **stdout**, and **stderr** are all connected to a TTY, then "TTY
142044d4804dSStefan Eßermode" is considered to be available, and thus, dc(1) can turn on TTY mode,
142144d4804dSStefan Eßersubject to some settings.
14223aa99676SStefan Eßer
142344d4804dSStefan EßerIf there is the environment variable **DC_TTY_MODE** in the environment (see the
142444d4804dSStefan Eßer**ENVIRONMENT VARIABLES** section), then if that environment variable contains a
142544d4804dSStefan Eßernon-zero integer, dc(1) will turn on TTY mode when **stdin**, **stdout**, and
142644d4804dSStefan Eßer**stderr** are all connected to a TTY. If the **DC_TTY_MODE** environment
142744d4804dSStefan Eßervariable exists but is *not* a non-zero integer, then dc(1) will not turn TTY
142844d4804dSStefan Eßermode on.
142944d4804dSStefan Eßer
143044d4804dSStefan EßerIf the environment variable **DC_TTY_MODE** does *not* exist, the default
143144d4804dSStefan Eßersetting is used. The default setting can be queried with the **-h** or
143244d4804dSStefan Eßer**-\-help** options.
14333aa99676SStefan Eßer
14343aa99676SStefan EßerTTY mode is different from interactive mode because interactive mode is required
1435d101cdd6SStefan Eßerin the bc(1) specification (see the **STANDARDS** section), and interactive mode
1436d101cdd6SStefan Eßerrequires only **stdin** and **stdout** to be connected to a terminal.
14373aa99676SStefan Eßer
143844d4804dSStefan Eßer## Prompt
143944d4804dSStefan Eßer
144044d4804dSStefan EßerIf TTY mode is available, then a prompt can be enabled. Like TTY mode itself, it
144144d4804dSStefan Eßercan be turned on or off with an environment variable: **DC_PROMPT** (see the
144244d4804dSStefan Eßer**ENVIRONMENT VARIABLES** section).
144344d4804dSStefan Eßer
144444d4804dSStefan EßerIf the environment variable **DC_PROMPT** exists and is a non-zero integer, then
144544d4804dSStefan Eßerthe prompt is turned on when **stdin**, **stdout**, and **stderr** are connected
144644d4804dSStefan Eßerto a TTY and the **-P** and **-\-no-prompt** options were not used. The read
144744d4804dSStefan Eßerprompt will be turned on under the same conditions, except that the **-R** and
144844d4804dSStefan Eßer**-\-no-read-prompt** options must also not be used.
144944d4804dSStefan Eßer
145044d4804dSStefan EßerHowever, if **DC_PROMPT** does not exist, the prompt can be enabled or disabled
145144d4804dSStefan Eßerwith the **DC_TTY_MODE** environment variable, the **-P** and **-\-no-prompt**
145244d4804dSStefan Eßeroptions, and the **-R** and **-\-no-read-prompt** options. See the **ENVIRONMENT
145344d4804dSStefan EßerVARIABLES** and **OPTIONS** sections for more details.
145444d4804dSStefan Eßer
14553aa99676SStefan Eßer# SIGNAL HANDLING
14563aa99676SStefan Eßer
145744d4804dSStefan EßerSending a **SIGINT** will cause dc(1) to do one of two things.
145844d4804dSStefan Eßer
145944d4804dSStefan EßerIf dc(1) is not in interactive mode (see the **INTERACTIVE MODE** section), or
146044d4804dSStefan Eßerthe **DC_SIGINT_RESET** environment variable (see the **ENVIRONMENT VARIABLES**
146144d4804dSStefan Eßersection), or its default, is either not an integer or it is zero, dc(1) will
146244d4804dSStefan Eßerexit.
146344d4804dSStefan Eßer
146444d4804dSStefan EßerHowever, if dc(1) is in interactive mode, and the **DC_SIGINT_RESET** or its
146544d4804dSStefan Eßerdefault is an integer and non-zero, then dc(1) will stop executing the current
146644d4804dSStefan Eßerinput and reset (see the **RESET** section) upon receiving a **SIGINT**.
14673aa99676SStefan Eßer
14683aa99676SStefan EßerNote that "current input" can mean one of two things. If dc(1) is processing
146944d4804dSStefan Eßerinput from **stdin** in interactive mode, it will ask for more input. If dc(1)
147044d4804dSStefan Eßeris processing input from a file in interactive mode, it will stop processing the
147144d4804dSStefan Eßerfile and start processing the next file, if one exists, or ask for input from
147244d4804dSStefan Eßer**stdin** if no other file exists.
14733aa99676SStefan Eßer
14743aa99676SStefan EßerThis means that if a **SIGINT** is sent to dc(1) as it is executing a file, it
14753aa99676SStefan Eßercan seem as though dc(1) did not respond to the signal since it will immediately
14763aa99676SStefan Eßerstart executing the next file. This is by design; most files that users execute
14773aa99676SStefan Eßerwhen interacting with dc(1) have function definitions, which are quick to parse.
14783aa99676SStefan EßerIf a file takes a long time to execute, there may be a bug in that file. The
14793aa99676SStefan Eßerrest of the files could still be executed without problem, allowing the user to
14803aa99676SStefan Eßercontinue.
14813aa99676SStefan Eßer
14823aa99676SStefan Eßer**SIGTERM** and **SIGQUIT** cause dc(1) to clean up and exit, and it uses the
14833aa99676SStefan Eßerdefault handler for all other signals.
14843aa99676SStefan Eßer
14853aa99676SStefan Eßer# LOCALES
14863aa99676SStefan Eßer
14873aa99676SStefan EßerThis dc(1) ships with support for adding error messages for different locales
148844d4804dSStefan Eßerand thus, supports **LC_MESSAGES**.
14893aa99676SStefan Eßer
14903aa99676SStefan Eßer# SEE ALSO
14913aa99676SStefan Eßer
14923aa99676SStefan Eßerbc(1)
14933aa99676SStefan Eßer
14943aa99676SStefan Eßer# STANDARDS
14953aa99676SStefan Eßer
1496d101cdd6SStefan EßerThe dc(1) utility operators and some behavior are compliant with the operators
1497d101cdd6SStefan Eßerin the IEEE Std 1003.1-2017 (“POSIX.1-2017”) bc(1) specification at
1498d101cdd6SStefan Eßerhttps://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html .
14993aa99676SStefan Eßer
15003aa99676SStefan Eßer# BUGS
15013aa99676SStefan Eßer
15024fca8e0fSStefan EßerNone are known. Report bugs at https://git.gavinhoward.com/gavin/bc .
15033aa99676SStefan Eßer
15043aa99676SStefan Eßer# AUTHOR
15053aa99676SStefan Eßer
15064fca8e0fSStefan EßerGavin D. Howard <gavin@gavinhoward.com> and contributors.
1507