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