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