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