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 Workerbc - arbitrary-precision decimal arithmetic language and calculator 34*5a6e8488SAndroid Build Coastguard Worker 35*5a6e8488SAndroid Build Coastguard Worker# SYNOPSIS 36*5a6e8488SAndroid Build Coastguard Worker 37*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 38*5a6e8488SAndroid Build Coastguard Worker**bc** [**-cCghilPqRsvVw**] [**-\-digit-clamp**] [**-\-no-digit-clamp**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] [**-I** *ibase*] [**-\-ibase**=*ibase*] [**-O** *obase*] [**-\-obase**=*obase*] [**-S** *scale*] [**-\-scale**=*scale*] [**-E** *seed*] [**-\-seed**=*seed*] 39*5a6e8488SAndroid Build Coastguard Worker{{ end }} 40*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 41*5a6e8488SAndroid Build Coastguard Worker**bc** [**-cCghilPqRsvVw**] [**-\-digit-clamp**] [**-\-no-digit-clamp**] [**-\-global-stacks**] [**-\-help**] [**-\-interactive**] [**-\-mathlib**] [**-\-no-prompt**] [**-\-no-read-prompt**] [**-\-quiet**] [**-\-standard**] [**-\-warn**] [**-\-version**] [**-e** *expr*] [**-\-expression**=*expr*...] [**-f** *file*...] [**-\-file**=*file*...] [*file*...] 42*5a6e8488SAndroid Build Coastguard Worker{{ end }} 43*5a6e8488SAndroid Build Coastguard Worker 44*5a6e8488SAndroid Build Coastguard Worker# DESCRIPTION 45*5a6e8488SAndroid Build Coastguard Worker 46*5a6e8488SAndroid Build Coastguard Workerbc(1) is an interactive processor for a language first standardized in 1991 by 47*5a6e8488SAndroid Build Coastguard WorkerPOSIX. (See the **STANDARDS** section.) The language provides unlimited 48*5a6e8488SAndroid Build Coastguard Workerprecision decimal arithmetic and is somewhat C-like, but there are differences. 49*5a6e8488SAndroid Build Coastguard WorkerSuch differences will be noted in this document. 50*5a6e8488SAndroid Build Coastguard Worker 51*5a6e8488SAndroid Build Coastguard WorkerAfter parsing and handling options, this bc(1) reads any files given on the 52*5a6e8488SAndroid Build Coastguard Workercommand line and executes them before reading from **stdin**. 53*5a6e8488SAndroid Build Coastguard Worker 54*5a6e8488SAndroid Build Coastguard WorkerThis bc(1) is a drop-in replacement for *any* bc(1), including (and 55*5a6e8488SAndroid Build Coastguard Workerespecially) the GNU bc(1). It also has many extensions and extra features beyond 56*5a6e8488SAndroid Build Coastguard Workerother implementations. 57*5a6e8488SAndroid Build Coastguard Worker 58*5a6e8488SAndroid Build Coastguard Worker**Note**: If running this bc(1) on *any* script meant for another bc(1) gives a 59*5a6e8488SAndroid Build Coastguard Workerparse error, it is probably because a word this bc(1) reserves as a keyword is 60*5a6e8488SAndroid Build Coastguard Workerused as the name of a function, variable, or array. To fix that, use the 61*5a6e8488SAndroid Build Coastguard Workercommand-line option **-r** *keyword*, where *keyword* is the keyword that is 62*5a6e8488SAndroid Build Coastguard Workerused as a name in the script. For more information, see the **OPTIONS** section. 63*5a6e8488SAndroid Build Coastguard Worker 64*5a6e8488SAndroid Build Coastguard WorkerIf parsing scripts meant for other bc(1) implementations still does not work, 65*5a6e8488SAndroid Build Coastguard Workerthat is a bug and should be reported. See the **BUGS** section. 66*5a6e8488SAndroid Build Coastguard Worker 67*5a6e8488SAndroid Build Coastguard Worker# OPTIONS 68*5a6e8488SAndroid Build Coastguard Worker 69*5a6e8488SAndroid Build Coastguard WorkerThe following are the options that bc(1) accepts. 70*5a6e8488SAndroid Build Coastguard Worker 71*5a6e8488SAndroid Build Coastguard Worker**-C**, **-\-no-digit-clamp** 72*5a6e8488SAndroid Build Coastguard Worker 73*5a6e8488SAndroid Build Coastguard Worker: Disables clamping of digits greater than or equal to the current **ibase** 74*5a6e8488SAndroid Build Coastguard Worker when parsing numbers. 75*5a6e8488SAndroid Build Coastguard Worker 76*5a6e8488SAndroid Build Coastguard Worker This means that the value added to a number from a digit is always that 77*5a6e8488SAndroid Build Coastguard Worker digit's value multiplied by the value of ibase raised to the power of the 78*5a6e8488SAndroid Build Coastguard Worker digit's position, which starts from 0 at the least significant digit. 79*5a6e8488SAndroid Build Coastguard Worker 80*5a6e8488SAndroid Build Coastguard Worker If this and/or the **-c** or **-\-digit-clamp** options are given multiple 81*5a6e8488SAndroid Build Coastguard Worker times, the last one given is used. 82*5a6e8488SAndroid Build Coastguard Worker 83*5a6e8488SAndroid Build Coastguard Worker This option overrides the **BC_DIGIT_CLAMP** environment variable (see the 84*5a6e8488SAndroid Build Coastguard Worker **ENVIRONMENT VARIABLES** section) and the default, which can be queried 85*5a6e8488SAndroid Build Coastguard Worker with the **-h** or **-\-help** options. 86*5a6e8488SAndroid Build Coastguard Worker 87*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 88*5a6e8488SAndroid Build Coastguard Worker 89*5a6e8488SAndroid Build Coastguard Worker**-c**, **-\-digit-clamp** 90*5a6e8488SAndroid Build Coastguard Worker 91*5a6e8488SAndroid Build Coastguard Worker: Enables clamping of digits greater than or equal to the current **ibase** 92*5a6e8488SAndroid Build Coastguard Worker when parsing numbers. 93*5a6e8488SAndroid Build Coastguard Worker 94*5a6e8488SAndroid Build Coastguard Worker This means that digits that the value added to a number from a digit that is 95*5a6e8488SAndroid Build Coastguard Worker greater than or equal to the ibase is the value of ibase minus 1 all 96*5a6e8488SAndroid Build Coastguard Worker multiplied by the value of ibase raised to the power of the digit's 97*5a6e8488SAndroid Build Coastguard Worker position, which starts from 0 at the least significant digit. 98*5a6e8488SAndroid Build Coastguard Worker 99*5a6e8488SAndroid Build Coastguard Worker If this and/or the **-C** or **-\-no-digit-clamp** options are given 100*5a6e8488SAndroid Build Coastguard Worker multiple times, the last one given is used. 101*5a6e8488SAndroid Build Coastguard Worker 102*5a6e8488SAndroid Build Coastguard Worker This option overrides the **BC_DIGIT_CLAMP** environment variable (see the 103*5a6e8488SAndroid Build Coastguard Worker **ENVIRONMENT VARIABLES** section) and the default, which can be queried 104*5a6e8488SAndroid Build Coastguard Worker with the **-h** or **-\-help** options. 105*5a6e8488SAndroid Build Coastguard Worker 106*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 107*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 108*5a6e8488SAndroid Build Coastguard Worker 109*5a6e8488SAndroid Build Coastguard Worker**-E** *seed*, **-\-seed**=*seed* 110*5a6e8488SAndroid Build Coastguard Worker 111*5a6e8488SAndroid Build Coastguard Worker: Sets the builtin variable **seed** to the value *seed* assuming that *seed* 112*5a6e8488SAndroid Build Coastguard Worker is in base 10. It is a fatal error if *seed* is not a valid number. 113*5a6e8488SAndroid Build Coastguard Worker 114*5a6e8488SAndroid Build Coastguard Worker If multiple instances of this option are given, the last is used. 115*5a6e8488SAndroid Build Coastguard Worker 116*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 117*5a6e8488SAndroid Build Coastguard Worker{{ end }} 118*5a6e8488SAndroid Build Coastguard Worker 119*5a6e8488SAndroid Build Coastguard Worker**-e** *expr*, **-\-expression**=*expr* 120*5a6e8488SAndroid Build Coastguard Worker 121*5a6e8488SAndroid Build Coastguard Worker: Evaluates *expr*. If multiple expressions are given, they are evaluated in 122*5a6e8488SAndroid Build Coastguard Worker order. If files are given as well (see the **-f** and **-\-file** options), 123*5a6e8488SAndroid Build Coastguard Worker the expressions and files are evaluated in the order given. This means that 124*5a6e8488SAndroid Build Coastguard Worker if a file is given before an expression, the file is read in and evaluated 125*5a6e8488SAndroid Build Coastguard Worker first. 126*5a6e8488SAndroid Build Coastguard Worker 127*5a6e8488SAndroid Build Coastguard Worker If this option is given on the command-line (i.e., not in **BC_ENV_ARGS**, 128*5a6e8488SAndroid Build Coastguard Worker see the **ENVIRONMENT VARIABLES** section), then after processing all 129*5a6e8488SAndroid Build Coastguard Worker expressions and files, bc(1) will exit, unless **-** (**stdin**) was given 130*5a6e8488SAndroid Build Coastguard Worker as an argument at least once to **-f** or **-\-file**, whether on the 131*5a6e8488SAndroid Build Coastguard Worker command-line or in **BC_ENV_ARGS**. However, if any other **-e**, 132*5a6e8488SAndroid Build Coastguard Worker **-\-expression**, **-f**, or **-\-file** arguments are given after **-f-** 133*5a6e8488SAndroid Build Coastguard Worker or equivalent is given, bc(1) will give a fatal error and exit. 134*5a6e8488SAndroid Build Coastguard Worker 135*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 136*5a6e8488SAndroid Build Coastguard Worker 137*5a6e8488SAndroid Build Coastguard Worker**-f** *file*, **-\-file**=*file* 138*5a6e8488SAndroid Build Coastguard Worker 139*5a6e8488SAndroid Build Coastguard Worker: Reads in *file* and evaluates it, line by line, as though it were read 140*5a6e8488SAndroid Build Coastguard Worker through **stdin**. If expressions are also given (see the **-e** and 141*5a6e8488SAndroid Build Coastguard Worker **-\-expression** options), the expressions are evaluated in the order 142*5a6e8488SAndroid Build Coastguard Worker given. 143*5a6e8488SAndroid Build Coastguard Worker 144*5a6e8488SAndroid Build Coastguard Worker If this option is given on the command-line (i.e., not in **BC_ENV_ARGS**, 145*5a6e8488SAndroid Build Coastguard Worker see the **ENVIRONMENT VARIABLES** section), then after processing all 146*5a6e8488SAndroid Build Coastguard Worker expressions and files, bc(1) will exit, unless **-** (**stdin**) was given 147*5a6e8488SAndroid Build Coastguard Worker as an argument at least once to **-f** or **-\-file**. However, if any other 148*5a6e8488SAndroid Build Coastguard Worker **-e**, **-\-expression**, **-f**, or **-\-file** arguments are given after 149*5a6e8488SAndroid Build Coastguard Worker **-f-** or equivalent is given, bc(1) will give a fatal error and exit. 150*5a6e8488SAndroid Build Coastguard Worker 151*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 152*5a6e8488SAndroid Build Coastguard Worker 153*5a6e8488SAndroid Build Coastguard Worker**-g**, **-\-global-stacks** 154*5a6e8488SAndroid Build Coastguard Worker 155*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 156*5a6e8488SAndroid Build Coastguard Worker: Turns the globals **ibase**, **obase**, **scale**, and **seed** into stacks. 157*5a6e8488SAndroid Build Coastguard Worker 158*5a6e8488SAndroid Build Coastguard Worker This has the effect that a copy of the current value of all four are pushed 159*5a6e8488SAndroid Build Coastguard Worker{{ end }} 160*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 161*5a6e8488SAndroid Build Coastguard Worker: Turns the globals **ibase**, **obase**, and **scale** into stacks. 162*5a6e8488SAndroid Build Coastguard Worker 163*5a6e8488SAndroid Build Coastguard Worker This has the effect that a copy of the current value of all three are pushed 164*5a6e8488SAndroid Build Coastguard Worker{{ end }} 165*5a6e8488SAndroid Build Coastguard Worker onto a stack for every function call, as well as popped when every function 166*5a6e8488SAndroid Build Coastguard Worker returns. This means that functions can assign to any and all of those 167*5a6e8488SAndroid Build Coastguard Worker globals without worrying that the change will affect other functions. 168*5a6e8488SAndroid Build Coastguard Worker Thus, a hypothetical function named **output(x,b)** that simply printed 169*5a6e8488SAndroid Build Coastguard Worker **x** in base **b** could be written like this: 170*5a6e8488SAndroid Build Coastguard Worker 171*5a6e8488SAndroid Build Coastguard Worker define void output(x, b) { 172*5a6e8488SAndroid Build Coastguard Worker obase=b 173*5a6e8488SAndroid Build Coastguard Worker x 174*5a6e8488SAndroid Build Coastguard Worker } 175*5a6e8488SAndroid Build Coastguard Worker 176*5a6e8488SAndroid Build Coastguard Worker instead of like this: 177*5a6e8488SAndroid Build Coastguard Worker 178*5a6e8488SAndroid Build Coastguard Worker define void output(x, b) { 179*5a6e8488SAndroid Build Coastguard Worker auto c 180*5a6e8488SAndroid Build Coastguard Worker c=obase 181*5a6e8488SAndroid Build Coastguard Worker obase=b 182*5a6e8488SAndroid Build Coastguard Worker x 183*5a6e8488SAndroid Build Coastguard Worker obase=c 184*5a6e8488SAndroid Build Coastguard Worker } 185*5a6e8488SAndroid Build Coastguard Worker 186*5a6e8488SAndroid Build Coastguard Worker This makes writing functions much easier. 187*5a6e8488SAndroid Build Coastguard Worker 188*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 189*5a6e8488SAndroid Build Coastguard Worker (**Note**: the function **output(x,b)** exists in the extended math library. 190*5a6e8488SAndroid Build Coastguard Worker See the **LIBRARY** section.) 191*5a6e8488SAndroid Build Coastguard Worker 192*5a6e8488SAndroid Build Coastguard Worker However, since using this flag means that functions cannot set **ibase**, 193*5a6e8488SAndroid Build Coastguard Worker **obase**, **scale**, or **seed** globally, functions that are made to do so 194*5a6e8488SAndroid Build Coastguard Worker cannot work anymore. There are two possible use cases for that, and each has 195*5a6e8488SAndroid Build Coastguard Worker a solution. 196*5a6e8488SAndroid Build Coastguard Worker{{ end }} 197*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 198*5a6e8488SAndroid Build Coastguard Worker However, since using this flag means that functions cannot set **ibase**, 199*5a6e8488SAndroid Build Coastguard Worker **obase**, or **scale** globally, functions that are made to do so cannot 200*5a6e8488SAndroid Build Coastguard Worker work anymore. There are two possible use cases for that, and each has a 201*5a6e8488SAndroid Build Coastguard Worker solution. 202*5a6e8488SAndroid Build Coastguard Worker{{ end }} 203*5a6e8488SAndroid Build Coastguard Worker 204*5a6e8488SAndroid Build Coastguard Worker First, if a function is called on startup to turn bc(1) into a number 205*5a6e8488SAndroid Build Coastguard Worker converter, it is possible to replace that capability with various shell 206*5a6e8488SAndroid Build Coastguard Worker aliases. Examples: 207*5a6e8488SAndroid Build Coastguard Worker 208*5a6e8488SAndroid Build Coastguard Worker alias d2o="bc -e ibase=A -e obase=8" 209*5a6e8488SAndroid Build Coastguard Worker alias h2b="bc -e ibase=G -e obase=2" 210*5a6e8488SAndroid Build Coastguard Worker 211*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 212*5a6e8488SAndroid Build Coastguard Worker Second, if the purpose of a function is to set **ibase**, **obase**, 213*5a6e8488SAndroid Build Coastguard Worker **scale**, or **seed** globally for any other purpose, it could be split 214*5a6e8488SAndroid Build Coastguard Worker into one to four functions (based on how many globals it sets) and each of 215*5a6e8488SAndroid Build Coastguard Worker those functions could return the desired value for a global. 216*5a6e8488SAndroid Build Coastguard Worker 217*5a6e8488SAndroid Build Coastguard Worker For functions that set **seed**, the value assigned to **seed** is not 218*5a6e8488SAndroid Build Coastguard Worker propagated to parent functions. This means that the sequence of 219*5a6e8488SAndroid Build Coastguard Worker pseudo-random numbers that they see will not be the same sequence of 220*5a6e8488SAndroid Build Coastguard Worker pseudo-random numbers that any parent sees. This is only the case once 221*5a6e8488SAndroid Build Coastguard Worker **seed** has been set. 222*5a6e8488SAndroid Build Coastguard Worker 223*5a6e8488SAndroid Build Coastguard Worker If a function desires to not affect the sequence of pseudo-random numbers 224*5a6e8488SAndroid Build Coastguard Worker of its parents, but wants to use the same **seed**, it can use the following 225*5a6e8488SAndroid Build Coastguard Worker line: 226*5a6e8488SAndroid Build Coastguard Worker 227*5a6e8488SAndroid Build Coastguard Worker seed = seed 228*5a6e8488SAndroid Build Coastguard Worker{{ end }} 229*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 230*5a6e8488SAndroid Build Coastguard Worker Second, if the purpose of a function is to set **ibase**, **obase**, or 231*5a6e8488SAndroid Build Coastguard Worker **scale** globally for any other purpose, it could be split into one to 232*5a6e8488SAndroid Build Coastguard Worker three functions (based on how many globals it sets) and each of those 233*5a6e8488SAndroid Build Coastguard Worker functions could return the desired value for a global. 234*5a6e8488SAndroid Build Coastguard Worker{{ end }} 235*5a6e8488SAndroid Build Coastguard Worker 236*5a6e8488SAndroid Build Coastguard Worker If the behavior of this option is desired for every run of bc(1), then users 237*5a6e8488SAndroid Build Coastguard Worker could make sure to define **BC_ENV_ARGS** and include this option (see the 238*5a6e8488SAndroid Build Coastguard Worker **ENVIRONMENT VARIABLES** section for more details). 239*5a6e8488SAndroid Build Coastguard Worker 240*5a6e8488SAndroid Build Coastguard Worker If **-s**, **-w**, or any equivalents are used, this option is ignored. 241*5a6e8488SAndroid Build Coastguard Worker 242*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 243*5a6e8488SAndroid Build Coastguard Worker 244*5a6e8488SAndroid Build Coastguard Worker**-h**, **-\-help** 245*5a6e8488SAndroid Build Coastguard Worker 246*5a6e8488SAndroid Build Coastguard Worker: Prints a usage message and exits. 247*5a6e8488SAndroid Build Coastguard Worker 248*5a6e8488SAndroid Build Coastguard Worker**-I** *ibase*, **-\-ibase**=*ibase* 249*5a6e8488SAndroid Build Coastguard Worker 250*5a6e8488SAndroid Build Coastguard Worker: Sets the builtin variable **ibase** to the value *ibase* assuming that 251*5a6e8488SAndroid Build Coastguard Worker *ibase* is in base 10. It is a fatal error if *ibase* is not a valid number. 252*5a6e8488SAndroid Build Coastguard Worker 253*5a6e8488SAndroid Build Coastguard Worker If multiple instances of this option are given, the last is used. 254*5a6e8488SAndroid Build Coastguard Worker 255*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 256*5a6e8488SAndroid Build Coastguard Worker 257*5a6e8488SAndroid Build Coastguard Worker**-i**, **-\-interactive** 258*5a6e8488SAndroid Build Coastguard Worker 259*5a6e8488SAndroid Build Coastguard Worker: Forces interactive mode. (See the **INTERACTIVE MODE** section.) 260*5a6e8488SAndroid Build Coastguard Worker 261*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 262*5a6e8488SAndroid Build Coastguard Worker 263*5a6e8488SAndroid Build Coastguard Worker**-L**, **-\-no-line-length** 264*5a6e8488SAndroid Build Coastguard Worker 265*5a6e8488SAndroid Build Coastguard Worker: Disables line length checking and prints numbers without backslashes and 266*5a6e8488SAndroid Build Coastguard Worker newlines. In other words, this option sets **BC_LINE_LENGTH** to **0** (see 267*5a6e8488SAndroid Build Coastguard Worker the **ENVIRONMENT VARIABLES** section). 268*5a6e8488SAndroid Build Coastguard Worker 269*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 270*5a6e8488SAndroid Build Coastguard Worker 271*5a6e8488SAndroid Build Coastguard Worker**-l**, **-\-mathlib** 272*5a6e8488SAndroid Build Coastguard Worker 273*5a6e8488SAndroid Build Coastguard Worker: Sets **scale** (see the **SYNTAX** section) to **20** and loads the included 274*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 275*5a6e8488SAndroid Build Coastguard Worker math library and the extended math library before running any code, 276*5a6e8488SAndroid Build Coastguard Worker including any expressions or files specified on the command line. 277*5a6e8488SAndroid Build Coastguard Worker 278*5a6e8488SAndroid Build Coastguard Worker To learn what is in the libraries, see the **LIBRARY** section. 279*5a6e8488SAndroid Build Coastguard Worker{{ end }} 280*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 281*5a6e8488SAndroid Build Coastguard Worker math library before running any code, including any expressions or files 282*5a6e8488SAndroid Build Coastguard Worker specified on the command line. 283*5a6e8488SAndroid Build Coastguard Worker 284*5a6e8488SAndroid Build Coastguard Worker To learn what is in the library, see the **LIBRARY** section. 285*5a6e8488SAndroid Build Coastguard Worker{{ end }} 286*5a6e8488SAndroid Build Coastguard Worker 287*5a6e8488SAndroid Build Coastguard Worker**-O** *obase*, **-\-obase**=*obase* 288*5a6e8488SAndroid Build Coastguard Worker 289*5a6e8488SAndroid Build Coastguard Worker: Sets the builtin variable **obase** to the value *obase* assuming that 290*5a6e8488SAndroid Build Coastguard Worker *obase* is in base 10. It is a fatal error if *obase* is not a valid number. 291*5a6e8488SAndroid Build Coastguard Worker 292*5a6e8488SAndroid Build Coastguard Worker If multiple instances of this option are given, the last is used. 293*5a6e8488SAndroid Build Coastguard Worker 294*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 295*5a6e8488SAndroid Build Coastguard Worker 296*5a6e8488SAndroid Build Coastguard Worker**-P**, **-\-no-prompt** 297*5a6e8488SAndroid Build Coastguard Worker 298*5a6e8488SAndroid Build Coastguard Worker: Disables the prompt in TTY mode. (The prompt is only enabled in TTY mode. 299*5a6e8488SAndroid Build Coastguard Worker See the **TTY MODE** section.) This is mostly for those users that do not 300*5a6e8488SAndroid Build Coastguard Worker want a prompt or are not used to having them in bc(1). Most of those users 301*5a6e8488SAndroid Build Coastguard Worker would want to put this option in **BC_ENV_ARGS** (see the 302*5a6e8488SAndroid Build Coastguard Worker **ENVIRONMENT VARIABLES** section). 303*5a6e8488SAndroid Build Coastguard Worker 304*5a6e8488SAndroid Build Coastguard Worker These options override the **BC_PROMPT** and **BC_TTY_MODE** environment 305*5a6e8488SAndroid Build Coastguard Worker variables (see the **ENVIRONMENT VARIABLES** section). 306*5a6e8488SAndroid Build Coastguard Worker 307*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 308*5a6e8488SAndroid Build Coastguard Worker 309*5a6e8488SAndroid Build Coastguard Worker**-q**, **-\-quiet** 310*5a6e8488SAndroid Build Coastguard Worker 311*5a6e8488SAndroid Build Coastguard Worker: This option is for compatibility with the GNU bc(1) 312*5a6e8488SAndroid Build Coastguard Worker (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU 313*5a6e8488SAndroid Build Coastguard Worker bc(1) prints a copyright header. This bc(1) only prints the copyright header 314*5a6e8488SAndroid Build Coastguard Worker if one or more of the **-v**, **-V**, or **-\-version** options are given 315*5a6e8488SAndroid Build Coastguard Worker unless the **BC_BANNER** environment variable is set and contains a non-zero 316*5a6e8488SAndroid Build Coastguard Worker integer or if this bc(1) was built with the header displayed by default. If 317*5a6e8488SAndroid Build Coastguard Worker *any* of that is the case, then this option *does* prevent bc(1) from 318*5a6e8488SAndroid Build Coastguard Worker printing the header. 319*5a6e8488SAndroid Build Coastguard Worker 320*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 321*5a6e8488SAndroid Build Coastguard Worker 322*5a6e8488SAndroid Build Coastguard Worker**-R**, **-\-no-read-prompt** 323*5a6e8488SAndroid Build Coastguard Worker 324*5a6e8488SAndroid Build Coastguard Worker: Disables the read prompt in TTY mode. (The read prompt is only enabled in 325*5a6e8488SAndroid Build Coastguard Worker TTY mode. See the **TTY MODE** section.) This is mostly for those users that 326*5a6e8488SAndroid Build Coastguard Worker do not want a read prompt or are not used to having them in bc(1). Most of 327*5a6e8488SAndroid Build Coastguard Worker those users would want to put this option in **BC_ENV_ARGS** (see the 328*5a6e8488SAndroid Build Coastguard Worker **ENVIRONMENT VARIABLES** section). This option is also useful in hash bang 329*5a6e8488SAndroid Build Coastguard Worker lines of bc(1) scripts that prompt for user input. 330*5a6e8488SAndroid Build Coastguard Worker 331*5a6e8488SAndroid Build Coastguard Worker This option does not disable the regular prompt because the read prompt is 332*5a6e8488SAndroid Build Coastguard Worker only used when the **read()** built-in function is called. 333*5a6e8488SAndroid Build Coastguard Worker 334*5a6e8488SAndroid Build Coastguard Worker These options *do* override the **BC_PROMPT** and **BC_TTY_MODE** 335*5a6e8488SAndroid Build Coastguard Worker environment variables (see the **ENVIRONMENT VARIABLES** section), but only 336*5a6e8488SAndroid Build Coastguard Worker for the read prompt. 337*5a6e8488SAndroid Build Coastguard Worker 338*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 339*5a6e8488SAndroid Build Coastguard Worker 340*5a6e8488SAndroid Build Coastguard Worker**-r** *keyword*, **-\-redefine**=*keyword* 341*5a6e8488SAndroid Build Coastguard Worker 342*5a6e8488SAndroid Build Coastguard Worker: Redefines *keyword* in order to allow it to be used as a function, variable, 343*5a6e8488SAndroid Build Coastguard Worker or array name. This is useful when this bc(1) gives parse errors when 344*5a6e8488SAndroid Build Coastguard Worker parsing scripts meant for other bc(1) implementations. 345*5a6e8488SAndroid Build Coastguard Worker 346*5a6e8488SAndroid Build Coastguard Worker The keywords this bc(1) allows to be redefined are: 347*5a6e8488SAndroid Build Coastguard Worker 348*5a6e8488SAndroid Build Coastguard Worker * **abs** 349*5a6e8488SAndroid Build Coastguard Worker * **asciify** 350*5a6e8488SAndroid Build Coastguard Worker * **continue** 351*5a6e8488SAndroid Build Coastguard Worker * **divmod** 352*5a6e8488SAndroid Build Coastguard Worker * **else** 353*5a6e8488SAndroid Build Coastguard Worker * **halt** 354*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 355*5a6e8488SAndroid Build Coastguard Worker * **irand** 356*5a6e8488SAndroid Build Coastguard Worker{{ end }} 357*5a6e8488SAndroid Build Coastguard Worker * **last** 358*5a6e8488SAndroid Build Coastguard Worker * **limits** 359*5a6e8488SAndroid Build Coastguard Worker * **maxibase** 360*5a6e8488SAndroid Build Coastguard Worker * **maxobase** 361*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 362*5a6e8488SAndroid Build Coastguard Worker * **maxrand** 363*5a6e8488SAndroid Build Coastguard Worker{{ end }} 364*5a6e8488SAndroid Build Coastguard Worker * **maxscale** 365*5a6e8488SAndroid Build Coastguard Worker * **modexp** 366*5a6e8488SAndroid Build Coastguard Worker * **print** 367*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 368*5a6e8488SAndroid Build Coastguard Worker * **rand** 369*5a6e8488SAndroid Build Coastguard Worker{{ end }} 370*5a6e8488SAndroid Build Coastguard Worker * **read** 371*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 372*5a6e8488SAndroid Build Coastguard Worker * **seed** 373*5a6e8488SAndroid Build Coastguard Worker{{ end }} 374*5a6e8488SAndroid Build Coastguard Worker * **stream** 375*5a6e8488SAndroid Build Coastguard Worker 376*5a6e8488SAndroid Build Coastguard Worker If any of those keywords are used as a function, variable, or array name in 377*5a6e8488SAndroid Build Coastguard Worker a script, use this option with the keyword as the argument. If multiple are 378*5a6e8488SAndroid Build Coastguard Worker used, use this option for all of them; it can be used multiple times. 379*5a6e8488SAndroid Build Coastguard Worker 380*5a6e8488SAndroid Build Coastguard Worker Keywords are *not* redefined when parsing the builtin math library (see the 381*5a6e8488SAndroid Build Coastguard Worker **LIBRARY** section). 382*5a6e8488SAndroid Build Coastguard Worker 383*5a6e8488SAndroid Build Coastguard Worker It is a fatal error to redefine keywords mandated by the POSIX standard (see 384*5a6e8488SAndroid Build Coastguard Worker the **STANDARDS** section). It is a fatal error to attempt to redefine words 385*5a6e8488SAndroid Build Coastguard Worker that this bc(1) does not reserve as keywords. 386*5a6e8488SAndroid Build Coastguard Worker 387*5a6e8488SAndroid Build Coastguard Worker**-S** *scale*, **-\-scale**=*scale* 388*5a6e8488SAndroid Build Coastguard Worker 389*5a6e8488SAndroid Build Coastguard Worker: Sets the builtin variable **scale** to the value *scale* assuming that 390*5a6e8488SAndroid Build Coastguard Worker *scale* is in base 10. It is a fatal error if *scale* is not a valid number. 391*5a6e8488SAndroid Build Coastguard Worker 392*5a6e8488SAndroid Build Coastguard Worker If multiple instances of this option are given, the last is used. 393*5a6e8488SAndroid Build Coastguard Worker 394*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 395*5a6e8488SAndroid Build Coastguard Worker 396*5a6e8488SAndroid Build Coastguard Worker**-s**, **-\-standard** 397*5a6e8488SAndroid Build Coastguard Worker 398*5a6e8488SAndroid Build Coastguard Worker: Process exactly the language defined by the standard (see the **STANDARDS** 399*5a6e8488SAndroid Build Coastguard Worker section) and error if any extensions are used. 400*5a6e8488SAndroid Build Coastguard Worker 401*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 402*5a6e8488SAndroid Build Coastguard Worker 403*5a6e8488SAndroid Build Coastguard Worker**-v**, **-V**, **-\-version** 404*5a6e8488SAndroid Build Coastguard Worker 405*5a6e8488SAndroid Build Coastguard Worker: Print the version information (copyright header) and exits. 406*5a6e8488SAndroid Build Coastguard Worker 407*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 408*5a6e8488SAndroid Build Coastguard Worker 409*5a6e8488SAndroid Build Coastguard Worker**-w**, **-\-warn** 410*5a6e8488SAndroid Build Coastguard Worker 411*5a6e8488SAndroid Build Coastguard Worker: Like **-s** and **-\-standard**, except that warnings (and not errors) are 412*5a6e8488SAndroid Build Coastguard Worker printed for non-standard extensions and execution continues normally. 413*5a6e8488SAndroid Build Coastguard Worker 414*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 415*5a6e8488SAndroid Build Coastguard Worker 416*5a6e8488SAndroid Build Coastguard Worker**-z**, **-\-leading-zeroes** 417*5a6e8488SAndroid Build Coastguard Worker 418*5a6e8488SAndroid Build Coastguard Worker: Makes bc(1) print all numbers greater than **-1** and less than **1**, and 419*5a6e8488SAndroid Build Coastguard Worker not equal to **0**, with a leading zero. 420*5a6e8488SAndroid Build Coastguard Worker 421*5a6e8488SAndroid Build Coastguard Worker This can be set for individual numbers with the **plz(x)**, **plznl(x)**, 422*5a6e8488SAndroid Build Coastguard Worker **pnlz(x)**, and **pnlznl(x)** functions in the extended math library (see 423*5a6e8488SAndroid Build Coastguard Worker the **LIBRARY** section). 424*5a6e8488SAndroid Build Coastguard Worker 425*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 426*5a6e8488SAndroid Build Coastguard Worker 427*5a6e8488SAndroid Build Coastguard WorkerAll long options are **non-portable extensions**. 428*5a6e8488SAndroid Build Coastguard Worker 429*5a6e8488SAndroid Build Coastguard Worker# STDIN 430*5a6e8488SAndroid Build Coastguard Worker 431*5a6e8488SAndroid Build Coastguard WorkerIf no files or expressions are given by the **-f**, **-\-file**, **-e**, or 432*5a6e8488SAndroid Build Coastguard Worker**-\-expression** options, then bc(1) reads from **stdin**. 433*5a6e8488SAndroid Build Coastguard Worker 434*5a6e8488SAndroid Build Coastguard WorkerHowever, there are a few caveats to this. 435*5a6e8488SAndroid Build Coastguard Worker 436*5a6e8488SAndroid Build Coastguard WorkerFirst, **stdin** is evaluated a line at a time. The only exception to this is if 437*5a6e8488SAndroid Build Coastguard Workerthe parse cannot complete. That means that starting a string without ending it 438*5a6e8488SAndroid Build Coastguard Workeror starting a function, **if** statement, or loop without ending it will also 439*5a6e8488SAndroid Build Coastguard Workercause bc(1) to not execute. 440*5a6e8488SAndroid Build Coastguard Worker 441*5a6e8488SAndroid Build Coastguard WorkerSecond, after an **if** statement, bc(1) doesn't know if an **else** statement 442*5a6e8488SAndroid Build Coastguard Workerwill follow, so it will not execute until it knows there will not be an **else** 443*5a6e8488SAndroid Build Coastguard Workerstatement. 444*5a6e8488SAndroid Build Coastguard Worker 445*5a6e8488SAndroid Build Coastguard Worker# STDOUT 446*5a6e8488SAndroid Build Coastguard Worker 447*5a6e8488SAndroid Build Coastguard WorkerAny non-error output is written to **stdout**. In addition, if history (see the 448*5a6e8488SAndroid Build Coastguard Worker**HISTORY** section) and the prompt (see the **TTY MODE** section) are enabled, 449*5a6e8488SAndroid Build Coastguard Workerboth are output to **stdout**. 450*5a6e8488SAndroid Build Coastguard Worker 451*5a6e8488SAndroid Build Coastguard Worker**Note**: Unlike other bc(1) implementations, this bc(1) will issue a fatal 452*5a6e8488SAndroid Build Coastguard Workererror (see the **EXIT STATUS** section) if it cannot write to **stdout**, so if 453*5a6e8488SAndroid Build Coastguard Worker**stdout** is closed, as in **bc <file> >&-**, it will quit with an error. This 454*5a6e8488SAndroid Build Coastguard Workeris done so that bc(1) can report problems when **stdout** is redirected to a 455*5a6e8488SAndroid Build Coastguard Workerfile. 456*5a6e8488SAndroid Build Coastguard Worker 457*5a6e8488SAndroid Build Coastguard WorkerIf there are scripts that depend on the behavior of other bc(1) implementations, 458*5a6e8488SAndroid Build Coastguard Workerit is recommended that those scripts be changed to redirect **stdout** to 459*5a6e8488SAndroid Build Coastguard Worker**/dev/null**. 460*5a6e8488SAndroid Build Coastguard Worker 461*5a6e8488SAndroid Build Coastguard Worker# STDERR 462*5a6e8488SAndroid Build Coastguard Worker 463*5a6e8488SAndroid Build Coastguard WorkerAny error output is written to **stderr**. 464*5a6e8488SAndroid Build Coastguard Worker 465*5a6e8488SAndroid Build Coastguard Worker**Note**: Unlike other bc(1) implementations, this bc(1) will issue a fatal 466*5a6e8488SAndroid Build Coastguard Workererror (see the **EXIT STATUS** section) if it cannot write to **stderr**, so if 467*5a6e8488SAndroid Build Coastguard Worker**stderr** is closed, as in **bc <file> 2>&-**, it will quit with an error. This 468*5a6e8488SAndroid Build Coastguard Workeris done so that bc(1) can exit with an error code when **stderr** is redirected 469*5a6e8488SAndroid Build Coastguard Workerto a file. 470*5a6e8488SAndroid Build Coastguard Worker 471*5a6e8488SAndroid Build Coastguard WorkerIf there are scripts that depend on the behavior of other bc(1) implementations, 472*5a6e8488SAndroid Build Coastguard Workerit is recommended that those scripts be changed to redirect **stderr** to 473*5a6e8488SAndroid Build Coastguard Worker**/dev/null**. 474*5a6e8488SAndroid Build Coastguard Worker 475*5a6e8488SAndroid Build Coastguard Worker# SYNTAX 476*5a6e8488SAndroid Build Coastguard Worker 477*5a6e8488SAndroid Build Coastguard WorkerThe syntax for bc(1) programs is mostly C-like, with some differences. This 478*5a6e8488SAndroid Build Coastguard Workerbc(1) follows the POSIX standard (see the **STANDARDS** section), which is a 479*5a6e8488SAndroid Build Coastguard Workermuch more thorough resource for the language this bc(1) accepts. This section is 480*5a6e8488SAndroid Build Coastguard Workermeant to be a summary and a listing of all the extensions to the standard. 481*5a6e8488SAndroid Build Coastguard Worker 482*5a6e8488SAndroid Build Coastguard WorkerIn the sections below, **E** means expression, **S** means statement, and **I** 483*5a6e8488SAndroid Build Coastguard Workermeans identifier. 484*5a6e8488SAndroid Build Coastguard Worker 485*5a6e8488SAndroid Build Coastguard WorkerIdentifiers (**I**) start with a lowercase letter and can be followed by any 486*5a6e8488SAndroid Build Coastguard Workernumber (up to **BC_NAME_MAX-1**) of lowercase letters (**a-z**), digits 487*5a6e8488SAndroid Build Coastguard Worker(**0-9**), and underscores (**\_**). The regex is **\[a-z\]\[a-z0-9\_\]\***. 488*5a6e8488SAndroid Build Coastguard WorkerIdentifiers with more than one character (letter) are a 489*5a6e8488SAndroid Build Coastguard Worker**non-portable extension**. 490*5a6e8488SAndroid Build Coastguard Worker 491*5a6e8488SAndroid Build Coastguard Worker**ibase** is a global variable determining how to interpret constant numbers. It 492*5a6e8488SAndroid Build Coastguard Workeris the "input" base, or the number base used for interpreting input numbers. 493*5a6e8488SAndroid Build Coastguard Worker**ibase** is initially **10**. If the **-s** (**-\-standard**) and **-w** 494*5a6e8488SAndroid Build Coastguard Worker(**-\-warn**) flags were not given on the command line, the max allowable value 495*5a6e8488SAndroid Build Coastguard Workerfor **ibase** is **36**. Otherwise, it is **16**. The min allowable value for 496*5a6e8488SAndroid Build Coastguard Worker**ibase** is **2**. The max allowable value for **ibase** can be queried in 497*5a6e8488SAndroid Build Coastguard Workerbc(1) programs with the **maxibase()** built-in function. 498*5a6e8488SAndroid Build Coastguard Worker 499*5a6e8488SAndroid Build Coastguard Worker**obase** is a global variable determining how to output results. It is the 500*5a6e8488SAndroid Build Coastguard Worker"output" base, or the number base used for outputting numbers. **obase** is 501*5a6e8488SAndroid Build Coastguard Workerinitially **10**. The max allowable value for **obase** is **BC_BASE_MAX** and 502*5a6e8488SAndroid Build Coastguard Workercan be queried in bc(1) programs with the **maxobase()** built-in function. The 503*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 504*5a6e8488SAndroid Build Coastguard Workermin allowable value for **obase** is **0**. If **obase** is **0**, values are 505*5a6e8488SAndroid Build Coastguard Workeroutput in scientific notation, and if **obase** is **1**, values are output in 506*5a6e8488SAndroid Build Coastguard Workerengineering notation. Otherwise, values are output in the specified base. 507*5a6e8488SAndroid Build Coastguard Worker 508*5a6e8488SAndroid Build Coastguard WorkerOutputting in scientific and engineering notations are **non-portable 509*5a6e8488SAndroid Build Coastguard Workerextensions**. 510*5a6e8488SAndroid Build Coastguard Worker{{ end }} 511*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 512*5a6e8488SAndroid Build Coastguard Workermin allowable value for **obase** is **2**. Values are output in the specified 513*5a6e8488SAndroid Build Coastguard Workerbase. 514*5a6e8488SAndroid Build Coastguard Worker{{ end }} 515*5a6e8488SAndroid Build Coastguard Worker 516*5a6e8488SAndroid Build Coastguard WorkerThe *scale* of an expression is the number of digits in the result of the 517*5a6e8488SAndroid Build Coastguard Workerexpression right of the decimal point, and **scale** is a global variable that 518*5a6e8488SAndroid Build Coastguard Workersets the precision of any operations, with exceptions. **scale** is initially 519*5a6e8488SAndroid Build Coastguard Worker**0**. **scale** cannot be negative. The max allowable value for **scale** is 520*5a6e8488SAndroid Build Coastguard Worker**BC_SCALE_MAX** and can be queried in bc(1) programs with the **maxscale()** 521*5a6e8488SAndroid Build Coastguard Workerbuilt-in function. 522*5a6e8488SAndroid Build Coastguard Worker 523*5a6e8488SAndroid Build Coastguard Workerbc(1) has both *global* variables and *local* variables. All *local* 524*5a6e8488SAndroid Build Coastguard Workervariables are local to the function; they are parameters or are introduced in 525*5a6e8488SAndroid Build Coastguard Workerthe **auto** list of a function (see the **FUNCTIONS** section). If a variable 526*5a6e8488SAndroid Build Coastguard Workeris accessed which is not a parameter or in the **auto** list, it is assumed to 527*5a6e8488SAndroid Build Coastguard Workerbe *global*. If a parent function has a *local* variable version of a variable 528*5a6e8488SAndroid Build Coastguard Workerthat a child function considers *global*, the value of that *global* variable in 529*5a6e8488SAndroid Build Coastguard Workerthe child function is the value of the variable in the parent function, not the 530*5a6e8488SAndroid Build Coastguard Workervalue of the actual *global* variable. 531*5a6e8488SAndroid Build Coastguard Worker 532*5a6e8488SAndroid Build Coastguard WorkerAll of the above applies to arrays as well. 533*5a6e8488SAndroid Build Coastguard Worker 534*5a6e8488SAndroid Build Coastguard WorkerThe value of a statement that is an expression (i.e., any of the named 535*5a6e8488SAndroid Build Coastguard Workerexpressions or operands) is printed unless the lowest precedence operator is an 536*5a6e8488SAndroid Build Coastguard Workerassignment operator *and* the expression is notsurrounded by parentheses. 537*5a6e8488SAndroid Build Coastguard Worker 538*5a6e8488SAndroid Build Coastguard WorkerThe value that is printed is also assigned to the special variable **last**. A 539*5a6e8488SAndroid Build Coastguard Workersingle dot (**.**) may also be used as a synonym for **last**. These are 540*5a6e8488SAndroid Build Coastguard Worker**non-portable extensions**. 541*5a6e8488SAndroid Build Coastguard Worker 542*5a6e8488SAndroid Build Coastguard WorkerEither semicolons or newlines may separate statements. 543*5a6e8488SAndroid Build Coastguard Worker 544*5a6e8488SAndroid Build Coastguard Worker## Comments 545*5a6e8488SAndroid Build Coastguard Worker 546*5a6e8488SAndroid Build Coastguard WorkerThere are two kinds of comments: 547*5a6e8488SAndroid Build Coastguard Worker 548*5a6e8488SAndroid Build Coastguard Worker1. Block comments are enclosed in **/\*** and **\*/**. 549*5a6e8488SAndroid Build Coastguard Worker2. Line comments go from **#** until, and not including, the next newline. This 550*5a6e8488SAndroid Build Coastguard Worker is a **non-portable extension**. 551*5a6e8488SAndroid Build Coastguard Worker 552*5a6e8488SAndroid Build Coastguard Worker## Named Expressions 553*5a6e8488SAndroid Build Coastguard Worker 554*5a6e8488SAndroid Build Coastguard WorkerThe following are named expressions in bc(1): 555*5a6e8488SAndroid Build Coastguard Worker 556*5a6e8488SAndroid Build Coastguard Worker1. Variables: **I** 557*5a6e8488SAndroid Build Coastguard Worker2. Array Elements: **I[E]** 558*5a6e8488SAndroid Build Coastguard Worker3. **ibase** 559*5a6e8488SAndroid Build Coastguard Worker4. **obase** 560*5a6e8488SAndroid Build Coastguard Worker5. **scale** 561*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 562*5a6e8488SAndroid Build Coastguard Worker6. **seed** 563*5a6e8488SAndroid Build Coastguard Worker7. **last** or a single dot (**.**) 564*5a6e8488SAndroid Build Coastguard Worker 565*5a6e8488SAndroid Build Coastguard WorkerNumbers 6 and 7 are **non-portable extensions**. 566*5a6e8488SAndroid Build Coastguard Worker 567*5a6e8488SAndroid Build Coastguard WorkerThe meaning of **seed** is dependent on the current pseudo-random number 568*5a6e8488SAndroid Build Coastguard Workergenerator but is guaranteed to not change except for new major versions. 569*5a6e8488SAndroid Build Coastguard Worker 570*5a6e8488SAndroid Build Coastguard WorkerThe *scale* and sign of the value may be significant. 571*5a6e8488SAndroid Build Coastguard Worker 572*5a6e8488SAndroid Build Coastguard WorkerIf a previously used **seed** value is assigned to **seed** and used again, the 573*5a6e8488SAndroid Build Coastguard Workerpseudo-random number generator is guaranteed to produce the same sequence of 574*5a6e8488SAndroid Build Coastguard Workerpseudo-random numbers as it did when the **seed** value was previously used. 575*5a6e8488SAndroid Build Coastguard Worker 576*5a6e8488SAndroid Build Coastguard WorkerThe exact value assigned to **seed** is not guaranteed to be returned if 577*5a6e8488SAndroid Build Coastguard Worker**seed** is queried again immediately. However, if **seed** *does* return a 578*5a6e8488SAndroid Build Coastguard Workerdifferent value, both values, when assigned to **seed**, are guaranteed to 579*5a6e8488SAndroid Build Coastguard Workerproduce the same sequence of pseudo-random numbers. This means that certain 580*5a6e8488SAndroid Build Coastguard Workervalues assigned to **seed** will *not* produce unique sequences of pseudo-random 581*5a6e8488SAndroid Build Coastguard Workernumbers. The value of **seed** will change after any use of the **rand()** and 582*5a6e8488SAndroid Build Coastguard Worker**irand(E)** operands (see the *Operands* subsection below), except if the 583*5a6e8488SAndroid Build Coastguard Workerparameter passed to **irand(E)** is **0**, **1**, or negative. 584*5a6e8488SAndroid Build Coastguard Worker 585*5a6e8488SAndroid Build Coastguard WorkerThere is no limit to the length (number of significant decimal digits) or 586*5a6e8488SAndroid Build Coastguard Worker*scale* of the value that can be assigned to **seed**. 587*5a6e8488SAndroid Build Coastguard Worker{{ end }} 588*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 589*5a6e8488SAndroid Build Coastguard Worker6. **last** or a single dot (**.**) 590*5a6e8488SAndroid Build Coastguard Worker 591*5a6e8488SAndroid Build Coastguard WorkerNumber 6 is a **non-portable extension**. 592*5a6e8488SAndroid Build Coastguard Worker{{ end }} 593*5a6e8488SAndroid Build Coastguard Worker 594*5a6e8488SAndroid Build Coastguard WorkerVariables and arrays do not interfere; users can have arrays named the same as 595*5a6e8488SAndroid Build Coastguard Workervariables. This also applies to functions (see the **FUNCTIONS** section), so a 596*5a6e8488SAndroid Build Coastguard Workeruser can have a variable, array, and function that all have the same name, and 597*5a6e8488SAndroid Build Coastguard Workerthey will not shadow each other, whether inside of functions or not. 598*5a6e8488SAndroid Build Coastguard Worker 599*5a6e8488SAndroid Build Coastguard WorkerNamed expressions are required as the operand of **increment**/**decrement** 600*5a6e8488SAndroid Build Coastguard Workeroperators and as the left side of **assignment** operators (see the *Operators* 601*5a6e8488SAndroid Build Coastguard Workersubsection). 602*5a6e8488SAndroid Build Coastguard Worker 603*5a6e8488SAndroid Build Coastguard Worker## Operands 604*5a6e8488SAndroid Build Coastguard Worker 605*5a6e8488SAndroid Build Coastguard WorkerThe following are valid operands in bc(1): 606*5a6e8488SAndroid Build Coastguard Worker 607*5a6e8488SAndroid Build Coastguard Worker1. Numbers (see the *Numbers* subsection below). 608*5a6e8488SAndroid Build Coastguard Worker2. Array indices (**I[E]**). 609*5a6e8488SAndroid Build Coastguard Worker3. **(E)**: The value of **E** (used to change precedence). 610*5a6e8488SAndroid Build Coastguard Worker4. **sqrt(E)**: The square root of **E**. **E** must be non-negative. 611*5a6e8488SAndroid Build Coastguard Worker5. **length(E)**: The number of significant decimal digits in **E**. Returns 612*5a6e8488SAndroid Build Coastguard Worker **1** for **0** with no decimal places. If given a string, the length of the 613*5a6e8488SAndroid Build Coastguard Worker string is returned. Passing a string to **length(E)** is a **non-portable 614*5a6e8488SAndroid Build Coastguard Worker extension**. 615*5a6e8488SAndroid Build Coastguard Worker6. **length(I[])**: The number of elements in the array **I**. This is a 616*5a6e8488SAndroid Build Coastguard Worker **non-portable extension**. 617*5a6e8488SAndroid Build Coastguard Worker7. **scale(E)**: The *scale* of **E**. 618*5a6e8488SAndroid Build Coastguard Worker8. **abs(E)**: The absolute value of **E**. This is a **non-portable 619*5a6e8488SAndroid Build Coastguard Worker extension**. 620*5a6e8488SAndroid Build Coastguard Worker9. **is_number(E)**: **1** if the given argument is a number, **0** if it is a 621*5a6e8488SAndroid Build Coastguard Worker string. This is a **non-portable extension**. 622*5a6e8488SAndroid Build Coastguard Worker10. **is_string(E)**: **1** if the given argument is a string, **0** if it is a 623*5a6e8488SAndroid Build Coastguard Worker number. This is a **non-portable extension**. 624*5a6e8488SAndroid Build Coastguard Worker11. **modexp(E, E, E)**: Modular exponentiation, where the first expression is 625*5a6e8488SAndroid Build Coastguard Worker the base, the second is the exponent, and the third is the modulus. All 626*5a6e8488SAndroid Build Coastguard Worker three values must be integers. The second argument must be non-negative. The 627*5a6e8488SAndroid Build Coastguard Worker third argument must be non-zero. This is a **non-portable extension**. 628*5a6e8488SAndroid Build Coastguard Worker11. **divmod(E, E, I[])**: Division and modulus in one operation. This is for 629*5a6e8488SAndroid Build Coastguard Worker optimization. The first expression is the dividend, and the second is the 630*5a6e8488SAndroid Build Coastguard Worker divisor, which must be non-zero. The return value is the quotient, and the 631*5a6e8488SAndroid Build Coastguard Worker modulus is stored in index **0** of the provided array (the last argument). 632*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 633*5a6e8488SAndroid Build Coastguard Worker12. **asciify(E)**: If **E** is a string, returns a string that is the first 634*5a6e8488SAndroid Build Coastguard Worker letter of its argument. If it is a number, calculates the number mod **256** 635*5a6e8488SAndroid Build Coastguard Worker and returns that number as a one-character string. This is a **non-portable 636*5a6e8488SAndroid Build Coastguard Worker extension**. 637*5a6e8488SAndroid Build Coastguard Worker13. **asciify(I[])**: A string that is made up of the characters that would 638*5a6e8488SAndroid Build Coastguard Worker result from running **asciify(E)** on each element of the array identified 639*5a6e8488SAndroid Build Coastguard Worker by the argument. This allows creating multi-character strings and storing 640*5a6e8488SAndroid Build Coastguard Worker them. This is a **non-portable extension**. 641*5a6e8488SAndroid Build Coastguard Worker14. **I()**, **I(E)**, **I(E, E)**, and so on, where **I** is an identifier for 642*5a6e8488SAndroid Build Coastguard Worker a non-**void** function (see the *Void Functions* subsection of the 643*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). The **E** argument(s) may also be arrays of the form 644*5a6e8488SAndroid Build Coastguard Worker **I[]**, which will automatically be turned into array references (see the 645*5a6e8488SAndroid Build Coastguard Worker *Array References* subsection of the **FUNCTIONS** section) if the 646*5a6e8488SAndroid Build Coastguard Worker corresponding parameter in the function definition is an array reference. 647*5a6e8488SAndroid Build Coastguard Worker15. **read()**: Reads a line from **stdin** and uses that as an expression. The 648*5a6e8488SAndroid Build Coastguard Worker result of that expression is the result of the **read()** operand. This is a 649*5a6e8488SAndroid Build Coastguard Worker **non-portable extension**. 650*5a6e8488SAndroid Build Coastguard Worker16. **maxibase()**: The max allowable **ibase**. This is a **non-portable 651*5a6e8488SAndroid Build Coastguard Worker extension**. 652*5a6e8488SAndroid Build Coastguard Worker17. **maxobase()**: The max allowable **obase**. This is a **non-portable 653*5a6e8488SAndroid Build Coastguard Worker extension**. 654*5a6e8488SAndroid Build Coastguard Worker18. **maxscale()**: The max allowable **scale**. This is a **non-portable 655*5a6e8488SAndroid Build Coastguard Worker extension**. 656*5a6e8488SAndroid Build Coastguard Worker19. **line_length()**: The line length set with **BC_LINE_LENGTH** (see the 657*5a6e8488SAndroid Build Coastguard Worker **ENVIRONMENT VARIABLES** section). This is a **non-portable extension**. 658*5a6e8488SAndroid Build Coastguard Worker20. **global_stacks()**: **0** if global stacks are not enabled with the **-g** 659*5a6e8488SAndroid Build Coastguard Worker or **-\-global-stacks** options, non-zero otherwise. See the **OPTIONS** 660*5a6e8488SAndroid Build Coastguard Worker section. This is a **non-portable extension**. 661*5a6e8488SAndroid Build Coastguard Worker21. **leading_zero()**: **0** if leading zeroes are not enabled with the **-z** 662*5a6e8488SAndroid Build Coastguard Worker or **--leading-zeroes** options, non-zero otherwise. See the **OPTIONS** 663*5a6e8488SAndroid Build Coastguard Worker section. This is a **non-portable extension**. 664*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 665*5a6e8488SAndroid Build Coastguard Worker22. **rand()**: A pseudo-random integer between **0** (inclusive) and 666*5a6e8488SAndroid Build Coastguard Worker **BC_RAND_MAX** (inclusive). Using this operand will change the value of 667*5a6e8488SAndroid Build Coastguard Worker **seed**. This is a **non-portable extension**. 668*5a6e8488SAndroid Build Coastguard Worker23. **irand(E)**: A pseudo-random integer between **0** (inclusive) and the 669*5a6e8488SAndroid Build Coastguard Worker value of **E** (exclusive). If **E** is negative or is a non-integer 670*5a6e8488SAndroid Build Coastguard Worker (**E**'s *scale* is not **0**), an error is raised, and bc(1) resets (see 671*5a6e8488SAndroid Build Coastguard Worker the **RESET** section) while **seed** remains unchanged. If **E** is larger 672*5a6e8488SAndroid Build Coastguard Worker than **BC_RAND_MAX**, the higher bound is honored by generating several 673*5a6e8488SAndroid Build Coastguard Worker pseudo-random integers, multiplying them by appropriate powers of 674*5a6e8488SAndroid Build Coastguard Worker **BC_RAND_MAX+1**, and adding them together. Thus, the size of integer that 675*5a6e8488SAndroid Build Coastguard Worker can be generated with this operand is unbounded. Using this operand will 676*5a6e8488SAndroid Build Coastguard Worker change the value of **seed**, unless the value of **E** is **0** or **1**. 677*5a6e8488SAndroid Build Coastguard Worker In that case, **0** is returned, and **seed** is *not* changed. This is a 678*5a6e8488SAndroid Build Coastguard Worker **non-portable extension**. 679*5a6e8488SAndroid Build Coastguard Worker24. **maxrand()**: The max integer returned by **rand()**. This is a 680*5a6e8488SAndroid Build Coastguard Worker **non-portable extension**. 681*5a6e8488SAndroid Build Coastguard Worker 682*5a6e8488SAndroid Build Coastguard WorkerThe integers generated by **rand()** and **irand(E)** are guaranteed to be as 683*5a6e8488SAndroid Build Coastguard Workerunbiased as possible, subject to the limitations of the pseudo-random number 684*5a6e8488SAndroid Build Coastguard Workergenerator. 685*5a6e8488SAndroid Build Coastguard Worker 686*5a6e8488SAndroid Build Coastguard Worker**Note**: The values returned by the pseudo-random number generator with 687*5a6e8488SAndroid Build Coastguard Worker**rand()** and **irand(E)** are guaranteed to *NOT* be cryptographically secure. 688*5a6e8488SAndroid Build Coastguard WorkerThis is a consequence of using a seeded pseudo-random number generator. However, 689*5a6e8488SAndroid Build Coastguard Workerthey *are* guaranteed to be reproducible with identical **seed** values. This 690*5a6e8488SAndroid Build Coastguard Workermeans that the pseudo-random values from bc(1) should only be used where a 691*5a6e8488SAndroid Build Coastguard Workerreproducible stream of pseudo-random numbers is *ESSENTIAL*. In any other case, 692*5a6e8488SAndroid Build Coastguard Workeruse a non-seeded pseudo-random number generator. 693*5a6e8488SAndroid Build Coastguard Worker{{ end }} 694*5a6e8488SAndroid Build Coastguard Worker 695*5a6e8488SAndroid Build Coastguard Worker## Numbers 696*5a6e8488SAndroid Build Coastguard Worker 697*5a6e8488SAndroid Build Coastguard WorkerNumbers are strings made up of digits, uppercase letters, and at most **1** 698*5a6e8488SAndroid Build Coastguard Workerperiod for a radix. Numbers can have up to **BC_NUM_MAX** digits. Uppercase 699*5a6e8488SAndroid Build Coastguard Workerletters are equal to **9** plus their position in the alphabet, starting from 700*5a6e8488SAndroid Build Coastguard Worker**1** (i.e., **A** equals **10**, or **9+1**). 701*5a6e8488SAndroid Build Coastguard Worker 702*5a6e8488SAndroid Build Coastguard WorkerIf a digit or letter makes no sense with the current value of **ibase** (i.e., 703*5a6e8488SAndroid Build Coastguard Workerthey are greater than or equal to the current value of **ibase**), then the 704*5a6e8488SAndroid Build Coastguard Workerbehavior depends on the existence of the **-c**/**-\-digit-clamp** or 705*5a6e8488SAndroid Build Coastguard Worker**-C**/**-\-no-digit-clamp** options (see the **OPTIONS** section), the 706*5a6e8488SAndroid Build Coastguard Workerexistence and setting of the **BC_DIGIT_CLAMP** environment variable (see the 707*5a6e8488SAndroid Build Coastguard Worker**ENVIRONMENT VARIABLES** section), or the default, which can be queried with 708*5a6e8488SAndroid Build Coastguard Workerthe **-h**/**-\-help** option. 709*5a6e8488SAndroid Build Coastguard Worker 710*5a6e8488SAndroid Build Coastguard WorkerIf clamping is off, then digits or letters that are greater than or equal to the 711*5a6e8488SAndroid Build Coastguard Workercurrent value of **ibase** are not changed. Instead, their given value is 712*5a6e8488SAndroid Build Coastguard Workermultiplied by the appropriate power of **ibase** and added into the number. This 713*5a6e8488SAndroid Build Coastguard Workermeans that, with an **ibase** of **3**, the number **AB** is equal to 714*5a6e8488SAndroid Build Coastguard Worker**3\^1\*A+3\^0\*B**, which is **3** times **10** plus **11**, or **41**. 715*5a6e8488SAndroid Build Coastguard Worker 716*5a6e8488SAndroid Build Coastguard WorkerIf clamping is on, then digits or letters that are greater than or equal to the 717*5a6e8488SAndroid Build Coastguard Workercurrent value of **ibase** are set to the value of the highest valid digit in 718*5a6e8488SAndroid Build Coastguard Worker**ibase** before being multiplied by the appropriate power of **ibase** and 719*5a6e8488SAndroid Build Coastguard Workeradded into the number. This means that, with an **ibase** of **3**, the number 720*5a6e8488SAndroid Build Coastguard Worker**AB** is equal to **3\^1\*2+3\^0\*2**, which is **3** times **2** plus **2**, 721*5a6e8488SAndroid Build Coastguard Workeror **8**. 722*5a6e8488SAndroid Build Coastguard Worker 723*5a6e8488SAndroid Build Coastguard WorkerThere is one exception to clamping: single-character numbers (i.e., **A** 724*5a6e8488SAndroid Build Coastguard Workeralone). Such numbers are never clamped and always take the value they would have 725*5a6e8488SAndroid Build Coastguard Workerin the highest possible **ibase**. This means that **A** alone always equals 726*5a6e8488SAndroid Build Coastguard Workerdecimal **10** and **Z** alone always equals decimal **35**. This behavior is 727*5a6e8488SAndroid Build Coastguard Workermandated by the standard (see the STANDARDS section) and is meant to provide an 728*5a6e8488SAndroid Build Coastguard Workereasy way to set the current **ibase** (with the **i** command) regardless of the 729*5a6e8488SAndroid Build Coastguard Workercurrent value of **ibase**. 730*5a6e8488SAndroid Build Coastguard Worker 731*5a6e8488SAndroid Build Coastguard WorkerIf clamping is on, and the clamped value of a character is needed, use a leading 732*5a6e8488SAndroid Build Coastguard Workerzero, i.e., for **A**, use **0A**. 733*5a6e8488SAndroid Build Coastguard Worker 734*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 735*5a6e8488SAndroid Build Coastguard WorkerIn addition, bc(1) accepts numbers in scientific notation. These have the form 736*5a6e8488SAndroid Build Coastguard Worker**\<number\>e\<integer\>**. The exponent (the portion after the **e**) must be 737*5a6e8488SAndroid Build Coastguard Workeran integer. An example is **1.89237e9**, which is equal to **1892370000**. 738*5a6e8488SAndroid Build Coastguard WorkerNegative exponents are also allowed, so **4.2890e-3** is equal to **0.0042890**. 739*5a6e8488SAndroid Build Coastguard Worker 740*5a6e8488SAndroid Build Coastguard WorkerUsing scientific notation is an error or warning if the **-s** or **-w**, 741*5a6e8488SAndroid Build Coastguard Workerrespectively, command-line options (or equivalents) are given. 742*5a6e8488SAndroid Build Coastguard Worker 743*5a6e8488SAndroid Build Coastguard Worker**WARNING**: Both the number and the exponent in scientific notation are 744*5a6e8488SAndroid Build Coastguard Workerinterpreted according to the current **ibase**, but the number is still 745*5a6e8488SAndroid Build Coastguard Workermultiplied by **10\^exponent** regardless of the current **ibase**. For example, 746*5a6e8488SAndroid Build Coastguard Workerif **ibase** is **16** and bc(1) is given the number string **FFeA**, the 747*5a6e8488SAndroid Build Coastguard Workerresulting decimal number will be **2550000000000**, and if bc(1) is given the 748*5a6e8488SAndroid Build Coastguard Workernumber string **10e-4**, the resulting decimal number will be **0.0016**. 749*5a6e8488SAndroid Build Coastguard Worker 750*5a6e8488SAndroid Build Coastguard WorkerAccepting input as scientific notation is a **non-portable extension**. 751*5a6e8488SAndroid Build Coastguard Worker{{ end }} 752*5a6e8488SAndroid Build Coastguard Worker 753*5a6e8488SAndroid Build Coastguard Worker## Operators 754*5a6e8488SAndroid Build Coastguard Worker 755*5a6e8488SAndroid Build Coastguard WorkerThe following arithmetic and logical operators can be used. They are listed in 756*5a6e8488SAndroid Build Coastguard Workerorder of decreasing precedence. Operators in the same group have the same 757*5a6e8488SAndroid Build Coastguard Workerprecedence. 758*5a6e8488SAndroid Build Coastguard Worker 759*5a6e8488SAndroid Build Coastguard Worker**++** **-\-** 760*5a6e8488SAndroid Build Coastguard Worker 761*5a6e8488SAndroid Build Coastguard Worker: Type: Prefix and Postfix 762*5a6e8488SAndroid Build Coastguard Worker 763*5a6e8488SAndroid Build Coastguard Worker Associativity: None 764*5a6e8488SAndroid Build Coastguard Worker 765*5a6e8488SAndroid Build Coastguard Worker Description: **increment**, **decrement** 766*5a6e8488SAndroid Build Coastguard Worker 767*5a6e8488SAndroid Build Coastguard Worker**-** **!** 768*5a6e8488SAndroid Build Coastguard Worker 769*5a6e8488SAndroid Build Coastguard Worker: Type: Prefix 770*5a6e8488SAndroid Build Coastguard Worker 771*5a6e8488SAndroid Build Coastguard Worker Associativity: None 772*5a6e8488SAndroid Build Coastguard Worker 773*5a6e8488SAndroid Build Coastguard Worker Description: **negation**, **boolean not** 774*5a6e8488SAndroid Build Coastguard Worker 775*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 776*5a6e8488SAndroid Build Coastguard Worker**\$** 777*5a6e8488SAndroid Build Coastguard Worker 778*5a6e8488SAndroid Build Coastguard Worker: Type: Postfix 779*5a6e8488SAndroid Build Coastguard Worker 780*5a6e8488SAndroid Build Coastguard Worker Associativity: None 781*5a6e8488SAndroid Build Coastguard Worker 782*5a6e8488SAndroid Build Coastguard Worker Description: **truncation** 783*5a6e8488SAndroid Build Coastguard Worker 784*5a6e8488SAndroid Build Coastguard Worker**\@** 785*5a6e8488SAndroid Build Coastguard Worker 786*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 787*5a6e8488SAndroid Build Coastguard Worker 788*5a6e8488SAndroid Build Coastguard Worker Associativity: Right 789*5a6e8488SAndroid Build Coastguard Worker 790*5a6e8488SAndroid Build Coastguard Worker Description: **set precision** 791*5a6e8488SAndroid Build Coastguard Worker{{ end }} 792*5a6e8488SAndroid Build Coastguard Worker 793*5a6e8488SAndroid Build Coastguard Worker**\^** 794*5a6e8488SAndroid Build Coastguard Worker 795*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 796*5a6e8488SAndroid Build Coastguard Worker 797*5a6e8488SAndroid Build Coastguard Worker Associativity: Right 798*5a6e8488SAndroid Build Coastguard Worker 799*5a6e8488SAndroid Build Coastguard Worker Description: **power** 800*5a6e8488SAndroid Build Coastguard Worker 801*5a6e8488SAndroid Build Coastguard Worker**\*** **/** **%** 802*5a6e8488SAndroid Build Coastguard Worker 803*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 804*5a6e8488SAndroid Build Coastguard Worker 805*5a6e8488SAndroid Build Coastguard Worker Associativity: Left 806*5a6e8488SAndroid Build Coastguard Worker 807*5a6e8488SAndroid Build Coastguard Worker Description: **multiply**, **divide**, **modulus** 808*5a6e8488SAndroid Build Coastguard Worker 809*5a6e8488SAndroid Build Coastguard Worker**+** **-** 810*5a6e8488SAndroid Build Coastguard Worker 811*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 812*5a6e8488SAndroid Build Coastguard Worker 813*5a6e8488SAndroid Build Coastguard Worker Associativity: Left 814*5a6e8488SAndroid Build Coastguard Worker 815*5a6e8488SAndroid Build Coastguard Worker Description: **add**, **subtract** 816*5a6e8488SAndroid Build Coastguard Worker 817*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 818*5a6e8488SAndroid Build Coastguard Worker**\<\<** **\>\>** 819*5a6e8488SAndroid Build Coastguard Worker 820*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 821*5a6e8488SAndroid Build Coastguard Worker 822*5a6e8488SAndroid Build Coastguard Worker Associativity: Left 823*5a6e8488SAndroid Build Coastguard Worker 824*5a6e8488SAndroid Build Coastguard Worker Description: **shift left**, **shift right** 825*5a6e8488SAndroid Build Coastguard Worker 826*5a6e8488SAndroid Build Coastguard Worker**=** **\<\<=** **\>\>=** **+=** **-=** **\*=** **/=** **%=** **\^=** **\@=** 827*5a6e8488SAndroid Build Coastguard Worker{{ end }} 828*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 829*5a6e8488SAndroid Build Coastguard Worker**=** **+=** **-=** **\*=** **/=** **%=** **\^=** 830*5a6e8488SAndroid Build Coastguard Worker{{ end }} 831*5a6e8488SAndroid Build Coastguard Worker 832*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 833*5a6e8488SAndroid Build Coastguard Worker 834*5a6e8488SAndroid Build Coastguard Worker Associativity: Right 835*5a6e8488SAndroid Build Coastguard Worker 836*5a6e8488SAndroid Build Coastguard Worker Description: **assignment** 837*5a6e8488SAndroid Build Coastguard Worker 838*5a6e8488SAndroid Build Coastguard Worker**==** **\<=** **\>=** **!=** **\<** **\>** 839*5a6e8488SAndroid Build Coastguard Worker 840*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 841*5a6e8488SAndroid Build Coastguard Worker 842*5a6e8488SAndroid Build Coastguard Worker Associativity: Left 843*5a6e8488SAndroid Build Coastguard Worker 844*5a6e8488SAndroid Build Coastguard Worker Description: **relational** 845*5a6e8488SAndroid Build Coastguard Worker 846*5a6e8488SAndroid Build Coastguard Worker**&&** 847*5a6e8488SAndroid Build Coastguard Worker 848*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 849*5a6e8488SAndroid Build Coastguard Worker 850*5a6e8488SAndroid Build Coastguard Worker Associativity: Left 851*5a6e8488SAndroid Build Coastguard Worker 852*5a6e8488SAndroid Build Coastguard Worker Description: **boolean and** 853*5a6e8488SAndroid Build Coastguard Worker 854*5a6e8488SAndroid Build Coastguard Worker**||** 855*5a6e8488SAndroid Build Coastguard Worker 856*5a6e8488SAndroid Build Coastguard Worker: Type: Binary 857*5a6e8488SAndroid Build Coastguard Worker 858*5a6e8488SAndroid Build Coastguard Worker Associativity: Left 859*5a6e8488SAndroid Build Coastguard Worker 860*5a6e8488SAndroid Build Coastguard Worker Description: **boolean or** 861*5a6e8488SAndroid Build Coastguard Worker 862*5a6e8488SAndroid Build Coastguard WorkerThe operators will be described in more detail below. 863*5a6e8488SAndroid Build Coastguard Worker 864*5a6e8488SAndroid Build Coastguard Worker**++** **-\-** 865*5a6e8488SAndroid Build Coastguard Worker 866*5a6e8488SAndroid Build Coastguard Worker: The prefix and postfix **increment** and **decrement** operators behave 867*5a6e8488SAndroid Build Coastguard Worker exactly like they would in C. They require a named expression (see the 868*5a6e8488SAndroid Build Coastguard Worker *Named Expressions* subsection) as an operand. 869*5a6e8488SAndroid Build Coastguard Worker 870*5a6e8488SAndroid Build Coastguard Worker The prefix versions of these operators are more efficient; use them where 871*5a6e8488SAndroid Build Coastguard Worker possible. 872*5a6e8488SAndroid Build Coastguard Worker 873*5a6e8488SAndroid Build Coastguard Worker**-** 874*5a6e8488SAndroid Build Coastguard Worker 875*5a6e8488SAndroid Build Coastguard Worker: The **negation** operator returns **0** if a user attempts to negate any 876*5a6e8488SAndroid Build Coastguard Worker expression with the value **0**. Otherwise, a copy of the expression with 877*5a6e8488SAndroid Build Coastguard Worker its sign flipped is returned. 878*5a6e8488SAndroid Build Coastguard Worker 879*5a6e8488SAndroid Build Coastguard Worker**!** 880*5a6e8488SAndroid Build Coastguard Worker 881*5a6e8488SAndroid Build Coastguard Worker: The **boolean not** operator returns **1** if the expression is **0**, or 882*5a6e8488SAndroid Build Coastguard Worker **0** otherwise. 883*5a6e8488SAndroid Build Coastguard Worker 884*5a6e8488SAndroid Build Coastguard Worker **Warning**: This operator has a **different precedence** than the 885*5a6e8488SAndroid Build Coastguard Worker equivalent operator in GNU bc(1) and other bc(1) implementations! 886*5a6e8488SAndroid Build Coastguard Worker 887*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 888*5a6e8488SAndroid Build Coastguard Worker 889*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 890*5a6e8488SAndroid Build Coastguard Worker**\$** 891*5a6e8488SAndroid Build Coastguard Worker 892*5a6e8488SAndroid Build Coastguard Worker: The **truncation** operator returns a copy of the given expression with all 893*5a6e8488SAndroid Build Coastguard Worker of its *scale* removed. 894*5a6e8488SAndroid Build Coastguard Worker 895*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 896*5a6e8488SAndroid Build Coastguard Worker 897*5a6e8488SAndroid Build Coastguard Worker**\@** 898*5a6e8488SAndroid Build Coastguard Worker 899*5a6e8488SAndroid Build Coastguard Worker: The **set precision** operator takes two expressions and returns a copy of 900*5a6e8488SAndroid Build Coastguard Worker the first with its *scale* equal to the value of the second expression. That 901*5a6e8488SAndroid Build Coastguard Worker could either mean that the number is returned without change (if the 902*5a6e8488SAndroid Build Coastguard Worker *scale* of the first expression matches the value of the second 903*5a6e8488SAndroid Build Coastguard Worker expression), extended (if it is less), or truncated (if it is more). 904*5a6e8488SAndroid Build Coastguard Worker 905*5a6e8488SAndroid Build Coastguard Worker The second expression must be an integer (no *scale*) and non-negative. 906*5a6e8488SAndroid Build Coastguard Worker 907*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 908*5a6e8488SAndroid Build Coastguard Worker{{ end }} 909*5a6e8488SAndroid Build Coastguard Worker 910*5a6e8488SAndroid Build Coastguard Worker**\^** 911*5a6e8488SAndroid Build Coastguard Worker 912*5a6e8488SAndroid Build Coastguard Worker: The **power** operator (not the **exclusive or** operator, as it would be in 913*5a6e8488SAndroid Build Coastguard Worker C) takes two expressions and raises the first to the power of the value of 914*5a6e8488SAndroid Build Coastguard Worker the second. The *scale* of the result is equal to **scale**. 915*5a6e8488SAndroid Build Coastguard Worker 916*5a6e8488SAndroid Build Coastguard Worker The second expression must be an integer (no *scale*), and if it is 917*5a6e8488SAndroid Build Coastguard Worker negative, the first value must be non-zero. 918*5a6e8488SAndroid Build Coastguard Worker 919*5a6e8488SAndroid Build Coastguard Worker**\*** 920*5a6e8488SAndroid Build Coastguard Worker 921*5a6e8488SAndroid Build Coastguard Worker: The **multiply** operator takes two expressions, multiplies them, and 922*5a6e8488SAndroid Build Coastguard Worker returns the product. If **a** is the *scale* of the first expression and 923*5a6e8488SAndroid Build Coastguard Worker **b** is the *scale* of the second expression, the *scale* of the result is 924*5a6e8488SAndroid Build Coastguard Worker equal to **min(a+b,max(scale,a,b))** where **min()** and **max()** return 925*5a6e8488SAndroid Build Coastguard Worker the obvious values. 926*5a6e8488SAndroid Build Coastguard Worker 927*5a6e8488SAndroid Build Coastguard Worker**/** 928*5a6e8488SAndroid Build Coastguard Worker 929*5a6e8488SAndroid Build Coastguard Worker: The **divide** operator takes two expressions, divides them, and returns the 930*5a6e8488SAndroid Build Coastguard Worker quotient. The *scale* of the result shall be the value of **scale**. 931*5a6e8488SAndroid Build Coastguard Worker 932*5a6e8488SAndroid Build Coastguard Worker The second expression must be non-zero. 933*5a6e8488SAndroid Build Coastguard Worker 934*5a6e8488SAndroid Build Coastguard Worker**%** 935*5a6e8488SAndroid Build Coastguard Worker 936*5a6e8488SAndroid Build Coastguard Worker: The **modulus** operator takes two expressions, **a** and **b**, and 937*5a6e8488SAndroid Build Coastguard Worker evaluates them by 1) Computing **a/b** to current **scale** and 2) Using the 938*5a6e8488SAndroid Build Coastguard Worker result of step 1 to calculate **a-(a/b)\*b** to *scale* 939*5a6e8488SAndroid Build Coastguard Worker **max(scale+scale(b),scale(a))**. 940*5a6e8488SAndroid Build Coastguard Worker 941*5a6e8488SAndroid Build Coastguard Worker The second expression must be non-zero. 942*5a6e8488SAndroid Build Coastguard Worker 943*5a6e8488SAndroid Build Coastguard Worker**+** 944*5a6e8488SAndroid Build Coastguard Worker 945*5a6e8488SAndroid Build Coastguard Worker: The **add** operator takes two expressions, **a** and **b**, and returns the 946*5a6e8488SAndroid Build Coastguard Worker sum, with a *scale* equal to the max of the *scale*s of **a** and **b**. 947*5a6e8488SAndroid Build Coastguard Worker 948*5a6e8488SAndroid Build Coastguard Worker**-** 949*5a6e8488SAndroid Build Coastguard Worker 950*5a6e8488SAndroid Build Coastguard Worker: The **subtract** operator takes two expressions, **a** and **b**, and 951*5a6e8488SAndroid Build Coastguard Worker returns the difference, with a *scale* equal to the max of the *scale*s of 952*5a6e8488SAndroid Build Coastguard Worker **a** and **b**. 953*5a6e8488SAndroid Build Coastguard Worker 954*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 955*5a6e8488SAndroid Build Coastguard Worker**\<\<** 956*5a6e8488SAndroid Build Coastguard Worker 957*5a6e8488SAndroid Build Coastguard Worker: The **left shift** operator takes two expressions, **a** and **b**, and 958*5a6e8488SAndroid Build Coastguard Worker returns a copy of the value of **a** with its decimal point moved **b** 959*5a6e8488SAndroid Build Coastguard Worker places to the right. 960*5a6e8488SAndroid Build Coastguard Worker 961*5a6e8488SAndroid Build Coastguard Worker The second expression must be an integer (no *scale*) and non-negative. 962*5a6e8488SAndroid Build Coastguard Worker 963*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 964*5a6e8488SAndroid Build Coastguard Worker 965*5a6e8488SAndroid Build Coastguard Worker**\>\>** 966*5a6e8488SAndroid Build Coastguard Worker 967*5a6e8488SAndroid Build Coastguard Worker: The **right shift** operator takes two expressions, **a** and **b**, and 968*5a6e8488SAndroid Build Coastguard Worker returns a copy of the value of **a** with its decimal point moved **b** 969*5a6e8488SAndroid Build Coastguard Worker places to the left. 970*5a6e8488SAndroid Build Coastguard Worker 971*5a6e8488SAndroid Build Coastguard Worker The second expression must be an integer (no *scale*) and non-negative. 972*5a6e8488SAndroid Build Coastguard Worker 973*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 974*5a6e8488SAndroid Build Coastguard Worker{{ end }} 975*5a6e8488SAndroid Build Coastguard Worker 976*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 977*5a6e8488SAndroid Build Coastguard Worker**=** **\<\<=** **\>\>=** **+=** **-=** **\*=** **/=** **%=** **\^=** **\@=** 978*5a6e8488SAndroid Build Coastguard Worker{{ end }} 979*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 980*5a6e8488SAndroid Build Coastguard Worker**=** **+=** **-=** **\*=** **/=** **%=** **\^=** 981*5a6e8488SAndroid Build Coastguard Worker{{ end }} 982*5a6e8488SAndroid Build Coastguard Worker 983*5a6e8488SAndroid Build Coastguard Worker: The **assignment** operators take two expressions, **a** and **b** where 984*5a6e8488SAndroid Build Coastguard Worker **a** is a named expression (see the *Named Expressions* subsection). 985*5a6e8488SAndroid Build Coastguard Worker 986*5a6e8488SAndroid Build Coastguard Worker For **=**, **b** is copied and the result is assigned to **a**. For all 987*5a6e8488SAndroid Build Coastguard Worker others, **a** and **b** are applied as operands to the corresponding 988*5a6e8488SAndroid Build Coastguard Worker arithmetic operator and the result is assigned to **a**. 989*5a6e8488SAndroid Build Coastguard Worker 990*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 991*5a6e8488SAndroid Build Coastguard Worker The **assignment** operators that correspond to operators that are 992*5a6e8488SAndroid Build Coastguard Worker extensions are themselves **non-portable extensions**. 993*5a6e8488SAndroid Build Coastguard Worker{{ end }} 994*5a6e8488SAndroid Build Coastguard Worker 995*5a6e8488SAndroid Build Coastguard Worker**==** **\<=** **\>=** **!=** **\<** **\>** 996*5a6e8488SAndroid Build Coastguard Worker 997*5a6e8488SAndroid Build Coastguard Worker: The **relational** operators compare two expressions, **a** and **b**, and 998*5a6e8488SAndroid Build Coastguard Worker if the relation holds, according to C language semantics, the result is 999*5a6e8488SAndroid Build Coastguard Worker **1**. Otherwise, it is **0**. 1000*5a6e8488SAndroid Build Coastguard Worker 1001*5a6e8488SAndroid Build Coastguard Worker Note that unlike in C, these operators have a lower precedence than the 1002*5a6e8488SAndroid Build Coastguard Worker **assignment** operators, which means that **a=b\>c** is interpreted as 1003*5a6e8488SAndroid Build Coastguard Worker **(a=b)\>c**. 1004*5a6e8488SAndroid Build Coastguard Worker 1005*5a6e8488SAndroid Build Coastguard Worker Also, unlike the standard (see the **STANDARDS** section) requires, these 1006*5a6e8488SAndroid Build Coastguard Worker operators can appear anywhere any other expressions can be used. This 1007*5a6e8488SAndroid Build Coastguard Worker allowance is a **non-portable extension**. 1008*5a6e8488SAndroid Build Coastguard Worker 1009*5a6e8488SAndroid Build Coastguard Worker**&&** 1010*5a6e8488SAndroid Build Coastguard Worker 1011*5a6e8488SAndroid Build Coastguard Worker: The **boolean and** operator takes two expressions and returns **1** if both 1012*5a6e8488SAndroid Build Coastguard Worker expressions are non-zero, **0** otherwise. 1013*5a6e8488SAndroid Build Coastguard Worker 1014*5a6e8488SAndroid Build Coastguard Worker This is *not* a short-circuit operator. 1015*5a6e8488SAndroid Build Coastguard Worker 1016*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 1017*5a6e8488SAndroid Build Coastguard Worker 1018*5a6e8488SAndroid Build Coastguard Worker**||** 1019*5a6e8488SAndroid Build Coastguard Worker 1020*5a6e8488SAndroid Build Coastguard Worker: The **boolean or** operator takes two expressions and returns **1** if one 1021*5a6e8488SAndroid Build Coastguard Worker of the expressions is non-zero, **0** otherwise. 1022*5a6e8488SAndroid Build Coastguard Worker 1023*5a6e8488SAndroid Build Coastguard Worker This is *not* a short-circuit operator. 1024*5a6e8488SAndroid Build Coastguard Worker 1025*5a6e8488SAndroid Build Coastguard Worker This is a **non-portable extension**. 1026*5a6e8488SAndroid Build Coastguard Worker 1027*5a6e8488SAndroid Build Coastguard Worker## Statements 1028*5a6e8488SAndroid Build Coastguard Worker 1029*5a6e8488SAndroid Build Coastguard WorkerThe following items are statements: 1030*5a6e8488SAndroid Build Coastguard Worker 1031*5a6e8488SAndroid Build Coastguard Worker1. **E** 1032*5a6e8488SAndroid Build Coastguard Worker2. **{** **S** **;** ... **;** **S** **}** 1033*5a6e8488SAndroid Build Coastguard Worker3. **if** **(** **E** **)** **S** 1034*5a6e8488SAndroid Build Coastguard Worker4. **if** **(** **E** **)** **S** **else** **S** 1035*5a6e8488SAndroid Build Coastguard Worker5. **while** **(** **E** **)** **S** 1036*5a6e8488SAndroid Build Coastguard Worker6. **for** **(** **E** **;** **E** **;** **E** **)** **S** 1037*5a6e8488SAndroid Build Coastguard Worker7. An empty statement 1038*5a6e8488SAndroid Build Coastguard Worker8. **break** 1039*5a6e8488SAndroid Build Coastguard Worker9. **continue** 1040*5a6e8488SAndroid Build Coastguard Worker10. **quit** 1041*5a6e8488SAndroid Build Coastguard Worker11. **halt** 1042*5a6e8488SAndroid Build Coastguard Worker12. **limits** 1043*5a6e8488SAndroid Build Coastguard Worker13. A string of characters, enclosed in double quotes 1044*5a6e8488SAndroid Build Coastguard Worker14. **print** **E** **,** ... **,** **E** 1045*5a6e8488SAndroid Build Coastguard Worker15. **stream** **E** **,** ... **,** **E** 1046*5a6e8488SAndroid Build Coastguard Worker16. **I()**, **I(E)**, **I(E, E)**, and so on, where **I** is an identifier for 1047*5a6e8488SAndroid Build Coastguard Worker a **void** function (see the *Void Functions* subsection of the 1048*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). The **E** argument(s) may also be arrays of the form 1049*5a6e8488SAndroid Build Coastguard Worker **I[]**, which will automatically be turned into array references (see the 1050*5a6e8488SAndroid Build Coastguard Worker *Array References* subsection of the **FUNCTIONS** section) if the 1051*5a6e8488SAndroid Build Coastguard Worker corresponding parameter in the function definition is an array reference. 1052*5a6e8488SAndroid Build Coastguard Worker 1053*5a6e8488SAndroid Build Coastguard WorkerNumbers 4, 9, 11, 12, 14, 15, and 16 are **non-portable extensions**. 1054*5a6e8488SAndroid Build Coastguard Worker 1055*5a6e8488SAndroid Build Coastguard WorkerAlso, as a **non-portable extension**, any or all of the expressions in the 1056*5a6e8488SAndroid Build Coastguard Workerheader of a for loop may be omitted. If the condition (second expression) is 1057*5a6e8488SAndroid Build Coastguard Workeromitted, it is assumed to be a constant **1**. 1058*5a6e8488SAndroid Build Coastguard Worker 1059*5a6e8488SAndroid Build Coastguard WorkerThe **break** statement causes a loop to stop iterating and resume execution 1060*5a6e8488SAndroid Build Coastguard Workerimmediately following a loop. This is only allowed in loops. 1061*5a6e8488SAndroid Build Coastguard Worker 1062*5a6e8488SAndroid Build Coastguard WorkerThe **continue** statement causes a loop iteration to stop early and returns to 1063*5a6e8488SAndroid Build Coastguard Workerthe start of the loop, including testing the loop condition. This is only 1064*5a6e8488SAndroid Build Coastguard Workerallowed in loops. 1065*5a6e8488SAndroid Build Coastguard Worker 1066*5a6e8488SAndroid Build Coastguard WorkerThe **if** **else** statement does the same thing as in C. 1067*5a6e8488SAndroid Build Coastguard Worker 1068*5a6e8488SAndroid Build Coastguard WorkerThe **quit** statement causes bc(1) to quit, even if it is on a branch that will 1069*5a6e8488SAndroid Build Coastguard Workernot be executed (it is a compile-time command). 1070*5a6e8488SAndroid Build Coastguard Worker 1071*5a6e8488SAndroid Build Coastguard Worker**Warning**: The behavior of this bc(1) on **quit** is slightly different from 1072*5a6e8488SAndroid Build Coastguard Workerother bc(1) implementations. Other bc(1) implementations will exit as soon as 1073*5a6e8488SAndroid Build Coastguard Workerthey finish parsing the line that a **quit** command is on. This bc(1) will 1074*5a6e8488SAndroid Build Coastguard Workerexecute any completed and executable statements that occur before the **quit** 1075*5a6e8488SAndroid Build Coastguard Workerstatement before exiting. 1076*5a6e8488SAndroid Build Coastguard Worker 1077*5a6e8488SAndroid Build Coastguard WorkerIn other words, for the bc(1) code below: 1078*5a6e8488SAndroid Build Coastguard Worker 1079*5a6e8488SAndroid Build Coastguard Worker for (i = 0; i < 3; ++i) i; quit 1080*5a6e8488SAndroid Build Coastguard Worker 1081*5a6e8488SAndroid Build Coastguard WorkerOther bc(1) implementations will print nothing, and this bc(1) will print **0**, 1082*5a6e8488SAndroid Build Coastguard Worker**1**, and **2** on successive lines before exiting. 1083*5a6e8488SAndroid Build Coastguard Worker 1084*5a6e8488SAndroid Build Coastguard WorkerThe **halt** statement causes bc(1) to quit, if it is executed. (Unlike **quit** 1085*5a6e8488SAndroid Build Coastguard Workerif it is on a branch of an **if** statement that is not executed, bc(1) does not 1086*5a6e8488SAndroid Build Coastguard Workerquit.) 1087*5a6e8488SAndroid Build Coastguard Worker 1088*5a6e8488SAndroid Build Coastguard WorkerThe **limits** statement prints the limits that this bc(1) is subject to. This 1089*5a6e8488SAndroid Build Coastguard Workeris like the **quit** statement in that it is a compile-time command. 1090*5a6e8488SAndroid Build Coastguard Worker 1091*5a6e8488SAndroid Build Coastguard WorkerAn expression by itself is evaluated and printed, followed by a newline. 1092*5a6e8488SAndroid Build Coastguard Worker 1093*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 1094*5a6e8488SAndroid Build Coastguard WorkerBoth scientific notation and engineering notation are available for printing the 1095*5a6e8488SAndroid Build Coastguard Workerresults of expressions. Scientific notation is activated by assigning **0** to 1096*5a6e8488SAndroid Build Coastguard Worker**obase**, and engineering notation is activated by assigning **1** to 1097*5a6e8488SAndroid Build Coastguard Worker**obase**. To deactivate them, just assign a different value to **obase**. 1098*5a6e8488SAndroid Build Coastguard Worker 1099*5a6e8488SAndroid Build Coastguard WorkerScientific notation and engineering notation are disabled if bc(1) is run with 1100*5a6e8488SAndroid Build Coastguard Workereither the **-s** or **-w** command-line options (or equivalents). 1101*5a6e8488SAndroid Build Coastguard Worker 1102*5a6e8488SAndroid Build Coastguard WorkerPrinting numbers in scientific notation and/or engineering notation is a 1103*5a6e8488SAndroid Build Coastguard Worker**non-portable extension**. 1104*5a6e8488SAndroid Build Coastguard Worker{{ end }} 1105*5a6e8488SAndroid Build Coastguard Worker 1106*5a6e8488SAndroid Build Coastguard Worker## Strings 1107*5a6e8488SAndroid Build Coastguard Worker 1108*5a6e8488SAndroid Build Coastguard WorkerIf strings appear as a statement by themselves, they are printed without a 1109*5a6e8488SAndroid Build Coastguard Workertrailing newline. 1110*5a6e8488SAndroid Build Coastguard Worker 1111*5a6e8488SAndroid Build Coastguard WorkerIn addition to appearing as a lone statement by themselves, strings can be 1112*5a6e8488SAndroid Build Coastguard Workerassigned to variables and array elements. They can also be passed to functions 1113*5a6e8488SAndroid Build Coastguard Workerin variable parameters. 1114*5a6e8488SAndroid Build Coastguard Worker 1115*5a6e8488SAndroid Build Coastguard WorkerIf any statement that expects a string is given a variable that had a string 1116*5a6e8488SAndroid Build Coastguard Workerassigned to it, the statement acts as though it had received a string. 1117*5a6e8488SAndroid Build Coastguard Worker 1118*5a6e8488SAndroid Build Coastguard WorkerIf any math operation is attempted on a string or a variable or array element 1119*5a6e8488SAndroid Build Coastguard Workerthat has been assigned a string, an error is raised, and bc(1) resets (see the 1120*5a6e8488SAndroid Build Coastguard Worker**RESET** section). 1121*5a6e8488SAndroid Build Coastguard Worker 1122*5a6e8488SAndroid Build Coastguard WorkerAssigning strings to variables and array elements and passing them to functions 1123*5a6e8488SAndroid Build Coastguard Workerare **non-portable extensions**. 1124*5a6e8488SAndroid Build Coastguard Worker 1125*5a6e8488SAndroid Build Coastguard Worker## Print Statement 1126*5a6e8488SAndroid Build Coastguard Worker 1127*5a6e8488SAndroid Build Coastguard WorkerThe "expressions" in a **print** statement may also be strings. If they are, there 1128*5a6e8488SAndroid Build Coastguard Workerare backslash escape sequences that are interpreted specially. What those 1129*5a6e8488SAndroid Build Coastguard Workersequences are, and what they cause to be printed, are shown below: 1130*5a6e8488SAndroid Build Coastguard Worker 1131*5a6e8488SAndroid Build Coastguard Worker**\\a**: **\\a** 1132*5a6e8488SAndroid Build Coastguard Worker 1133*5a6e8488SAndroid Build Coastguard Worker**\\b**: **\\b** 1134*5a6e8488SAndroid Build Coastguard Worker 1135*5a6e8488SAndroid Build Coastguard Worker**\\\\**: **\\** 1136*5a6e8488SAndroid Build Coastguard Worker 1137*5a6e8488SAndroid Build Coastguard Worker**\\e**: **\\** 1138*5a6e8488SAndroid Build Coastguard Worker 1139*5a6e8488SAndroid Build Coastguard Worker**\\f**: **\\f** 1140*5a6e8488SAndroid Build Coastguard Worker 1141*5a6e8488SAndroid Build Coastguard Worker**\\n**: **\\n** 1142*5a6e8488SAndroid Build Coastguard Worker 1143*5a6e8488SAndroid Build Coastguard Worker**\\q**: **"** 1144*5a6e8488SAndroid Build Coastguard Worker 1145*5a6e8488SAndroid Build Coastguard Worker**\\r**: **\\r** 1146*5a6e8488SAndroid Build Coastguard Worker 1147*5a6e8488SAndroid Build Coastguard Worker**\\t**: **\\t** 1148*5a6e8488SAndroid Build Coastguard Worker 1149*5a6e8488SAndroid Build Coastguard WorkerAny other character following a backslash causes the backslash and character to 1150*5a6e8488SAndroid Build Coastguard Workerbe printed as-is. 1151*5a6e8488SAndroid Build Coastguard Worker 1152*5a6e8488SAndroid Build Coastguard WorkerAny non-string expression in a print statement shall be assigned to **last**, 1153*5a6e8488SAndroid Build Coastguard Workerlike any other expression that is printed. 1154*5a6e8488SAndroid Build Coastguard Worker 1155*5a6e8488SAndroid Build Coastguard Worker## Stream Statement 1156*5a6e8488SAndroid Build Coastguard Worker 1157*5a6e8488SAndroid Build Coastguard WorkerThe expressions in a **stream** statement may also be strings. 1158*5a6e8488SAndroid Build Coastguard Worker 1159*5a6e8488SAndroid Build Coastguard WorkerIf a **stream** statement is given a string, it prints the string as though the 1160*5a6e8488SAndroid Build Coastguard Workerstring had appeared as its own statement. In other words, the **stream** 1161*5a6e8488SAndroid Build Coastguard Workerstatement prints strings normally, without a newline. 1162*5a6e8488SAndroid Build Coastguard Worker 1163*5a6e8488SAndroid Build Coastguard WorkerIf a **stream** statement is given a number, a copy of it is truncated and its 1164*5a6e8488SAndroid Build Coastguard Workerabsolute value is calculated. The result is then printed as though **obase** is 1165*5a6e8488SAndroid Build Coastguard Worker**256** and each digit is interpreted as an 8-bit ASCII character, making it a 1166*5a6e8488SAndroid Build Coastguard Workerbyte stream. 1167*5a6e8488SAndroid Build Coastguard Worker 1168*5a6e8488SAndroid Build Coastguard Worker## Order of Evaluation 1169*5a6e8488SAndroid Build Coastguard Worker 1170*5a6e8488SAndroid Build Coastguard WorkerAll expressions in a statment are evaluated left to right, except as necessary 1171*5a6e8488SAndroid Build Coastguard Workerto maintain order of operations. This means, for example, assuming that **i** is 1172*5a6e8488SAndroid Build Coastguard Workerequal to **0**, in the expression 1173*5a6e8488SAndroid Build Coastguard Worker 1174*5a6e8488SAndroid Build Coastguard Worker a[i++] = i++ 1175*5a6e8488SAndroid Build Coastguard Worker 1176*5a6e8488SAndroid Build Coastguard Workerthe first (or 0th) element of **a** is set to **1**, and **i** is equal to **2** 1177*5a6e8488SAndroid Build Coastguard Workerat the end of the expression. 1178*5a6e8488SAndroid Build Coastguard Worker 1179*5a6e8488SAndroid Build Coastguard WorkerThis includes function arguments. Thus, assuming **i** is equal to **0**, this 1180*5a6e8488SAndroid Build Coastguard Workermeans that in the expression 1181*5a6e8488SAndroid Build Coastguard Worker 1182*5a6e8488SAndroid Build Coastguard Worker x(i++, i++) 1183*5a6e8488SAndroid Build Coastguard Worker 1184*5a6e8488SAndroid Build Coastguard Workerthe first argument passed to **x()** is **0**, and the second argument is **1**, 1185*5a6e8488SAndroid Build Coastguard Workerwhile **i** is equal to **2** before the function starts executing. 1186*5a6e8488SAndroid Build Coastguard Worker 1187*5a6e8488SAndroid Build Coastguard Worker# FUNCTIONS 1188*5a6e8488SAndroid Build Coastguard Worker 1189*5a6e8488SAndroid Build Coastguard WorkerFunction definitions are as follows: 1190*5a6e8488SAndroid Build Coastguard Worker 1191*5a6e8488SAndroid Build Coastguard Worker``` 1192*5a6e8488SAndroid Build Coastguard Workerdefine I(I,...,I){ 1193*5a6e8488SAndroid Build Coastguard Worker auto I,...,I 1194*5a6e8488SAndroid Build Coastguard Worker S;...;S 1195*5a6e8488SAndroid Build Coastguard Worker return(E) 1196*5a6e8488SAndroid Build Coastguard Worker} 1197*5a6e8488SAndroid Build Coastguard Worker``` 1198*5a6e8488SAndroid Build Coastguard Worker 1199*5a6e8488SAndroid Build Coastguard WorkerAny **I** in the parameter list or **auto** list may be replaced with **I[]** to 1200*5a6e8488SAndroid Build Coastguard Workermake a parameter or **auto** var an array, and any **I** in the parameter list 1201*5a6e8488SAndroid Build Coastguard Workermay be replaced with **\*I[]** to make a parameter an array reference. Callers 1202*5a6e8488SAndroid Build Coastguard Workerof functions that take array references should not put an asterisk in the call; 1203*5a6e8488SAndroid Build Coastguard Workerthey must be called with just **I[]** like normal array parameters and will be 1204*5a6e8488SAndroid Build Coastguard Workerautomatically converted into references. 1205*5a6e8488SAndroid Build Coastguard Worker 1206*5a6e8488SAndroid Build Coastguard WorkerAs a **non-portable extension**, the opening brace of a **define** statement may 1207*5a6e8488SAndroid Build Coastguard Workerappear on the next line. 1208*5a6e8488SAndroid Build Coastguard Worker 1209*5a6e8488SAndroid Build Coastguard WorkerAs a **non-portable extension**, the return statement may also be in one of the 1210*5a6e8488SAndroid Build Coastguard Workerfollowing forms: 1211*5a6e8488SAndroid Build Coastguard Worker 1212*5a6e8488SAndroid Build Coastguard Worker1. **return** 1213*5a6e8488SAndroid Build Coastguard Worker2. **return** **(** **)** 1214*5a6e8488SAndroid Build Coastguard Worker3. **return** **E** 1215*5a6e8488SAndroid Build Coastguard Worker 1216*5a6e8488SAndroid Build Coastguard WorkerThe first two, or not specifying a **return** statement, is equivalent to 1217*5a6e8488SAndroid Build Coastguard Worker**return (0)**, unless the function is a **void** function (see the *Void 1218*5a6e8488SAndroid Build Coastguard WorkerFunctions* subsection below). 1219*5a6e8488SAndroid Build Coastguard Worker 1220*5a6e8488SAndroid Build Coastguard Worker## Void Functions 1221*5a6e8488SAndroid Build Coastguard Worker 1222*5a6e8488SAndroid Build Coastguard WorkerFunctions can also be **void** functions, defined as follows: 1223*5a6e8488SAndroid Build Coastguard Worker 1224*5a6e8488SAndroid Build Coastguard Worker``` 1225*5a6e8488SAndroid Build Coastguard Workerdefine void I(I,...,I){ 1226*5a6e8488SAndroid Build Coastguard Worker auto I,...,I 1227*5a6e8488SAndroid Build Coastguard Worker S;...;S 1228*5a6e8488SAndroid Build Coastguard Worker return 1229*5a6e8488SAndroid Build Coastguard Worker} 1230*5a6e8488SAndroid Build Coastguard Worker``` 1231*5a6e8488SAndroid Build Coastguard Worker 1232*5a6e8488SAndroid Build Coastguard WorkerThey can only be used as standalone expressions, where such an expression would 1233*5a6e8488SAndroid Build Coastguard Workerbe printed alone, except in a print statement. 1234*5a6e8488SAndroid Build Coastguard Worker 1235*5a6e8488SAndroid Build Coastguard WorkerVoid functions can only use the first two **return** statements listed above. 1236*5a6e8488SAndroid Build Coastguard WorkerThey can also omit the return statement entirely. 1237*5a6e8488SAndroid Build Coastguard Worker 1238*5a6e8488SAndroid Build Coastguard WorkerThe word "void" is not treated as a keyword; it is still possible to have 1239*5a6e8488SAndroid Build Coastguard Workervariables, arrays, and functions named **void**. The word "void" is only 1240*5a6e8488SAndroid Build Coastguard Workertreated specially right after the **define** keyword. 1241*5a6e8488SAndroid Build Coastguard Worker 1242*5a6e8488SAndroid Build Coastguard WorkerThis is a **non-portable extension**. 1243*5a6e8488SAndroid Build Coastguard Worker 1244*5a6e8488SAndroid Build Coastguard Worker## Array References 1245*5a6e8488SAndroid Build Coastguard Worker 1246*5a6e8488SAndroid Build Coastguard WorkerFor any array in the parameter list, if the array is declared in the form 1247*5a6e8488SAndroid Build Coastguard Worker 1248*5a6e8488SAndroid Build Coastguard Worker``` 1249*5a6e8488SAndroid Build Coastguard Worker*I[] 1250*5a6e8488SAndroid Build Coastguard Worker``` 1251*5a6e8488SAndroid Build Coastguard Worker 1252*5a6e8488SAndroid Build Coastguard Workerit is a **reference**. Any changes to the array in the function are reflected, 1253*5a6e8488SAndroid Build Coastguard Workerwhen the function returns, to the array that was passed in. 1254*5a6e8488SAndroid Build Coastguard Worker 1255*5a6e8488SAndroid Build Coastguard WorkerOther than this, all function arguments are passed by value. 1256*5a6e8488SAndroid Build Coastguard Worker 1257*5a6e8488SAndroid Build Coastguard WorkerThis is a **non-portable extension**. 1258*5a6e8488SAndroid Build Coastguard Worker 1259*5a6e8488SAndroid Build Coastguard Worker# LIBRARY 1260*5a6e8488SAndroid Build Coastguard Worker 1261*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 1262*5a6e8488SAndroid Build Coastguard WorkerAll of the functions below, including the functions in the extended math 1263*5a6e8488SAndroid Build Coastguard Workerlibrary (see the *Extended Library* subsection below), are available when the 1264*5a6e8488SAndroid Build Coastguard Worker**-l** or **-\-mathlib** command-line flags are given, except that the extended 1265*5a6e8488SAndroid Build Coastguard Workermath library is not available when the **-s** option, the **-w** option, or 1266*5a6e8488SAndroid Build Coastguard Workerequivalents are given. 1267*5a6e8488SAndroid Build Coastguard Worker{{ end }} 1268*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 1269*5a6e8488SAndroid Build Coastguard WorkerAll of the functions below are available when the **-l** or **-\-mathlib** 1270*5a6e8488SAndroid Build Coastguard Workercommand-line flags are given. 1271*5a6e8488SAndroid Build Coastguard Worker{{ end }} 1272*5a6e8488SAndroid Build Coastguard Worker 1273*5a6e8488SAndroid Build Coastguard Worker## Standard Library 1274*5a6e8488SAndroid Build Coastguard Worker 1275*5a6e8488SAndroid Build Coastguard WorkerThe standard (see the **STANDARDS** section) defines the following functions for 1276*5a6e8488SAndroid Build Coastguard Workerthe math library: 1277*5a6e8488SAndroid Build Coastguard Worker 1278*5a6e8488SAndroid Build Coastguard Worker**s(x)** 1279*5a6e8488SAndroid Build Coastguard Worker 1280*5a6e8488SAndroid Build Coastguard Worker: Returns the sine of **x**, which is assumed to be in radians. 1281*5a6e8488SAndroid Build Coastguard Worker 1282*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1283*5a6e8488SAndroid Build Coastguard Worker subsection below). 1284*5a6e8488SAndroid Build Coastguard Worker 1285*5a6e8488SAndroid Build Coastguard Worker**c(x)** 1286*5a6e8488SAndroid Build Coastguard Worker 1287*5a6e8488SAndroid Build Coastguard Worker: Returns the cosine of **x**, which is assumed to be in radians. 1288*5a6e8488SAndroid Build Coastguard Worker 1289*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1290*5a6e8488SAndroid Build Coastguard Worker subsection below). 1291*5a6e8488SAndroid Build Coastguard Worker 1292*5a6e8488SAndroid Build Coastguard Worker**a(x)** 1293*5a6e8488SAndroid Build Coastguard Worker 1294*5a6e8488SAndroid Build Coastguard Worker: Returns the arctangent of **x**, in radians. 1295*5a6e8488SAndroid Build Coastguard Worker 1296*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1297*5a6e8488SAndroid Build Coastguard Worker subsection below). 1298*5a6e8488SAndroid Build Coastguard Worker 1299*5a6e8488SAndroid Build Coastguard Worker**l(x)** 1300*5a6e8488SAndroid Build Coastguard Worker 1301*5a6e8488SAndroid Build Coastguard Worker: Returns the natural logarithm of **x**. 1302*5a6e8488SAndroid Build Coastguard Worker 1303*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1304*5a6e8488SAndroid Build Coastguard Worker subsection below). 1305*5a6e8488SAndroid Build Coastguard Worker 1306*5a6e8488SAndroid Build Coastguard Worker**e(x)** 1307*5a6e8488SAndroid Build Coastguard Worker 1308*5a6e8488SAndroid Build Coastguard Worker: Returns the mathematical constant **e** raised to the power of **x**. 1309*5a6e8488SAndroid Build Coastguard Worker 1310*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1311*5a6e8488SAndroid Build Coastguard Worker subsection below). 1312*5a6e8488SAndroid Build Coastguard Worker 1313*5a6e8488SAndroid Build Coastguard Worker**j(x, n)** 1314*5a6e8488SAndroid Build Coastguard Worker 1315*5a6e8488SAndroid Build Coastguard Worker: Returns the bessel integer order **n** (truncated) of **x**. 1316*5a6e8488SAndroid Build Coastguard Worker 1317*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1318*5a6e8488SAndroid Build Coastguard Worker subsection below). 1319*5a6e8488SAndroid Build Coastguard Worker 1320*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 1321*5a6e8488SAndroid Build Coastguard Worker## Extended Library 1322*5a6e8488SAndroid Build Coastguard Worker 1323*5a6e8488SAndroid Build Coastguard WorkerThe extended library is *not* loaded when the **-s**/**-\-standard** or 1324*5a6e8488SAndroid Build Coastguard Worker**-w**/**-\-warn** options are given since they are not part of the library 1325*5a6e8488SAndroid Build Coastguard Workerdefined by the standard (see the **STANDARDS** section). 1326*5a6e8488SAndroid Build Coastguard Worker 1327*5a6e8488SAndroid Build Coastguard WorkerThe extended library is a **non-portable extension**. 1328*5a6e8488SAndroid Build Coastguard Worker 1329*5a6e8488SAndroid Build Coastguard Worker**p(x, y)** 1330*5a6e8488SAndroid Build Coastguard Worker 1331*5a6e8488SAndroid Build Coastguard Worker: Calculates **x** to the power of **y**, even if **y** is not an integer, and 1332*5a6e8488SAndroid Build Coastguard Worker returns the result to the current **scale**. 1333*5a6e8488SAndroid Build Coastguard Worker 1334*5a6e8488SAndroid Build Coastguard Worker It is an error if **y** is negative and **x** is **0**. 1335*5a6e8488SAndroid Build Coastguard Worker 1336*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1337*5a6e8488SAndroid Build Coastguard Worker subsection below). 1338*5a6e8488SAndroid Build Coastguard Worker 1339*5a6e8488SAndroid Build Coastguard Worker**r(x, p)** 1340*5a6e8488SAndroid Build Coastguard Worker 1341*5a6e8488SAndroid Build Coastguard Worker: Returns **x** rounded to **p** decimal places according to the rounding mode 1342*5a6e8488SAndroid Build Coastguard Worker round half away from **0** 1343*5a6e8488SAndroid Build Coastguard Worker (https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero). 1344*5a6e8488SAndroid Build Coastguard Worker 1345*5a6e8488SAndroid Build Coastguard Worker**ceil(x, p)** 1346*5a6e8488SAndroid Build Coastguard Worker 1347*5a6e8488SAndroid Build Coastguard Worker: Returns **x** rounded to **p** decimal places according to the rounding mode 1348*5a6e8488SAndroid Build Coastguard Worker round away from **0** 1349*5a6e8488SAndroid Build Coastguard Worker (https://en.wikipedia.org/wiki/Rounding#Rounding_away_from_zero). 1350*5a6e8488SAndroid Build Coastguard Worker 1351*5a6e8488SAndroid Build Coastguard Worker**f(x)** 1352*5a6e8488SAndroid Build Coastguard Worker 1353*5a6e8488SAndroid Build Coastguard Worker: Returns the factorial of the truncated absolute value of **x**. 1354*5a6e8488SAndroid Build Coastguard Worker 1355*5a6e8488SAndroid Build Coastguard Worker**max(a, b)** 1356*5a6e8488SAndroid Build Coastguard Worker 1357*5a6e8488SAndroid Build Coastguard Worker: Returns **a** if **a** is greater than **b**; otherwise, returns **b**. 1358*5a6e8488SAndroid Build Coastguard Worker 1359*5a6e8488SAndroid Build Coastguard Worker**min(a, b)** 1360*5a6e8488SAndroid Build Coastguard Worker 1361*5a6e8488SAndroid Build Coastguard Worker: Returns **a** if **a** is less than **b**; otherwise, returns **b**. 1362*5a6e8488SAndroid Build Coastguard Worker 1363*5a6e8488SAndroid Build Coastguard Worker**perm(n, k)** 1364*5a6e8488SAndroid Build Coastguard Worker 1365*5a6e8488SAndroid Build Coastguard Worker: Returns the permutation of the truncated absolute value of **n** of the 1366*5a6e8488SAndroid Build Coastguard Worker truncated absolute value of **k**, if **k \<= n**. If not, it returns **0**. 1367*5a6e8488SAndroid Build Coastguard Worker 1368*5a6e8488SAndroid Build Coastguard Worker**comb(n, k)** 1369*5a6e8488SAndroid Build Coastguard Worker 1370*5a6e8488SAndroid Build Coastguard Worker: Returns the combination of the truncated absolute value of **n** of the 1371*5a6e8488SAndroid Build Coastguard Worker truncated absolute value of **k**, if **k \<= n**. If not, it returns **0**. 1372*5a6e8488SAndroid Build Coastguard Worker 1373*5a6e8488SAndroid Build Coastguard Worker**fib(n)** 1374*5a6e8488SAndroid Build Coastguard Worker 1375*5a6e8488SAndroid Build Coastguard Worker: Returns the Fibonacci number of the truncated absolute value of **n**. 1376*5a6e8488SAndroid Build Coastguard Worker 1377*5a6e8488SAndroid Build Coastguard Worker**l2(x)** 1378*5a6e8488SAndroid Build Coastguard Worker 1379*5a6e8488SAndroid Build Coastguard Worker: Returns the logarithm base **2** of **x**. 1380*5a6e8488SAndroid Build Coastguard Worker 1381*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1382*5a6e8488SAndroid Build Coastguard Worker subsection below). 1383*5a6e8488SAndroid Build Coastguard Worker 1384*5a6e8488SAndroid Build Coastguard Worker**l10(x)** 1385*5a6e8488SAndroid Build Coastguard Worker 1386*5a6e8488SAndroid Build Coastguard Worker: Returns the logarithm base **10** of **x**. 1387*5a6e8488SAndroid Build Coastguard Worker 1388*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1389*5a6e8488SAndroid Build Coastguard Worker subsection below). 1390*5a6e8488SAndroid Build Coastguard Worker 1391*5a6e8488SAndroid Build Coastguard Worker**log(x, b)** 1392*5a6e8488SAndroid Build Coastguard Worker 1393*5a6e8488SAndroid Build Coastguard Worker: Returns the logarithm base **b** of **x**. 1394*5a6e8488SAndroid Build Coastguard Worker 1395*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1396*5a6e8488SAndroid Build Coastguard Worker subsection below). 1397*5a6e8488SAndroid Build Coastguard Worker 1398*5a6e8488SAndroid Build Coastguard Worker**cbrt(x)** 1399*5a6e8488SAndroid Build Coastguard Worker 1400*5a6e8488SAndroid Build Coastguard Worker: Returns the cube root of **x**. 1401*5a6e8488SAndroid Build Coastguard Worker 1402*5a6e8488SAndroid Build Coastguard Worker**root(x, n)** 1403*5a6e8488SAndroid Build Coastguard Worker 1404*5a6e8488SAndroid Build Coastguard Worker: Calculates the truncated value of **n**, **r**, and returns the **r**th root 1405*5a6e8488SAndroid Build Coastguard Worker of **x** to the current **scale**. 1406*5a6e8488SAndroid Build Coastguard Worker 1407*5a6e8488SAndroid Build Coastguard Worker If **r** is **0** or negative, this raises an error and causes bc(1) to 1408*5a6e8488SAndroid Build Coastguard Worker reset (see the **RESET** section). It also raises an error and causes bc(1) 1409*5a6e8488SAndroid Build Coastguard Worker to reset if **r** is even and **x** is negative. 1410*5a6e8488SAndroid Build Coastguard Worker 1411*5a6e8488SAndroid Build Coastguard Worker**gcd(a, b)** 1412*5a6e8488SAndroid Build Coastguard Worker 1413*5a6e8488SAndroid Build Coastguard Worker: Returns the greatest common divisor (factor) of the truncated absolute value 1414*5a6e8488SAndroid Build Coastguard Worker of **a** and the truncated absolute value of **b**. 1415*5a6e8488SAndroid Build Coastguard Worker 1416*5a6e8488SAndroid Build Coastguard Worker**lcm(a, b)** 1417*5a6e8488SAndroid Build Coastguard Worker 1418*5a6e8488SAndroid Build Coastguard Worker: Returns the least common multiple of the truncated absolute value of **a** 1419*5a6e8488SAndroid Build Coastguard Worker and the truncated absolute value of **b**. 1420*5a6e8488SAndroid Build Coastguard Worker 1421*5a6e8488SAndroid Build Coastguard Worker**pi(p)** 1422*5a6e8488SAndroid Build Coastguard Worker 1423*5a6e8488SAndroid Build Coastguard Worker: Returns **pi** to **p** decimal places. 1424*5a6e8488SAndroid Build Coastguard Worker 1425*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1426*5a6e8488SAndroid Build Coastguard Worker subsection below). 1427*5a6e8488SAndroid Build Coastguard Worker 1428*5a6e8488SAndroid Build Coastguard Worker**t(x)** 1429*5a6e8488SAndroid Build Coastguard Worker 1430*5a6e8488SAndroid Build Coastguard Worker: Returns the tangent of **x**, which is assumed to be in radians. 1431*5a6e8488SAndroid Build Coastguard Worker 1432*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1433*5a6e8488SAndroid Build Coastguard Worker subsection below). 1434*5a6e8488SAndroid Build Coastguard Worker 1435*5a6e8488SAndroid Build Coastguard Worker**a2(y, x)** 1436*5a6e8488SAndroid Build Coastguard Worker 1437*5a6e8488SAndroid Build Coastguard Worker: Returns the arctangent of **y/x**, in radians. If both **y** and **x** are 1438*5a6e8488SAndroid Build Coastguard Worker equal to **0**, it raises an error and causes bc(1) to reset (see the 1439*5a6e8488SAndroid Build Coastguard Worker **RESET** section). Otherwise, if **x** is greater than **0**, it returns 1440*5a6e8488SAndroid Build Coastguard Worker **a(y/x)**. If **x** is less than **0**, and **y** is greater than or equal 1441*5a6e8488SAndroid Build Coastguard Worker to **0**, it returns **a(y/x)+pi**. If **x** is less than **0**, and **y** 1442*5a6e8488SAndroid Build Coastguard Worker is less than **0**, it returns **a(y/x)-pi**. If **x** is equal to **0**, 1443*5a6e8488SAndroid Build Coastguard Worker and **y** is greater than **0**, it returns **pi/2**. If **x** is equal to 1444*5a6e8488SAndroid Build Coastguard Worker **0**, and **y** is less than **0**, it returns **-pi/2**. 1445*5a6e8488SAndroid Build Coastguard Worker 1446*5a6e8488SAndroid Build Coastguard Worker This function is the same as the **atan2()** function in many programming 1447*5a6e8488SAndroid Build Coastguard Worker languages. 1448*5a6e8488SAndroid Build Coastguard Worker 1449*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1450*5a6e8488SAndroid Build Coastguard Worker subsection below). 1451*5a6e8488SAndroid Build Coastguard Worker 1452*5a6e8488SAndroid Build Coastguard Worker**sin(x)** 1453*5a6e8488SAndroid Build Coastguard Worker 1454*5a6e8488SAndroid Build Coastguard Worker: Returns the sine of **x**, which is assumed to be in radians. 1455*5a6e8488SAndroid Build Coastguard Worker 1456*5a6e8488SAndroid Build Coastguard Worker This is an alias of **s(x)**. 1457*5a6e8488SAndroid Build Coastguard Worker 1458*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1459*5a6e8488SAndroid Build Coastguard Worker subsection below). 1460*5a6e8488SAndroid Build Coastguard Worker 1461*5a6e8488SAndroid Build Coastguard Worker**cos(x)** 1462*5a6e8488SAndroid Build Coastguard Worker 1463*5a6e8488SAndroid Build Coastguard Worker: Returns the cosine of **x**, which is assumed to be in radians. 1464*5a6e8488SAndroid Build Coastguard Worker 1465*5a6e8488SAndroid Build Coastguard Worker This is an alias of **c(x)**. 1466*5a6e8488SAndroid Build Coastguard Worker 1467*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1468*5a6e8488SAndroid Build Coastguard Worker subsection below). 1469*5a6e8488SAndroid Build Coastguard Worker 1470*5a6e8488SAndroid Build Coastguard Worker**tan(x)** 1471*5a6e8488SAndroid Build Coastguard Worker 1472*5a6e8488SAndroid Build Coastguard Worker: Returns the tangent of **x**, which is assumed to be in radians. 1473*5a6e8488SAndroid Build Coastguard Worker 1474*5a6e8488SAndroid Build Coastguard Worker If **x** is equal to **1** or **-1**, this raises an error and causes bc(1) 1475*5a6e8488SAndroid Build Coastguard Worker to reset (see the **RESET** section). 1476*5a6e8488SAndroid Build Coastguard Worker 1477*5a6e8488SAndroid Build Coastguard Worker This is an alias of **t(x)**. 1478*5a6e8488SAndroid Build Coastguard Worker 1479*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1480*5a6e8488SAndroid Build Coastguard Worker subsection below). 1481*5a6e8488SAndroid Build Coastguard Worker 1482*5a6e8488SAndroid Build Coastguard Worker**atan(x)** 1483*5a6e8488SAndroid Build Coastguard Worker 1484*5a6e8488SAndroid Build Coastguard Worker: Returns the arctangent of **x**, in radians. 1485*5a6e8488SAndroid Build Coastguard Worker 1486*5a6e8488SAndroid Build Coastguard Worker This is an alias of **a(x)**. 1487*5a6e8488SAndroid Build Coastguard Worker 1488*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1489*5a6e8488SAndroid Build Coastguard Worker subsection below). 1490*5a6e8488SAndroid Build Coastguard Worker 1491*5a6e8488SAndroid Build Coastguard Worker**atan2(y, x)** 1492*5a6e8488SAndroid Build Coastguard Worker 1493*5a6e8488SAndroid Build Coastguard Worker: Returns the arctangent of **y/x**, in radians. If both **y** and **x** are 1494*5a6e8488SAndroid Build Coastguard Worker equal to **0**, it raises an error and causes bc(1) to reset (see the 1495*5a6e8488SAndroid Build Coastguard Worker **RESET** section). Otherwise, if **x** is greater than **0**, it returns 1496*5a6e8488SAndroid Build Coastguard Worker **a(y/x)**. If **x** is less than **0**, and **y** is greater than or equal 1497*5a6e8488SAndroid Build Coastguard Worker to **0**, it returns **a(y/x)+pi**. If **x** is less than **0**, and **y** 1498*5a6e8488SAndroid Build Coastguard Worker is less than **0**, it returns **a(y/x)-pi**. If **x** is equal to **0**, 1499*5a6e8488SAndroid Build Coastguard Worker and **y** is greater than **0**, it returns **pi/2**. If **x** is equal to 1500*5a6e8488SAndroid Build Coastguard Worker **0**, and **y** is less than **0**, it returns **-pi/2**. 1501*5a6e8488SAndroid Build Coastguard Worker 1502*5a6e8488SAndroid Build Coastguard Worker This function is the same as the **atan2()** function in many programming 1503*5a6e8488SAndroid Build Coastguard Worker languages. 1504*5a6e8488SAndroid Build Coastguard Worker 1505*5a6e8488SAndroid Build Coastguard Worker This is an alias of **a2(y, x)**. 1506*5a6e8488SAndroid Build Coastguard Worker 1507*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1508*5a6e8488SAndroid Build Coastguard Worker subsection below). 1509*5a6e8488SAndroid Build Coastguard Worker 1510*5a6e8488SAndroid Build Coastguard Worker**r2d(x)** 1511*5a6e8488SAndroid Build Coastguard Worker 1512*5a6e8488SAndroid Build Coastguard Worker: Converts **x** from radians to degrees and returns the result. 1513*5a6e8488SAndroid Build Coastguard Worker 1514*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1515*5a6e8488SAndroid Build Coastguard Worker subsection below). 1516*5a6e8488SAndroid Build Coastguard Worker 1517*5a6e8488SAndroid Build Coastguard Worker**d2r(x)** 1518*5a6e8488SAndroid Build Coastguard Worker 1519*5a6e8488SAndroid Build Coastguard Worker: Converts **x** from degrees to radians and returns the result. 1520*5a6e8488SAndroid Build Coastguard Worker 1521*5a6e8488SAndroid Build Coastguard Worker This is a transcendental function (see the *Transcendental Functions* 1522*5a6e8488SAndroid Build Coastguard Worker subsection below). 1523*5a6e8488SAndroid Build Coastguard Worker 1524*5a6e8488SAndroid Build Coastguard Worker**frand(p)** 1525*5a6e8488SAndroid Build Coastguard Worker 1526*5a6e8488SAndroid Build Coastguard Worker: Generates a pseudo-random number between **0** (inclusive) and **1** 1527*5a6e8488SAndroid Build Coastguard Worker (exclusive) with the number of decimal digits after the decimal point equal 1528*5a6e8488SAndroid Build Coastguard Worker to the truncated absolute value of **p**. If **p** is not **0**, then 1529*5a6e8488SAndroid Build Coastguard Worker calling this function will change the value of **seed**. If **p** is **0**, 1530*5a6e8488SAndroid Build Coastguard Worker then **0** is returned, and **seed** is *not* changed. 1531*5a6e8488SAndroid Build Coastguard Worker 1532*5a6e8488SAndroid Build Coastguard Worker**ifrand(i, p)** 1533*5a6e8488SAndroid Build Coastguard Worker 1534*5a6e8488SAndroid Build Coastguard Worker: Generates a pseudo-random number that is between **0** (inclusive) and the 1535*5a6e8488SAndroid Build Coastguard Worker truncated absolute value of **i** (exclusive) with the number of decimal 1536*5a6e8488SAndroid Build Coastguard Worker digits after the decimal point equal to the truncated absolute value of 1537*5a6e8488SAndroid Build Coastguard Worker **p**. If the absolute value of **i** is greater than or equal to **2**, and 1538*5a6e8488SAndroid Build Coastguard Worker **p** is not **0**, then calling this function will change the value of 1539*5a6e8488SAndroid Build Coastguard Worker **seed**; otherwise, **0** is returned, and **seed** is not changed. 1540*5a6e8488SAndroid Build Coastguard Worker 1541*5a6e8488SAndroid Build Coastguard Worker**i2rand(a, b)** 1542*5a6e8488SAndroid Build Coastguard Worker 1543*5a6e8488SAndroid Build Coastguard Worker: Takes the truncated value of **a** and **b** and uses them as inclusive 1544*5a6e8488SAndroid Build Coastguard Worker bounds to enerate a pseudo-random integer. If the difference of the 1545*5a6e8488SAndroid Build Coastguard Worker truncated values of **a** and **b** is **0**, then the truncated value is 1546*5a6e8488SAndroid Build Coastguard Worker returned, and **seed** is *not* changed. Otherwise, this function will 1547*5a6e8488SAndroid Build Coastguard Worker change the value of **seed**. 1548*5a6e8488SAndroid Build Coastguard Worker 1549*5a6e8488SAndroid Build Coastguard Worker**srand(x)** 1550*5a6e8488SAndroid Build Coastguard Worker 1551*5a6e8488SAndroid Build Coastguard Worker: Returns **x** with its sign flipped with probability **0.5**. In other 1552*5a6e8488SAndroid Build Coastguard Worker words, it randomizes the sign of **x**. 1553*5a6e8488SAndroid Build Coastguard Worker 1554*5a6e8488SAndroid Build Coastguard Worker**brand()** 1555*5a6e8488SAndroid Build Coastguard Worker 1556*5a6e8488SAndroid Build Coastguard Worker: Returns a random boolean value (either **0** or **1**). 1557*5a6e8488SAndroid Build Coastguard Worker 1558*5a6e8488SAndroid Build Coastguard Worker**band(a, b)** 1559*5a6e8488SAndroid Build Coastguard Worker 1560*5a6e8488SAndroid Build Coastguard Worker: Takes the truncated absolute value of both **a** and **b** and calculates 1561*5a6e8488SAndroid Build Coastguard Worker and returns the result of the bitwise **and** operation between them. 1562*5a6e8488SAndroid Build Coastguard Worker 1563*5a6e8488SAndroid Build Coastguard Worker If you want to use signed two's complement arguments, use **s2u(x)** to 1564*5a6e8488SAndroid Build Coastguard Worker convert. 1565*5a6e8488SAndroid Build Coastguard Worker 1566*5a6e8488SAndroid Build Coastguard Worker**bor(a, b)** 1567*5a6e8488SAndroid Build Coastguard Worker 1568*5a6e8488SAndroid Build Coastguard Worker: Takes the truncated absolute value of both **a** and **b** and calculates 1569*5a6e8488SAndroid Build Coastguard Worker and returns the result of the bitwise **or** operation between them. 1570*5a6e8488SAndroid Build Coastguard Worker 1571*5a6e8488SAndroid Build Coastguard Worker If you want to use signed two's complement arguments, use **s2u(x)** to 1572*5a6e8488SAndroid Build Coastguard Worker convert. 1573*5a6e8488SAndroid Build Coastguard Worker 1574*5a6e8488SAndroid Build Coastguard Worker**bxor(a, b)** 1575*5a6e8488SAndroid Build Coastguard Worker 1576*5a6e8488SAndroid Build Coastguard Worker: Takes the truncated absolute value of both **a** and **b** and calculates 1577*5a6e8488SAndroid Build Coastguard Worker and returns the result of the bitwise **xor** operation between them. 1578*5a6e8488SAndroid Build Coastguard Worker 1579*5a6e8488SAndroid Build Coastguard Worker If you want to use signed two's complement arguments, use **s2u(x)** to 1580*5a6e8488SAndroid Build Coastguard Worker convert. 1581*5a6e8488SAndroid Build Coastguard Worker 1582*5a6e8488SAndroid Build Coastguard Worker**bshl(a, b)** 1583*5a6e8488SAndroid Build Coastguard Worker 1584*5a6e8488SAndroid Build Coastguard Worker: Takes the truncated absolute value of both **a** and **b** and calculates 1585*5a6e8488SAndroid Build Coastguard Worker and returns the result of **a** bit-shifted left by **b** places. 1586*5a6e8488SAndroid Build Coastguard Worker 1587*5a6e8488SAndroid Build Coastguard Worker If you want to use signed two's complement arguments, use **s2u(x)** to 1588*5a6e8488SAndroid Build Coastguard Worker convert. 1589*5a6e8488SAndroid Build Coastguard Worker 1590*5a6e8488SAndroid Build Coastguard Worker**bshr(a, b)** 1591*5a6e8488SAndroid Build Coastguard Worker 1592*5a6e8488SAndroid Build Coastguard Worker: Takes the truncated absolute value of both **a** and **b** and calculates 1593*5a6e8488SAndroid Build Coastguard Worker and returns the truncated result of **a** bit-shifted right by **b** places. 1594*5a6e8488SAndroid Build Coastguard Worker 1595*5a6e8488SAndroid Build Coastguard Worker If you want to use signed two's complement arguments, use **s2u(x)** to 1596*5a6e8488SAndroid Build Coastguard Worker convert. 1597*5a6e8488SAndroid Build Coastguard Worker 1598*5a6e8488SAndroid Build Coastguard Worker**bnotn(x, n)** 1599*5a6e8488SAndroid Build Coastguard Worker 1600*5a6e8488SAndroid Build Coastguard Worker: Takes the truncated absolute value of **x** and does a bitwise not as though 1601*5a6e8488SAndroid Build Coastguard Worker it has the same number of bytes as the truncated absolute value of **n**. 1602*5a6e8488SAndroid Build Coastguard Worker 1603*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1604*5a6e8488SAndroid Build Coastguard Worker convert. 1605*5a6e8488SAndroid Build Coastguard Worker 1606*5a6e8488SAndroid Build Coastguard Worker**bnot8(x)** 1607*5a6e8488SAndroid Build Coastguard Worker 1608*5a6e8488SAndroid Build Coastguard Worker: Does a bitwise not of the truncated absolute value of **x** as though it has 1609*5a6e8488SAndroid Build Coastguard Worker **8** binary digits (**1** unsigned byte). 1610*5a6e8488SAndroid Build Coastguard Worker 1611*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1612*5a6e8488SAndroid Build Coastguard Worker convert. 1613*5a6e8488SAndroid Build Coastguard Worker 1614*5a6e8488SAndroid Build Coastguard Worker**bnot16(x)** 1615*5a6e8488SAndroid Build Coastguard Worker 1616*5a6e8488SAndroid Build Coastguard Worker: Does a bitwise not of the truncated absolute value of **x** as though it has 1617*5a6e8488SAndroid Build Coastguard Worker **16** binary digits (**2** unsigned bytes). 1618*5a6e8488SAndroid Build Coastguard Worker 1619*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1620*5a6e8488SAndroid Build Coastguard Worker convert. 1621*5a6e8488SAndroid Build Coastguard Worker 1622*5a6e8488SAndroid Build Coastguard Worker**bnot32(x)** 1623*5a6e8488SAndroid Build Coastguard Worker 1624*5a6e8488SAndroid Build Coastguard Worker: Does a bitwise not of the truncated absolute value of **x** as though it has 1625*5a6e8488SAndroid Build Coastguard Worker **32** binary digits (**4** unsigned bytes). 1626*5a6e8488SAndroid Build Coastguard Worker 1627*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1628*5a6e8488SAndroid Build Coastguard Worker convert. 1629*5a6e8488SAndroid Build Coastguard Worker 1630*5a6e8488SAndroid Build Coastguard Worker**bnot64(x)** 1631*5a6e8488SAndroid Build Coastguard Worker 1632*5a6e8488SAndroid Build Coastguard Worker: Does a bitwise not of the truncated absolute value of **x** as though it has 1633*5a6e8488SAndroid Build Coastguard Worker **64** binary digits (**8** unsigned bytes). 1634*5a6e8488SAndroid Build Coastguard Worker 1635*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1636*5a6e8488SAndroid Build Coastguard Worker convert. 1637*5a6e8488SAndroid Build Coastguard Worker 1638*5a6e8488SAndroid Build Coastguard Worker**bnot(x)** 1639*5a6e8488SAndroid Build Coastguard Worker 1640*5a6e8488SAndroid Build Coastguard Worker: Does a bitwise not of the truncated absolute value of **x** as though it has 1641*5a6e8488SAndroid Build Coastguard Worker the minimum number of power of two unsigned bytes. 1642*5a6e8488SAndroid Build Coastguard Worker 1643*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1644*5a6e8488SAndroid Build Coastguard Worker convert. 1645*5a6e8488SAndroid Build Coastguard Worker 1646*5a6e8488SAndroid Build Coastguard Worker**brevn(x, n)** 1647*5a6e8488SAndroid Build Coastguard Worker 1648*5a6e8488SAndroid Build Coastguard Worker: Runs a bit reversal on the truncated absolute value of **x** as though it 1649*5a6e8488SAndroid Build Coastguard Worker has the same number of 8-bit bytes as the truncated absolute value of **n**. 1650*5a6e8488SAndroid Build Coastguard Worker 1651*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1652*5a6e8488SAndroid Build Coastguard Worker convert. 1653*5a6e8488SAndroid Build Coastguard Worker 1654*5a6e8488SAndroid Build Coastguard Worker**brev8(x)** 1655*5a6e8488SAndroid Build Coastguard Worker 1656*5a6e8488SAndroid Build Coastguard Worker: Runs a bit reversal on the truncated absolute value of **x** as though it 1657*5a6e8488SAndroid Build Coastguard Worker has 8 binary digits (**1** unsigned byte). 1658*5a6e8488SAndroid Build Coastguard Worker 1659*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1660*5a6e8488SAndroid Build Coastguard Worker convert. 1661*5a6e8488SAndroid Build Coastguard Worker 1662*5a6e8488SAndroid Build Coastguard Worker**brev16(x)** 1663*5a6e8488SAndroid Build Coastguard Worker 1664*5a6e8488SAndroid Build Coastguard Worker: Runs a bit reversal on the truncated absolute value of **x** as though it 1665*5a6e8488SAndroid Build Coastguard Worker has 16 binary digits (**2** unsigned bytes). 1666*5a6e8488SAndroid Build Coastguard Worker 1667*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1668*5a6e8488SAndroid Build Coastguard Worker convert. 1669*5a6e8488SAndroid Build Coastguard Worker 1670*5a6e8488SAndroid Build Coastguard Worker**brev32(x)** 1671*5a6e8488SAndroid Build Coastguard Worker 1672*5a6e8488SAndroid Build Coastguard Worker: Runs a bit reversal on the truncated absolute value of **x** as though it 1673*5a6e8488SAndroid Build Coastguard Worker has 32 binary digits (**4** unsigned bytes). 1674*5a6e8488SAndroid Build Coastguard Worker 1675*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1676*5a6e8488SAndroid Build Coastguard Worker convert. 1677*5a6e8488SAndroid Build Coastguard Worker 1678*5a6e8488SAndroid Build Coastguard Worker**brev64(x)** 1679*5a6e8488SAndroid Build Coastguard Worker 1680*5a6e8488SAndroid Build Coastguard Worker: Runs a bit reversal on the truncated absolute value of **x** as though it 1681*5a6e8488SAndroid Build Coastguard Worker has 64 binary digits (**8** unsigned bytes). 1682*5a6e8488SAndroid Build Coastguard Worker 1683*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1684*5a6e8488SAndroid Build Coastguard Worker convert. 1685*5a6e8488SAndroid Build Coastguard Worker 1686*5a6e8488SAndroid Build Coastguard Worker**brev(x)** 1687*5a6e8488SAndroid Build Coastguard Worker 1688*5a6e8488SAndroid Build Coastguard Worker: Runs a bit reversal on the truncated absolute value of **x** as though it 1689*5a6e8488SAndroid Build Coastguard Worker has the minimum number of power of two unsigned bytes. 1690*5a6e8488SAndroid Build Coastguard Worker 1691*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1692*5a6e8488SAndroid Build Coastguard Worker convert. 1693*5a6e8488SAndroid Build Coastguard Worker 1694*5a6e8488SAndroid Build Coastguard Worker**broln(x, p, n)** 1695*5a6e8488SAndroid Build Coastguard Worker 1696*5a6e8488SAndroid Build Coastguard Worker: Does a left bitwise rotatation of the truncated absolute value of **x**, as 1697*5a6e8488SAndroid Build Coastguard Worker though it has the same number of unsigned 8-bit bytes as the truncated 1698*5a6e8488SAndroid Build Coastguard Worker absolute value of **n**, by the number of places equal to the truncated 1699*5a6e8488SAndroid Build Coastguard Worker absolute value of **p** modded by the **2** to the power of the number of 1700*5a6e8488SAndroid Build Coastguard Worker binary digits in **n** 8-bit bytes. 1701*5a6e8488SAndroid Build Coastguard Worker 1702*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1703*5a6e8488SAndroid Build Coastguard Worker convert. 1704*5a6e8488SAndroid Build Coastguard Worker 1705*5a6e8488SAndroid Build Coastguard Worker**brol8(x, p)** 1706*5a6e8488SAndroid Build Coastguard Worker 1707*5a6e8488SAndroid Build Coastguard Worker: Does a left bitwise rotatation of the truncated absolute value of **x**, as 1708*5a6e8488SAndroid Build Coastguard Worker though it has **8** binary digits (**1** unsigned byte), by the number of 1709*5a6e8488SAndroid Build Coastguard Worker places equal to the truncated absolute value of **p** modded by **2** to the 1710*5a6e8488SAndroid Build Coastguard Worker power of **8**. 1711*5a6e8488SAndroid Build Coastguard Worker 1712*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1713*5a6e8488SAndroid Build Coastguard Worker convert. 1714*5a6e8488SAndroid Build Coastguard Worker 1715*5a6e8488SAndroid Build Coastguard Worker**brol16(x, p)** 1716*5a6e8488SAndroid Build Coastguard Worker 1717*5a6e8488SAndroid Build Coastguard Worker: Does a left bitwise rotatation of the truncated absolute value of **x**, as 1718*5a6e8488SAndroid Build Coastguard Worker though it has **16** binary digits (**2** unsigned bytes), by the number of 1719*5a6e8488SAndroid Build Coastguard Worker places equal to the truncated absolute value of **p** modded by **2** to the 1720*5a6e8488SAndroid Build Coastguard Worker power of **16**. 1721*5a6e8488SAndroid Build Coastguard Worker 1722*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1723*5a6e8488SAndroid Build Coastguard Worker convert. 1724*5a6e8488SAndroid Build Coastguard Worker 1725*5a6e8488SAndroid Build Coastguard Worker**brol32(x, p)** 1726*5a6e8488SAndroid Build Coastguard Worker 1727*5a6e8488SAndroid Build Coastguard Worker: Does a left bitwise rotatation of the truncated absolute value of **x**, as 1728*5a6e8488SAndroid Build Coastguard Worker though it has **32** binary digits (**4** unsigned bytes), by the number of 1729*5a6e8488SAndroid Build Coastguard Worker places equal to the truncated absolute value of **p** modded by **2** to the 1730*5a6e8488SAndroid Build Coastguard Worker power of **32**. 1731*5a6e8488SAndroid Build Coastguard Worker 1732*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1733*5a6e8488SAndroid Build Coastguard Worker convert. 1734*5a6e8488SAndroid Build Coastguard Worker 1735*5a6e8488SAndroid Build Coastguard Worker**brol64(x, p)** 1736*5a6e8488SAndroid Build Coastguard Worker 1737*5a6e8488SAndroid Build Coastguard Worker: Does a left bitwise rotatation of the truncated absolute value of **x**, as 1738*5a6e8488SAndroid Build Coastguard Worker though it has **64** binary digits (**8** unsigned bytes), by the number of 1739*5a6e8488SAndroid Build Coastguard Worker places equal to the truncated absolute value of **p** modded by **2** to the 1740*5a6e8488SAndroid Build Coastguard Worker power of **64**. 1741*5a6e8488SAndroid Build Coastguard Worker 1742*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1743*5a6e8488SAndroid Build Coastguard Worker convert. 1744*5a6e8488SAndroid Build Coastguard Worker 1745*5a6e8488SAndroid Build Coastguard Worker**brol(x, p)** 1746*5a6e8488SAndroid Build Coastguard Worker 1747*5a6e8488SAndroid Build Coastguard Worker: Does a left bitwise rotatation of the truncated absolute value of **x**, as 1748*5a6e8488SAndroid Build Coastguard Worker though it has the minimum number of power of two unsigned 8-bit bytes, by 1749*5a6e8488SAndroid Build Coastguard Worker the number of places equal to the truncated absolute value of **p** modded 1750*5a6e8488SAndroid Build Coastguard Worker by 2 to the power of the number of binary digits in the minimum number of 1751*5a6e8488SAndroid Build Coastguard Worker 8-bit bytes. 1752*5a6e8488SAndroid Build Coastguard Worker 1753*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1754*5a6e8488SAndroid Build Coastguard Worker convert. 1755*5a6e8488SAndroid Build Coastguard Worker 1756*5a6e8488SAndroid Build Coastguard Worker**brorn(x, p, n)** 1757*5a6e8488SAndroid Build Coastguard Worker 1758*5a6e8488SAndroid Build Coastguard Worker: Does a right bitwise rotatation of the truncated absolute value of **x**, as 1759*5a6e8488SAndroid Build Coastguard Worker though it has the same number of unsigned 8-bit bytes as the truncated 1760*5a6e8488SAndroid Build Coastguard Worker absolute value of **n**, by the number of places equal to the truncated 1761*5a6e8488SAndroid Build Coastguard Worker absolute value of **p** modded by the **2** to the power of the number of 1762*5a6e8488SAndroid Build Coastguard Worker binary digits in **n** 8-bit bytes. 1763*5a6e8488SAndroid Build Coastguard Worker 1764*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1765*5a6e8488SAndroid Build Coastguard Worker convert. 1766*5a6e8488SAndroid Build Coastguard Worker 1767*5a6e8488SAndroid Build Coastguard Worker**bror8(x, p)** 1768*5a6e8488SAndroid Build Coastguard Worker 1769*5a6e8488SAndroid Build Coastguard Worker: Does a right bitwise rotatation of the truncated absolute value of **x**, as 1770*5a6e8488SAndroid Build Coastguard Worker though it has **8** binary digits (**1** unsigned byte), by the number of 1771*5a6e8488SAndroid Build Coastguard Worker places equal to the truncated absolute value of **p** modded by **2** to the 1772*5a6e8488SAndroid Build Coastguard Worker power of **8**. 1773*5a6e8488SAndroid Build Coastguard Worker 1774*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1775*5a6e8488SAndroid Build Coastguard Worker convert. 1776*5a6e8488SAndroid Build Coastguard Worker 1777*5a6e8488SAndroid Build Coastguard Worker**bror16(x, p)** 1778*5a6e8488SAndroid Build Coastguard Worker 1779*5a6e8488SAndroid Build Coastguard Worker: Does a right bitwise rotatation of the truncated absolute value of **x**, as 1780*5a6e8488SAndroid Build Coastguard Worker though it has **16** binary digits (**2** unsigned bytes), by the number of 1781*5a6e8488SAndroid Build Coastguard Worker places equal to the truncated absolute value of **p** modded by **2** to the 1782*5a6e8488SAndroid Build Coastguard Worker power of **16**. 1783*5a6e8488SAndroid Build Coastguard Worker 1784*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1785*5a6e8488SAndroid Build Coastguard Worker convert. 1786*5a6e8488SAndroid Build Coastguard Worker 1787*5a6e8488SAndroid Build Coastguard Worker**bror32(x, p)** 1788*5a6e8488SAndroid Build Coastguard Worker 1789*5a6e8488SAndroid Build Coastguard Worker: Does a right bitwise rotatation of the truncated absolute value of **x**, as 1790*5a6e8488SAndroid Build Coastguard Worker though it has **32** binary digits (**2** unsigned bytes), by the number of 1791*5a6e8488SAndroid Build Coastguard Worker places equal to the truncated absolute value of **p** modded by **2** to the 1792*5a6e8488SAndroid Build Coastguard Worker power of **32**. 1793*5a6e8488SAndroid Build Coastguard Worker 1794*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1795*5a6e8488SAndroid Build Coastguard Worker convert. 1796*5a6e8488SAndroid Build Coastguard Worker 1797*5a6e8488SAndroid Build Coastguard Worker**bror64(x, p)** 1798*5a6e8488SAndroid Build Coastguard Worker 1799*5a6e8488SAndroid Build Coastguard Worker: Does a right bitwise rotatation of the truncated absolute value of **x**, as 1800*5a6e8488SAndroid Build Coastguard Worker though it has **64** binary digits (**2** unsigned bytes), by the number of 1801*5a6e8488SAndroid Build Coastguard Worker places equal to the truncated absolute value of **p** modded by **2** to the 1802*5a6e8488SAndroid Build Coastguard Worker power of **64**. 1803*5a6e8488SAndroid Build Coastguard Worker 1804*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1805*5a6e8488SAndroid Build Coastguard Worker convert. 1806*5a6e8488SAndroid Build Coastguard Worker 1807*5a6e8488SAndroid Build Coastguard Worker**bror(x, p)** 1808*5a6e8488SAndroid Build Coastguard Worker 1809*5a6e8488SAndroid Build Coastguard Worker: Does a right bitwise rotatation of the truncated absolute value of **x**, as 1810*5a6e8488SAndroid Build Coastguard Worker though it has the minimum number of power of two unsigned 8-bit bytes, by 1811*5a6e8488SAndroid Build Coastguard Worker the number of places equal to the truncated absolute value of **p** modded 1812*5a6e8488SAndroid Build Coastguard Worker by 2 to the power of the number of binary digits in the minimum number of 1813*5a6e8488SAndroid Build Coastguard Worker 8-bit bytes. 1814*5a6e8488SAndroid Build Coastguard Worker 1815*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1816*5a6e8488SAndroid Build Coastguard Worker convert. 1817*5a6e8488SAndroid Build Coastguard Worker 1818*5a6e8488SAndroid Build Coastguard Worker**bmodn(x, n)** 1819*5a6e8488SAndroid Build Coastguard Worker 1820*5a6e8488SAndroid Build Coastguard Worker: Returns the modulus of the truncated absolute value of **x** by **2** to the 1821*5a6e8488SAndroid Build Coastguard Worker power of the multiplication of the truncated absolute value of **n** and 1822*5a6e8488SAndroid Build Coastguard Worker **8**. 1823*5a6e8488SAndroid Build Coastguard Worker 1824*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1825*5a6e8488SAndroid Build Coastguard Worker convert. 1826*5a6e8488SAndroid Build Coastguard Worker 1827*5a6e8488SAndroid Build Coastguard Worker**bmod8(x, n)** 1828*5a6e8488SAndroid Build Coastguard Worker 1829*5a6e8488SAndroid Build Coastguard Worker: Returns the modulus of the truncated absolute value of **x** by **2** to the 1830*5a6e8488SAndroid Build Coastguard Worker power of **8**. 1831*5a6e8488SAndroid Build Coastguard Worker 1832*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1833*5a6e8488SAndroid Build Coastguard Worker convert. 1834*5a6e8488SAndroid Build Coastguard Worker 1835*5a6e8488SAndroid Build Coastguard Worker**bmod16(x, n)** 1836*5a6e8488SAndroid Build Coastguard Worker 1837*5a6e8488SAndroid Build Coastguard Worker: Returns the modulus of the truncated absolute value of **x** by **2** to the 1838*5a6e8488SAndroid Build Coastguard Worker power of **16**. 1839*5a6e8488SAndroid Build Coastguard Worker 1840*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1841*5a6e8488SAndroid Build Coastguard Worker convert. 1842*5a6e8488SAndroid Build Coastguard Worker 1843*5a6e8488SAndroid Build Coastguard Worker**bmod32(x, n)** 1844*5a6e8488SAndroid Build Coastguard Worker 1845*5a6e8488SAndroid Build Coastguard Worker: Returns the modulus of the truncated absolute value of **x** by **2** to the 1846*5a6e8488SAndroid Build Coastguard Worker power of **32**. 1847*5a6e8488SAndroid Build Coastguard Worker 1848*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1849*5a6e8488SAndroid Build Coastguard Worker convert. 1850*5a6e8488SAndroid Build Coastguard Worker 1851*5a6e8488SAndroid Build Coastguard Worker**bmod64(x, n)** 1852*5a6e8488SAndroid Build Coastguard Worker 1853*5a6e8488SAndroid Build Coastguard Worker: Returns the modulus of the truncated absolute value of **x** by **2** to the 1854*5a6e8488SAndroid Build Coastguard Worker power of **64**. 1855*5a6e8488SAndroid Build Coastguard Worker 1856*5a6e8488SAndroid Build Coastguard Worker If you want to a use signed two's complement argument, use **s2u(x)** to 1857*5a6e8488SAndroid Build Coastguard Worker convert. 1858*5a6e8488SAndroid Build Coastguard Worker 1859*5a6e8488SAndroid Build Coastguard Worker**bunrev(t)** 1860*5a6e8488SAndroid Build Coastguard Worker 1861*5a6e8488SAndroid Build Coastguard Worker: Assumes **t** is a bitwise-reversed number with an extra set bit one place 1862*5a6e8488SAndroid Build Coastguard Worker more significant than the real most significant bit (which was the least 1863*5a6e8488SAndroid Build Coastguard Worker significant bit in the original number). This number is reversed and 1864*5a6e8488SAndroid Build Coastguard Worker returned without the extra set bit. 1865*5a6e8488SAndroid Build Coastguard Worker 1866*5a6e8488SAndroid Build Coastguard Worker This function is used to implement other bitwise functions; it is not meant 1867*5a6e8488SAndroid Build Coastguard Worker to be used by users, but it can be. 1868*5a6e8488SAndroid Build Coastguard Worker 1869*5a6e8488SAndroid Build Coastguard Worker**plz(x)** 1870*5a6e8488SAndroid Build Coastguard Worker 1871*5a6e8488SAndroid Build Coastguard Worker: If **x** is not equal to **0** and greater that **-1** and less than **1**, 1872*5a6e8488SAndroid Build Coastguard Worker it is printed with a leading zero, regardless of the use of the **-z** 1873*5a6e8488SAndroid Build Coastguard Worker option (see the **OPTIONS** section) and without a trailing newline. 1874*5a6e8488SAndroid Build Coastguard Worker 1875*5a6e8488SAndroid Build Coastguard Worker Otherwise, **x** is printed normally, without a trailing newline. 1876*5a6e8488SAndroid Build Coastguard Worker 1877*5a6e8488SAndroid Build Coastguard Worker**plznl(x)** 1878*5a6e8488SAndroid Build Coastguard Worker 1879*5a6e8488SAndroid Build Coastguard Worker: If **x** is not equal to **0** and greater that **-1** and less than **1**, 1880*5a6e8488SAndroid Build Coastguard Worker it is printed with a leading zero, regardless of the use of the **-z** 1881*5a6e8488SAndroid Build Coastguard Worker option (see the **OPTIONS** section) and with a trailing newline. 1882*5a6e8488SAndroid Build Coastguard Worker 1883*5a6e8488SAndroid Build Coastguard Worker Otherwise, **x** is printed normally, with a trailing newline. 1884*5a6e8488SAndroid Build Coastguard Worker 1885*5a6e8488SAndroid Build Coastguard Worker**pnlz(x)** 1886*5a6e8488SAndroid Build Coastguard Worker 1887*5a6e8488SAndroid Build Coastguard Worker: If **x** is not equal to **0** and greater that **-1** and less than **1**, 1888*5a6e8488SAndroid Build Coastguard Worker it is printed without a leading zero, regardless of the use of the **-z** 1889*5a6e8488SAndroid Build Coastguard Worker option (see the **OPTIONS** section) and without a trailing newline. 1890*5a6e8488SAndroid Build Coastguard Worker 1891*5a6e8488SAndroid Build Coastguard Worker Otherwise, **x** is printed normally, without a trailing newline. 1892*5a6e8488SAndroid Build Coastguard Worker 1893*5a6e8488SAndroid Build Coastguard Worker**pnlznl(x)** 1894*5a6e8488SAndroid Build Coastguard Worker 1895*5a6e8488SAndroid Build Coastguard Worker: If **x** is not equal to **0** and greater that **-1** and less than **1**, 1896*5a6e8488SAndroid Build Coastguard Worker it is printed without a leading zero, regardless of the use of the **-z** 1897*5a6e8488SAndroid Build Coastguard Worker option (see the **OPTIONS** section) and with a trailing newline. 1898*5a6e8488SAndroid Build Coastguard Worker 1899*5a6e8488SAndroid Build Coastguard Worker Otherwise, **x** is printed normally, with a trailing newline. 1900*5a6e8488SAndroid Build Coastguard Worker 1901*5a6e8488SAndroid Build Coastguard Worker**ubytes(x)** 1902*5a6e8488SAndroid Build Coastguard Worker 1903*5a6e8488SAndroid Build Coastguard Worker: Returns the numbers of unsigned integer bytes required to hold the truncated 1904*5a6e8488SAndroid Build Coastguard Worker absolute value of **x**. 1905*5a6e8488SAndroid Build Coastguard Worker 1906*5a6e8488SAndroid Build Coastguard Worker**sbytes(x)** 1907*5a6e8488SAndroid Build Coastguard Worker 1908*5a6e8488SAndroid Build Coastguard Worker: Returns the numbers of signed, two's-complement integer bytes required to 1909*5a6e8488SAndroid Build Coastguard Worker hold the truncated value of **x**. 1910*5a6e8488SAndroid Build Coastguard Worker 1911*5a6e8488SAndroid Build Coastguard Worker**s2u(x)** 1912*5a6e8488SAndroid Build Coastguard Worker 1913*5a6e8488SAndroid Build Coastguard Worker: Returns **x** if it is non-negative. If it *is* negative, then it calculates 1914*5a6e8488SAndroid Build Coastguard Worker what **x** would be as a 2's-complement signed integer and returns the 1915*5a6e8488SAndroid Build Coastguard Worker non-negative integer that would have the same representation in binary. 1916*5a6e8488SAndroid Build Coastguard Worker 1917*5a6e8488SAndroid Build Coastguard Worker**s2un(x,n)** 1918*5a6e8488SAndroid Build Coastguard Worker 1919*5a6e8488SAndroid Build Coastguard Worker: Returns **x** if it is non-negative. If it *is* negative, then it calculates 1920*5a6e8488SAndroid Build Coastguard Worker what **x** would be as a 2's-complement signed integer with **n** bytes and 1921*5a6e8488SAndroid Build Coastguard Worker returns the non-negative integer that would have the same representation in 1922*5a6e8488SAndroid Build Coastguard Worker binary. If **x** cannot fit into **n** 2's-complement signed bytes, it is 1923*5a6e8488SAndroid Build Coastguard Worker truncated to fit. 1924*5a6e8488SAndroid Build Coastguard Worker 1925*5a6e8488SAndroid Build Coastguard Worker**hex(x)** 1926*5a6e8488SAndroid Build Coastguard Worker 1927*5a6e8488SAndroid Build Coastguard Worker: Outputs the hexadecimal (base **16**) representation of **x**. 1928*5a6e8488SAndroid Build Coastguard Worker 1929*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 1930*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 1931*5a6e8488SAndroid Build Coastguard Worker 1932*5a6e8488SAndroid Build Coastguard Worker**binary(x)** 1933*5a6e8488SAndroid Build Coastguard Worker 1934*5a6e8488SAndroid Build Coastguard Worker: Outputs the binary (base **2**) representation of **x**. 1935*5a6e8488SAndroid Build Coastguard Worker 1936*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 1937*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 1938*5a6e8488SAndroid Build Coastguard Worker 1939*5a6e8488SAndroid Build Coastguard Worker**output(x, b)** 1940*5a6e8488SAndroid Build Coastguard Worker 1941*5a6e8488SAndroid Build Coastguard Worker: Outputs the base **b** representation of **x**. 1942*5a6e8488SAndroid Build Coastguard Worker 1943*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 1944*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 1945*5a6e8488SAndroid Build Coastguard Worker 1946*5a6e8488SAndroid Build Coastguard Worker**uint(x)** 1947*5a6e8488SAndroid Build Coastguard Worker 1948*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as an 1949*5a6e8488SAndroid Build Coastguard Worker unsigned integer in as few power of two bytes as possible. Both outputs are 1950*5a6e8488SAndroid Build Coastguard Worker split into bytes separated by spaces. 1951*5a6e8488SAndroid Build Coastguard Worker 1952*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer or is negative, an error message is printed 1953*5a6e8488SAndroid Build Coastguard Worker instead, but bc(1) is not reset (see the **RESET** section). 1954*5a6e8488SAndroid Build Coastguard Worker 1955*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 1956*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 1957*5a6e8488SAndroid Build Coastguard Worker 1958*5a6e8488SAndroid Build Coastguard Worker**int(x)** 1959*5a6e8488SAndroid Build Coastguard Worker 1960*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as a signed, 1961*5a6e8488SAndroid Build Coastguard Worker two's-complement integer in as few power of two bytes as possible. Both 1962*5a6e8488SAndroid Build Coastguard Worker outputs are split into bytes separated by spaces. 1963*5a6e8488SAndroid Build Coastguard Worker 1964*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer, an error message is printed instead, but bc(1) 1965*5a6e8488SAndroid Build Coastguard Worker is not reset (see the **RESET** section). 1966*5a6e8488SAndroid Build Coastguard Worker 1967*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 1968*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 1969*5a6e8488SAndroid Build Coastguard Worker 1970*5a6e8488SAndroid Build Coastguard Worker**uintn(x, n)** 1971*5a6e8488SAndroid Build Coastguard Worker 1972*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as an 1973*5a6e8488SAndroid Build Coastguard Worker unsigned integer in **n** bytes. Both outputs are split into bytes separated 1974*5a6e8488SAndroid Build Coastguard Worker by spaces. 1975*5a6e8488SAndroid Build Coastguard Worker 1976*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer, is negative, or cannot fit into **n** bytes, an 1977*5a6e8488SAndroid Build Coastguard Worker error message is printed instead, but bc(1) is not reset (see the **RESET** 1978*5a6e8488SAndroid Build Coastguard Worker section). 1979*5a6e8488SAndroid Build Coastguard Worker 1980*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 1981*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 1982*5a6e8488SAndroid Build Coastguard Worker 1983*5a6e8488SAndroid Build Coastguard Worker**intn(x, n)** 1984*5a6e8488SAndroid Build Coastguard Worker 1985*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as a signed, 1986*5a6e8488SAndroid Build Coastguard Worker two's-complement integer in **n** bytes. Both outputs are split into bytes 1987*5a6e8488SAndroid Build Coastguard Worker separated by spaces. 1988*5a6e8488SAndroid Build Coastguard Worker 1989*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer or cannot fit into **n** bytes, an error message 1990*5a6e8488SAndroid Build Coastguard Worker is printed instead, but bc(1) is not reset (see the **RESET** section). 1991*5a6e8488SAndroid Build Coastguard Worker 1992*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 1993*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 1994*5a6e8488SAndroid Build Coastguard Worker 1995*5a6e8488SAndroid Build Coastguard Worker**uint8(x)** 1996*5a6e8488SAndroid Build Coastguard Worker 1997*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as an 1998*5a6e8488SAndroid Build Coastguard Worker unsigned integer in **1** byte. Both outputs are split into bytes separated 1999*5a6e8488SAndroid Build Coastguard Worker by spaces. 2000*5a6e8488SAndroid Build Coastguard Worker 2001*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer, is negative, or cannot fit into **1** byte, an 2002*5a6e8488SAndroid Build Coastguard Worker error message is printed instead, but bc(1) is not reset (see the **RESET** 2003*5a6e8488SAndroid Build Coastguard Worker section). 2004*5a6e8488SAndroid Build Coastguard Worker 2005*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2006*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2007*5a6e8488SAndroid Build Coastguard Worker 2008*5a6e8488SAndroid Build Coastguard Worker**int8(x)** 2009*5a6e8488SAndroid Build Coastguard Worker 2010*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as a signed, 2011*5a6e8488SAndroid Build Coastguard Worker two's-complement integer in **1** byte. Both outputs are split into bytes 2012*5a6e8488SAndroid Build Coastguard Worker separated by spaces. 2013*5a6e8488SAndroid Build Coastguard Worker 2014*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer or cannot fit into **1** byte, an error message 2015*5a6e8488SAndroid Build Coastguard Worker is printed instead, but bc(1) is not reset (see the **RESET** section). 2016*5a6e8488SAndroid Build Coastguard Worker 2017*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2018*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2019*5a6e8488SAndroid Build Coastguard Worker 2020*5a6e8488SAndroid Build Coastguard Worker**uint16(x)** 2021*5a6e8488SAndroid Build Coastguard Worker 2022*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as an 2023*5a6e8488SAndroid Build Coastguard Worker unsigned integer in **2** bytes. Both outputs are split into bytes separated 2024*5a6e8488SAndroid Build Coastguard Worker by spaces. 2025*5a6e8488SAndroid Build Coastguard Worker 2026*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer, is negative, or cannot fit into **2** bytes, an 2027*5a6e8488SAndroid Build Coastguard Worker error message is printed instead, but bc(1) is not reset (see the **RESET** 2028*5a6e8488SAndroid Build Coastguard Worker section). 2029*5a6e8488SAndroid Build Coastguard Worker 2030*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2031*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2032*5a6e8488SAndroid Build Coastguard Worker 2033*5a6e8488SAndroid Build Coastguard Worker**int16(x)** 2034*5a6e8488SAndroid Build Coastguard Worker 2035*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as a signed, 2036*5a6e8488SAndroid Build Coastguard Worker two's-complement integer in **2** bytes. Both outputs are split into bytes 2037*5a6e8488SAndroid Build Coastguard Worker separated by spaces. 2038*5a6e8488SAndroid Build Coastguard Worker 2039*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer or cannot fit into **2** bytes, an error message 2040*5a6e8488SAndroid Build Coastguard Worker is printed instead, but bc(1) is not reset (see the **RESET** section). 2041*5a6e8488SAndroid Build Coastguard Worker 2042*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2043*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2044*5a6e8488SAndroid Build Coastguard Worker 2045*5a6e8488SAndroid Build Coastguard Worker**uint32(x)** 2046*5a6e8488SAndroid Build Coastguard Worker 2047*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as an 2048*5a6e8488SAndroid Build Coastguard Worker unsigned integer in **4** bytes. Both outputs are split into bytes separated 2049*5a6e8488SAndroid Build Coastguard Worker by spaces. 2050*5a6e8488SAndroid Build Coastguard Worker 2051*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer, is negative, or cannot fit into **4** bytes, an 2052*5a6e8488SAndroid Build Coastguard Worker error message is printed instead, but bc(1) is not reset (see the **RESET** 2053*5a6e8488SAndroid Build Coastguard Worker section). 2054*5a6e8488SAndroid Build Coastguard Worker 2055*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2056*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2057*5a6e8488SAndroid Build Coastguard Worker 2058*5a6e8488SAndroid Build Coastguard Worker**int32(x)** 2059*5a6e8488SAndroid Build Coastguard Worker 2060*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as a signed, 2061*5a6e8488SAndroid Build Coastguard Worker two's-complement integer in **4** bytes. Both outputs are split into bytes 2062*5a6e8488SAndroid Build Coastguard Worker separated by spaces. 2063*5a6e8488SAndroid Build Coastguard Worker 2064*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer or cannot fit into **4** bytes, an error message 2065*5a6e8488SAndroid Build Coastguard Worker is printed instead, but bc(1) is not reset (see the **RESET** section). 2066*5a6e8488SAndroid Build Coastguard Worker 2067*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2068*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2069*5a6e8488SAndroid Build Coastguard Worker 2070*5a6e8488SAndroid Build Coastguard Worker**uint64(x)** 2071*5a6e8488SAndroid Build Coastguard Worker 2072*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as an 2073*5a6e8488SAndroid Build Coastguard Worker unsigned integer in **8** bytes. Both outputs are split into bytes separated 2074*5a6e8488SAndroid Build Coastguard Worker by spaces. 2075*5a6e8488SAndroid Build Coastguard Worker 2076*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer, is negative, or cannot fit into **8** bytes, an 2077*5a6e8488SAndroid Build Coastguard Worker error message is printed instead, but bc(1) is not reset (see the **RESET** 2078*5a6e8488SAndroid Build Coastguard Worker section). 2079*5a6e8488SAndroid Build Coastguard Worker 2080*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2081*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2082*5a6e8488SAndroid Build Coastguard Worker 2083*5a6e8488SAndroid Build Coastguard Worker**int64(x)** 2084*5a6e8488SAndroid Build Coastguard Worker 2085*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation, in binary and hexadecimal, of **x** as a signed, 2086*5a6e8488SAndroid Build Coastguard Worker two's-complement integer in **8** bytes. Both outputs are split into bytes 2087*5a6e8488SAndroid Build Coastguard Worker separated by spaces. 2088*5a6e8488SAndroid Build Coastguard Worker 2089*5a6e8488SAndroid Build Coastguard Worker If **x** is not an integer or cannot fit into **8** bytes, an error message 2090*5a6e8488SAndroid Build Coastguard Worker is printed instead, but bc(1) is not reset (see the **RESET** section). 2091*5a6e8488SAndroid Build Coastguard Worker 2092*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2093*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2094*5a6e8488SAndroid Build Coastguard Worker 2095*5a6e8488SAndroid Build Coastguard Worker**hex_uint(x, n)** 2096*5a6e8488SAndroid Build Coastguard Worker 2097*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation of the truncated absolute value of **x** as an 2098*5a6e8488SAndroid Build Coastguard Worker unsigned integer in hexadecimal using **n** bytes. Not all of the value will 2099*5a6e8488SAndroid Build Coastguard Worker be output if **n** is too small. 2100*5a6e8488SAndroid Build Coastguard Worker 2101*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2102*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2103*5a6e8488SAndroid Build Coastguard Worker 2104*5a6e8488SAndroid Build Coastguard Worker**binary_uint(x, n)** 2105*5a6e8488SAndroid Build Coastguard Worker 2106*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation of the truncated absolute value of **x** as an 2107*5a6e8488SAndroid Build Coastguard Worker unsigned integer in binary using **n** bytes. Not all of the value will be 2108*5a6e8488SAndroid Build Coastguard Worker output if **n** is too small. 2109*5a6e8488SAndroid Build Coastguard Worker 2110*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2111*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2112*5a6e8488SAndroid Build Coastguard Worker 2113*5a6e8488SAndroid Build Coastguard Worker**output_uint(x, n)** 2114*5a6e8488SAndroid Build Coastguard Worker 2115*5a6e8488SAndroid Build Coastguard Worker: Outputs the representation of the truncated absolute value of **x** as an 2116*5a6e8488SAndroid Build Coastguard Worker unsigned integer in the current **obase** (see the **SYNTAX** section) using 2117*5a6e8488SAndroid Build Coastguard Worker **n** bytes. Not all of the value will be output if **n** is too small. 2118*5a6e8488SAndroid Build Coastguard Worker 2119*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2120*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2121*5a6e8488SAndroid Build Coastguard Worker 2122*5a6e8488SAndroid Build Coastguard Worker**output_byte(x, i)** 2123*5a6e8488SAndroid Build Coastguard Worker 2124*5a6e8488SAndroid Build Coastguard Worker: Outputs byte **i** of the truncated absolute value of **x**, where **0** is 2125*5a6e8488SAndroid Build Coastguard Worker the least significant byte and **number_of_bytes - 1** is the most 2126*5a6e8488SAndroid Build Coastguard Worker significant byte. 2127*5a6e8488SAndroid Build Coastguard Worker 2128*5a6e8488SAndroid Build Coastguard Worker This is a **void** function (see the *Void Functions* subsection of the 2129*5a6e8488SAndroid Build Coastguard Worker **FUNCTIONS** section). 2130*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2131*5a6e8488SAndroid Build Coastguard Worker 2132*5a6e8488SAndroid Build Coastguard Worker## Transcendental Functions 2133*5a6e8488SAndroid Build Coastguard Worker 2134*5a6e8488SAndroid Build Coastguard WorkerAll transcendental functions can return slightly inaccurate results, up to 1 ULP 2135*5a6e8488SAndroid Build Coastguard Worker(https://en.wikipedia.org/wiki/Unit_in_the_last_place). This is unavoidable, and 2136*5a6e8488SAndroid Build Coastguard Workerthe article at https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT explains 2137*5a6e8488SAndroid Build Coastguard Workerwhy it is impossible and unnecessary to calculate exact results for the 2138*5a6e8488SAndroid Build Coastguard Workertranscendental functions. 2139*5a6e8488SAndroid Build Coastguard Worker 2140*5a6e8488SAndroid Build Coastguard WorkerBecause of the possible inaccuracy, I recommend that users call those functions 2141*5a6e8488SAndroid Build Coastguard Workerwith the precision (**scale**) set to at least 1 higher than is necessary. If 2142*5a6e8488SAndroid Build Coastguard Workerexact results are *absolutely* required, users can double the precision 2143*5a6e8488SAndroid Build Coastguard Worker(**scale**) and then truncate. 2144*5a6e8488SAndroid Build Coastguard Worker 2145*5a6e8488SAndroid Build Coastguard WorkerThe transcendental functions in the standard math library are: 2146*5a6e8488SAndroid Build Coastguard Worker 2147*5a6e8488SAndroid Build Coastguard Worker* **s(x)** 2148*5a6e8488SAndroid Build Coastguard Worker* **c(x)** 2149*5a6e8488SAndroid Build Coastguard Worker* **a(x)** 2150*5a6e8488SAndroid Build Coastguard Worker* **l(x)** 2151*5a6e8488SAndroid Build Coastguard Worker* **e(x)** 2152*5a6e8488SAndroid Build Coastguard Worker* **j(x, n)** 2153*5a6e8488SAndroid Build Coastguard Worker 2154*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 2155*5a6e8488SAndroid Build Coastguard WorkerThe transcendental functions in the extended math library are: 2156*5a6e8488SAndroid Build Coastguard Worker 2157*5a6e8488SAndroid Build Coastguard Worker* **l2(x)** 2158*5a6e8488SAndroid Build Coastguard Worker* **l10(x)** 2159*5a6e8488SAndroid Build Coastguard Worker* **log(x, b)** 2160*5a6e8488SAndroid Build Coastguard Worker* **pi(p)** 2161*5a6e8488SAndroid Build Coastguard Worker* **t(x)** 2162*5a6e8488SAndroid Build Coastguard Worker* **a2(y, x)** 2163*5a6e8488SAndroid Build Coastguard Worker* **sin(x)** 2164*5a6e8488SAndroid Build Coastguard Worker* **cos(x)** 2165*5a6e8488SAndroid Build Coastguard Worker* **tan(x)** 2166*5a6e8488SAndroid Build Coastguard Worker* **atan(x)** 2167*5a6e8488SAndroid Build Coastguard Worker* **atan2(y, x)** 2168*5a6e8488SAndroid Build Coastguard Worker* **r2d(x)** 2169*5a6e8488SAndroid Build Coastguard Worker* **d2r(x)** 2170*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2171*5a6e8488SAndroid Build Coastguard Worker 2172*5a6e8488SAndroid Build Coastguard Worker# RESET 2173*5a6e8488SAndroid Build Coastguard Worker 2174*5a6e8488SAndroid Build Coastguard WorkerWhen bc(1) encounters an error or a signal that it has a non-default handler 2175*5a6e8488SAndroid Build Coastguard Workerfor, it resets. This means that several things happen. 2176*5a6e8488SAndroid Build Coastguard Worker 2177*5a6e8488SAndroid Build Coastguard WorkerFirst, any functions that are executing are stopped and popped off the stack. 2178*5a6e8488SAndroid Build Coastguard WorkerThe behavior is not unlike that of exceptions in programming languages. Then 2179*5a6e8488SAndroid Build Coastguard Workerthe execution point is set so that any code waiting to execute (after all 2180*5a6e8488SAndroid Build Coastguard Workerfunctions returned) is skipped. 2181*5a6e8488SAndroid Build Coastguard Worker 2182*5a6e8488SAndroid Build Coastguard WorkerThus, when bc(1) resets, it skips any remaining code waiting to be executed. 2183*5a6e8488SAndroid Build Coastguard WorkerThen, if it is interactive mode, and the error was not a fatal error (see the 2184*5a6e8488SAndroid Build Coastguard Worker**EXIT STATUS** section), it asks for more input; otherwise, it exits with the 2185*5a6e8488SAndroid Build Coastguard Workerappropriate return code. 2186*5a6e8488SAndroid Build Coastguard Worker 2187*5a6e8488SAndroid Build Coastguard WorkerNote that this reset behavior is different from the GNU bc(1), which attempts to 2188*5a6e8488SAndroid Build Coastguard Workerstart executing the statement right after the one that caused an error. 2189*5a6e8488SAndroid Build Coastguard Worker 2190*5a6e8488SAndroid Build Coastguard Worker# PERFORMANCE 2191*5a6e8488SAndroid Build Coastguard Worker 2192*5a6e8488SAndroid Build Coastguard WorkerMost bc(1) implementations use **char** types to calculate the value of **1** 2193*5a6e8488SAndroid Build Coastguard Workerdecimal digit at a time, but that can be slow. This bc(1) does something 2194*5a6e8488SAndroid Build Coastguard Workerdifferent. 2195*5a6e8488SAndroid Build Coastguard Worker 2196*5a6e8488SAndroid Build Coastguard WorkerIt uses large integers to calculate more than **1** decimal digit at a time. If 2197*5a6e8488SAndroid Build Coastguard Workerbuilt in a environment where **BC_LONG_BIT** (see the **LIMITS** section) is 2198*5a6e8488SAndroid Build Coastguard Worker**64**, then each integer has **9** decimal digits. If built in an environment 2199*5a6e8488SAndroid Build Coastguard Workerwhere **BC_LONG_BIT** is **32** then each integer has **4** decimal digits. This 2200*5a6e8488SAndroid Build Coastguard Workervalue (the number of decimal digits per large integer) is called 2201*5a6e8488SAndroid Build Coastguard Worker**BC_BASE_DIGS**. 2202*5a6e8488SAndroid Build Coastguard Worker 2203*5a6e8488SAndroid Build Coastguard WorkerThe actual values of **BC_LONG_BIT** and **BC_BASE_DIGS** can be queried with 2204*5a6e8488SAndroid Build Coastguard Workerthe **limits** statement. 2205*5a6e8488SAndroid Build Coastguard Worker 2206*5a6e8488SAndroid Build Coastguard WorkerIn addition, this bc(1) uses an even larger integer for overflow checking. This 2207*5a6e8488SAndroid Build Coastguard Workerinteger type depends on the value of **BC_LONG_BIT**, but is always at least 2208*5a6e8488SAndroid Build Coastguard Workertwice as large as the integer type used to store digits. 2209*5a6e8488SAndroid Build Coastguard Worker 2210*5a6e8488SAndroid Build Coastguard Worker# LIMITS 2211*5a6e8488SAndroid Build Coastguard Worker 2212*5a6e8488SAndroid Build Coastguard WorkerThe following are the limits on bc(1): 2213*5a6e8488SAndroid Build Coastguard Worker 2214*5a6e8488SAndroid Build Coastguard Worker**BC_LONG_BIT** 2215*5a6e8488SAndroid Build Coastguard Worker 2216*5a6e8488SAndroid Build Coastguard Worker: The number of bits in the **long** type in the environment where bc(1) was 2217*5a6e8488SAndroid Build Coastguard Worker built. This determines how many decimal digits can be stored in a single 2218*5a6e8488SAndroid Build Coastguard Worker large integer (see the **PERFORMANCE** section). 2219*5a6e8488SAndroid Build Coastguard Worker 2220*5a6e8488SAndroid Build Coastguard Worker**BC_BASE_DIGS** 2221*5a6e8488SAndroid Build Coastguard Worker 2222*5a6e8488SAndroid Build Coastguard Worker: The number of decimal digits per large integer (see the **PERFORMANCE** 2223*5a6e8488SAndroid Build Coastguard Worker section). Depends on **BC_LONG_BIT**. 2224*5a6e8488SAndroid Build Coastguard Worker 2225*5a6e8488SAndroid Build Coastguard Worker**BC_BASE_POW** 2226*5a6e8488SAndroid Build Coastguard Worker 2227*5a6e8488SAndroid Build Coastguard Worker: The max decimal number that each large integer can store (see 2228*5a6e8488SAndroid Build Coastguard Worker **BC_BASE_DIGS**) plus **1**. Depends on **BC_BASE_DIGS**. 2229*5a6e8488SAndroid Build Coastguard Worker 2230*5a6e8488SAndroid Build Coastguard Worker**BC_OVERFLOW_MAX** 2231*5a6e8488SAndroid Build Coastguard Worker 2232*5a6e8488SAndroid Build Coastguard Worker: The max number that the overflow type (see the **PERFORMANCE** section) can 2233*5a6e8488SAndroid Build Coastguard Worker hold. Depends on **BC_LONG_BIT**. 2234*5a6e8488SAndroid Build Coastguard Worker 2235*5a6e8488SAndroid Build Coastguard Worker**BC_BASE_MAX** 2236*5a6e8488SAndroid Build Coastguard Worker 2237*5a6e8488SAndroid Build Coastguard Worker: The maximum output base. Set at **BC_BASE_POW**. 2238*5a6e8488SAndroid Build Coastguard Worker 2239*5a6e8488SAndroid Build Coastguard Worker**BC_DIM_MAX** 2240*5a6e8488SAndroid Build Coastguard Worker 2241*5a6e8488SAndroid Build Coastguard Worker: The maximum size of arrays. Set at **SIZE_MAX-1**. 2242*5a6e8488SAndroid Build Coastguard Worker 2243*5a6e8488SAndroid Build Coastguard Worker**BC_SCALE_MAX** 2244*5a6e8488SAndroid Build Coastguard Worker 2245*5a6e8488SAndroid Build Coastguard Worker: The maximum **scale**. Set at **BC_OVERFLOW_MAX-1**. 2246*5a6e8488SAndroid Build Coastguard Worker 2247*5a6e8488SAndroid Build Coastguard Worker**BC_STRING_MAX** 2248*5a6e8488SAndroid Build Coastguard Worker 2249*5a6e8488SAndroid Build Coastguard Worker: The maximum length of strings. Set at **BC_OVERFLOW_MAX-1**. 2250*5a6e8488SAndroid Build Coastguard Worker 2251*5a6e8488SAndroid Build Coastguard Worker**BC_NAME_MAX** 2252*5a6e8488SAndroid Build Coastguard Worker 2253*5a6e8488SAndroid Build Coastguard Worker: The maximum length of identifiers. Set at **BC_OVERFLOW_MAX-1**. 2254*5a6e8488SAndroid Build Coastguard Worker 2255*5a6e8488SAndroid Build Coastguard Worker**BC_NUM_MAX** 2256*5a6e8488SAndroid Build Coastguard Worker 2257*5a6e8488SAndroid Build Coastguard Worker: The maximum length of a number (in decimal digits), which includes digits 2258*5a6e8488SAndroid Build Coastguard Worker after the decimal point. Set at **BC_OVERFLOW_MAX-1**. 2259*5a6e8488SAndroid Build Coastguard Worker 2260*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 2261*5a6e8488SAndroid Build Coastguard Worker**BC_RAND_MAX** 2262*5a6e8488SAndroid Build Coastguard Worker 2263*5a6e8488SAndroid Build Coastguard Worker: The maximum integer (inclusive) returned by the **rand()** operand. Set at 2264*5a6e8488SAndroid Build Coastguard Worker **2\^BC_LONG_BIT-1**. 2265*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2266*5a6e8488SAndroid Build Coastguard Worker 2267*5a6e8488SAndroid Build Coastguard WorkerExponent 2268*5a6e8488SAndroid Build Coastguard Worker 2269*5a6e8488SAndroid Build Coastguard Worker: The maximum allowable exponent (positive or negative). Set at 2270*5a6e8488SAndroid Build Coastguard Worker **BC_OVERFLOW_MAX**. 2271*5a6e8488SAndroid Build Coastguard Worker 2272*5a6e8488SAndroid Build Coastguard WorkerNumber of vars 2273*5a6e8488SAndroid Build Coastguard Worker 2274*5a6e8488SAndroid Build Coastguard Worker: The maximum number of vars/arrays. Set at **SIZE_MAX-1**. 2275*5a6e8488SAndroid Build Coastguard Worker 2276*5a6e8488SAndroid Build Coastguard WorkerThe actual values can be queried with the **limits** statement. 2277*5a6e8488SAndroid Build Coastguard Worker 2278*5a6e8488SAndroid Build Coastguard WorkerThese limits are meant to be effectively non-existent; the limits are so large 2279*5a6e8488SAndroid Build Coastguard Worker(at least on 64-bit machines) that there should not be any point at which they 2280*5a6e8488SAndroid Build Coastguard Workerbecome a problem. In fact, memory should be exhausted before these limits should 2281*5a6e8488SAndroid Build Coastguard Workerbe hit. 2282*5a6e8488SAndroid Build Coastguard Worker 2283*5a6e8488SAndroid Build Coastguard Worker# ENVIRONMENT VARIABLES 2284*5a6e8488SAndroid Build Coastguard Worker 2285*5a6e8488SAndroid Build Coastguard WorkerAs **non-portable extensions**, bc(1) recognizes the following environment 2286*5a6e8488SAndroid Build Coastguard Workervariables: 2287*5a6e8488SAndroid Build Coastguard Worker 2288*5a6e8488SAndroid Build Coastguard Worker**POSIXLY_CORRECT** 2289*5a6e8488SAndroid Build Coastguard Worker 2290*5a6e8488SAndroid Build Coastguard Worker: If this variable exists (no matter the contents), bc(1) behaves as if 2291*5a6e8488SAndroid Build Coastguard Worker the **-s** option was given. 2292*5a6e8488SAndroid Build Coastguard Worker 2293*5a6e8488SAndroid Build Coastguard Worker**BC_ENV_ARGS** 2294*5a6e8488SAndroid Build Coastguard Worker 2295*5a6e8488SAndroid Build Coastguard Worker: This is another way to give command-line arguments to bc(1). They should be 2296*5a6e8488SAndroid Build Coastguard Worker in the same format as all other command-line arguments. These are always 2297*5a6e8488SAndroid Build Coastguard Worker processed first, so any files given in **BC_ENV_ARGS** will be processed 2298*5a6e8488SAndroid Build Coastguard Worker before arguments and files given on the command-line. This gives the user 2299*5a6e8488SAndroid Build Coastguard Worker the ability to set up "standard" options and files to be used at every 2300*5a6e8488SAndroid Build Coastguard Worker invocation. The most useful thing for such files to contain would be useful 2301*5a6e8488SAndroid Build Coastguard Worker functions that the user might want every time bc(1) runs. 2302*5a6e8488SAndroid Build Coastguard Worker 2303*5a6e8488SAndroid Build Coastguard Worker The code that parses **BC_ENV_ARGS** will correctly handle quoted arguments, 2304*5a6e8488SAndroid Build Coastguard Worker but it does not understand escape sequences. For example, the string 2305*5a6e8488SAndroid Build Coastguard Worker **"/home/gavin/some bc file.bc"** will be correctly parsed, but the string 2306*5a6e8488SAndroid Build Coastguard Worker **"/home/gavin/some \"bc\" file.bc"** will include the backslashes. 2307*5a6e8488SAndroid Build Coastguard Worker 2308*5a6e8488SAndroid Build Coastguard Worker The quote parsing will handle either kind of quotes, **'** or **"**. Thus, 2309*5a6e8488SAndroid Build Coastguard Worker if you have a file with any number of single quotes in the name, you can use 2310*5a6e8488SAndroid Build Coastguard Worker double quotes as the outside quotes, as in **"some 'bc' file.bc"**, and vice 2311*5a6e8488SAndroid Build Coastguard Worker versa if you have a file with double quotes. However, handling a file with 2312*5a6e8488SAndroid Build Coastguard Worker both kinds of quotes in **BC_ENV_ARGS** is not supported due to the 2313*5a6e8488SAndroid Build Coastguard Worker complexity of the parsing, though such files are still supported on the 2314*5a6e8488SAndroid Build Coastguard Worker command-line where the parsing is done by the shell. 2315*5a6e8488SAndroid Build Coastguard Worker 2316*5a6e8488SAndroid Build Coastguard Worker**BC_LINE_LENGTH** 2317*5a6e8488SAndroid Build Coastguard Worker 2318*5a6e8488SAndroid Build Coastguard Worker: If this environment variable exists and contains an integer that is greater 2319*5a6e8488SAndroid Build Coastguard Worker than **1** and is less than **UINT16_MAX** (**2\^16-1**), bc(1) will output 2320*5a6e8488SAndroid Build Coastguard Worker lines to that length, including the backslash (**\\**). The default line 2321*5a6e8488SAndroid Build Coastguard Worker length is **70**. 2322*5a6e8488SAndroid Build Coastguard Worker 2323*5a6e8488SAndroid Build Coastguard Worker The special value of **0** will disable line length checking and print 2324*5a6e8488SAndroid Build Coastguard Worker numbers without regard to line length and without backslashes and newlines. 2325*5a6e8488SAndroid Build Coastguard Worker 2326*5a6e8488SAndroid Build Coastguard Worker**BC_BANNER** 2327*5a6e8488SAndroid Build Coastguard Worker 2328*5a6e8488SAndroid Build Coastguard Worker: If this environment variable exists and contains an integer, then a non-zero 2329*5a6e8488SAndroid Build Coastguard Worker value activates the copyright banner when bc(1) is in interactive mode, 2330*5a6e8488SAndroid Build Coastguard Worker while zero deactivates it. 2331*5a6e8488SAndroid Build Coastguard Worker 2332*5a6e8488SAndroid Build Coastguard Worker If bc(1) is not in interactive mode (see the **INTERACTIVE MODE** section), 2333*5a6e8488SAndroid Build Coastguard Worker then this environment variable has no effect because bc(1) does not print 2334*5a6e8488SAndroid Build Coastguard Worker the banner when not in interactive mode. 2335*5a6e8488SAndroid Build Coastguard Worker 2336*5a6e8488SAndroid Build Coastguard Worker This environment variable overrides the default, which can be queried with 2337*5a6e8488SAndroid Build Coastguard Worker the **-h** or **-\-help** options. 2338*5a6e8488SAndroid Build Coastguard Worker 2339*5a6e8488SAndroid Build Coastguard Worker**BC_SIGINT_RESET** 2340*5a6e8488SAndroid Build Coastguard Worker 2341*5a6e8488SAndroid Build Coastguard Worker: If bc(1) is not in interactive mode (see the **INTERACTIVE MODE** section), 2342*5a6e8488SAndroid Build Coastguard Worker then this environment variable has no effect because bc(1) exits on 2343*5a6e8488SAndroid Build Coastguard Worker **SIGINT** when not in interactive mode. 2344*5a6e8488SAndroid Build Coastguard Worker 2345*5a6e8488SAndroid Build Coastguard Worker However, when bc(1) is in interactive mode, then if this environment 2346*5a6e8488SAndroid Build Coastguard Worker variable exists and contains an integer, a non-zero value makes bc(1) reset 2347*5a6e8488SAndroid Build Coastguard Worker on **SIGINT**, rather than exit, and zero makes bc(1) exit. If this 2348*5a6e8488SAndroid Build Coastguard Worker environment variable exists and is *not* an integer, then bc(1) will exit on 2349*5a6e8488SAndroid Build Coastguard Worker **SIGINT**. 2350*5a6e8488SAndroid Build Coastguard Worker 2351*5a6e8488SAndroid Build Coastguard Worker This environment variable overrides the default, which can be queried with 2352*5a6e8488SAndroid Build Coastguard Worker the **-h** or **-\-help** options. 2353*5a6e8488SAndroid Build Coastguard Worker 2354*5a6e8488SAndroid Build Coastguard Worker**BC_TTY_MODE** 2355*5a6e8488SAndroid Build Coastguard Worker 2356*5a6e8488SAndroid Build Coastguard Worker: If TTY mode is *not* available (see the **TTY MODE** section), then this 2357*5a6e8488SAndroid Build Coastguard Worker environment variable has no effect. 2358*5a6e8488SAndroid Build Coastguard Worker 2359*5a6e8488SAndroid Build Coastguard Worker However, when TTY mode is available, then if this environment variable 2360*5a6e8488SAndroid Build Coastguard Worker exists and contains an integer, then a non-zero value makes bc(1) use TTY 2361*5a6e8488SAndroid Build Coastguard Worker mode, and zero makes bc(1) not use TTY mode. 2362*5a6e8488SAndroid Build Coastguard Worker 2363*5a6e8488SAndroid Build Coastguard Worker This environment variable overrides the default, which can be queried with 2364*5a6e8488SAndroid Build Coastguard Worker the **-h** or **-\-help** options. 2365*5a6e8488SAndroid Build Coastguard Worker 2366*5a6e8488SAndroid Build Coastguard Worker**BC_PROMPT** 2367*5a6e8488SAndroid Build Coastguard Worker 2368*5a6e8488SAndroid Build Coastguard Worker: If TTY mode is *not* available (see the **TTY MODE** section), then this 2369*5a6e8488SAndroid Build Coastguard Worker environment variable has no effect. 2370*5a6e8488SAndroid Build Coastguard Worker 2371*5a6e8488SAndroid Build Coastguard Worker However, when TTY mode is available, then if this environment variable 2372*5a6e8488SAndroid Build Coastguard Worker exists and contains an integer, a non-zero value makes bc(1) use a prompt, 2373*5a6e8488SAndroid Build Coastguard Worker and zero or a non-integer makes bc(1) not use a prompt. If this environment 2374*5a6e8488SAndroid Build Coastguard Worker variable does not exist and **BC_TTY_MODE** does, then the value of the 2375*5a6e8488SAndroid Build Coastguard Worker **BC_TTY_MODE** environment variable is used. 2376*5a6e8488SAndroid Build Coastguard Worker 2377*5a6e8488SAndroid Build Coastguard Worker This environment variable and the **BC_TTY_MODE** environment variable 2378*5a6e8488SAndroid Build Coastguard Worker override the default, which can be queried with the **-h** or **-\-help** 2379*5a6e8488SAndroid Build Coastguard Worker options. 2380*5a6e8488SAndroid Build Coastguard Worker 2381*5a6e8488SAndroid Build Coastguard Worker**BC_EXPR_EXIT** 2382*5a6e8488SAndroid Build Coastguard Worker 2383*5a6e8488SAndroid Build Coastguard Worker: If any expressions or expression files are given on the command-line with 2384*5a6e8488SAndroid Build Coastguard Worker **-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment 2385*5a6e8488SAndroid Build Coastguard Worker variable exists and contains an integer, a non-zero value makes bc(1) exit 2386*5a6e8488SAndroid Build Coastguard Worker after executing the expressions and expression files, and a zero value makes 2387*5a6e8488SAndroid Build Coastguard Worker bc(1) not exit. 2388*5a6e8488SAndroid Build Coastguard Worker 2389*5a6e8488SAndroid Build Coastguard Worker This environment variable overrides the default, which can be queried with 2390*5a6e8488SAndroid Build Coastguard Worker the **-h** or **-\-help** options. 2391*5a6e8488SAndroid Build Coastguard Worker 2392*5a6e8488SAndroid Build Coastguard Worker**BC_DIGIT_CLAMP** 2393*5a6e8488SAndroid Build Coastguard Worker 2394*5a6e8488SAndroid Build Coastguard Worker: When parsing numbers and if this environment variable exists and contains an 2395*5a6e8488SAndroid Build Coastguard Worker integer, a non-zero value makes bc(1) clamp digits that are greater than or 2396*5a6e8488SAndroid Build Coastguard Worker equal to the current **ibase** so that all such digits are considered equal 2397*5a6e8488SAndroid Build Coastguard Worker to the **ibase** minus 1, and a zero value disables such clamping so that 2398*5a6e8488SAndroid Build Coastguard Worker those digits are always equal to their value, which is multiplied by the 2399*5a6e8488SAndroid Build Coastguard Worker power of the **ibase**. 2400*5a6e8488SAndroid Build Coastguard Worker 2401*5a6e8488SAndroid Build Coastguard Worker This never applies to single-digit numbers, as per the standard (see the 2402*5a6e8488SAndroid Build Coastguard Worker **STANDARDS** section). 2403*5a6e8488SAndroid Build Coastguard Worker 2404*5a6e8488SAndroid Build Coastguard Worker This environment variable overrides the default, which can be queried with 2405*5a6e8488SAndroid Build Coastguard Worker the **-h** or **-\-help** options. 2406*5a6e8488SAndroid Build Coastguard Worker 2407*5a6e8488SAndroid Build Coastguard Worker# EXIT STATUS 2408*5a6e8488SAndroid Build Coastguard Worker 2409*5a6e8488SAndroid Build Coastguard Workerbc(1) returns the following exit statuses: 2410*5a6e8488SAndroid Build Coastguard Worker 2411*5a6e8488SAndroid Build Coastguard Worker**0** 2412*5a6e8488SAndroid Build Coastguard Worker 2413*5a6e8488SAndroid Build Coastguard Worker: No error. 2414*5a6e8488SAndroid Build Coastguard Worker 2415*5a6e8488SAndroid Build Coastguard Worker**1** 2416*5a6e8488SAndroid Build Coastguard Worker 2417*5a6e8488SAndroid Build Coastguard Worker: A math error occurred. This follows standard practice of using **1** for 2418*5a6e8488SAndroid Build Coastguard Worker expected errors, since math errors will happen in the process of normal 2419*5a6e8488SAndroid Build Coastguard Worker execution. 2420*5a6e8488SAndroid Build Coastguard Worker 2421*5a6e8488SAndroid Build Coastguard Worker Math errors include divide by **0**, taking the square root of a negative 2422*5a6e8488SAndroid Build Coastguard Worker{{ A H N HN }} 2423*5a6e8488SAndroid Build Coastguard Worker number, using a negative number as a bound for the pseudo-random number 2424*5a6e8488SAndroid Build Coastguard Worker generator, attempting to convert a negative number to a hardware integer, 2425*5a6e8488SAndroid Build Coastguard Worker overflow when converting a number to a hardware integer, overflow when 2426*5a6e8488SAndroid Build Coastguard Worker calculating the size of a number, and attempting to use a non-integer where 2427*5a6e8488SAndroid Build Coastguard Worker an integer is required. 2428*5a6e8488SAndroid Build Coastguard Worker 2429*5a6e8488SAndroid Build Coastguard Worker Converting to a hardware integer happens for the second operand of the power 2430*5a6e8488SAndroid Build Coastguard Worker (**\^**), places (**\@**), left shift (**\<\<**), and right shift (**\>\>**) 2431*5a6e8488SAndroid Build Coastguard Worker operators and their corresponding assignment operators. 2432*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2433*5a6e8488SAndroid Build Coastguard Worker{{ E EH EN EHN }} 2434*5a6e8488SAndroid Build Coastguard Worker number, attempting to convert a negative number to a hardware integer, 2435*5a6e8488SAndroid Build Coastguard Worker overflow when converting a number to a hardware integer, overflow when 2436*5a6e8488SAndroid Build Coastguard Worker calculating the size of a number, and attempting to use a non-integer where 2437*5a6e8488SAndroid Build Coastguard Worker an integer is required. 2438*5a6e8488SAndroid Build Coastguard Worker 2439*5a6e8488SAndroid Build Coastguard Worker Converting to a hardware integer happens for the second operand of the power 2440*5a6e8488SAndroid Build Coastguard Worker (**\^**) operator and the corresponding assignment operator. 2441*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2442*5a6e8488SAndroid Build Coastguard Worker 2443*5a6e8488SAndroid Build Coastguard Worker**2** 2444*5a6e8488SAndroid Build Coastguard Worker 2445*5a6e8488SAndroid Build Coastguard Worker: A parse error occurred. 2446*5a6e8488SAndroid Build Coastguard Worker 2447*5a6e8488SAndroid Build Coastguard Worker Parse errors include unexpected **EOF**, using an invalid character, failing 2448*5a6e8488SAndroid Build Coastguard Worker to find the end of a string or comment, using a token where it is invalid, 2449*5a6e8488SAndroid Build Coastguard Worker giving an invalid expression, giving an invalid print statement, giving an 2450*5a6e8488SAndroid Build Coastguard Worker invalid function definition, attempting to assign to an expression that is 2451*5a6e8488SAndroid Build Coastguard Worker not a named expression (see the *Named Expressions* subsection of the 2452*5a6e8488SAndroid Build Coastguard Worker **SYNTAX** section), giving an invalid **auto** list, having a duplicate 2453*5a6e8488SAndroid Build Coastguard Worker **auto**/function parameter, failing to find the end of a code block, 2454*5a6e8488SAndroid Build Coastguard Worker attempting to return a value from a **void** function, attempting to use a 2455*5a6e8488SAndroid Build Coastguard Worker variable as a reference, and using any extensions when the option **-s** or 2456*5a6e8488SAndroid Build Coastguard Worker any equivalents were given. 2457*5a6e8488SAndroid Build Coastguard Worker 2458*5a6e8488SAndroid Build Coastguard Worker**3** 2459*5a6e8488SAndroid Build Coastguard Worker 2460*5a6e8488SAndroid Build Coastguard Worker: A runtime error occurred. 2461*5a6e8488SAndroid Build Coastguard Worker 2462*5a6e8488SAndroid Build Coastguard Worker Runtime errors include assigning an invalid number to any global (**ibase**, 2463*5a6e8488SAndroid Build Coastguard Worker **obase**, or **scale**), giving a bad expression to a **read()** call, 2464*5a6e8488SAndroid Build Coastguard Worker calling **read()** inside of a **read()** call, type errors, passing the 2465*5a6e8488SAndroid Build Coastguard Worker wrong number of arguments to functions, attempting to call an undefined 2466*5a6e8488SAndroid Build Coastguard Worker function, and attempting to use a **void** function call as a value in an 2467*5a6e8488SAndroid Build Coastguard Worker expression. 2468*5a6e8488SAndroid Build Coastguard Worker 2469*5a6e8488SAndroid Build Coastguard Worker**4** 2470*5a6e8488SAndroid Build Coastguard Worker 2471*5a6e8488SAndroid Build Coastguard Worker: A fatal error occurred. 2472*5a6e8488SAndroid Build Coastguard Worker 2473*5a6e8488SAndroid Build Coastguard Worker Fatal errors include memory allocation errors, I/O errors, failing to open 2474*5a6e8488SAndroid Build Coastguard Worker files, attempting to use files that do not have only ASCII characters (bc(1) 2475*5a6e8488SAndroid Build Coastguard Worker only accepts ASCII characters), attempting to open a directory as a file, 2476*5a6e8488SAndroid Build Coastguard Worker and giving invalid command-line options. 2477*5a6e8488SAndroid Build Coastguard Worker 2478*5a6e8488SAndroid Build Coastguard WorkerThe exit status **4** is special; when a fatal error occurs, bc(1) always exits 2479*5a6e8488SAndroid Build Coastguard Workerand returns **4**, no matter what mode bc(1) is in. 2480*5a6e8488SAndroid Build Coastguard Worker 2481*5a6e8488SAndroid Build Coastguard WorkerThe other statuses will only be returned when bc(1) is not in interactive mode 2482*5a6e8488SAndroid Build Coastguard Worker(see the **INTERACTIVE MODE** section), since bc(1) resets its state (see the 2483*5a6e8488SAndroid Build Coastguard Worker**RESET** section) and accepts more input when one of those errors occurs in 2484*5a6e8488SAndroid Build Coastguard Workerinteractive mode. This is also the case when interactive mode is forced by the 2485*5a6e8488SAndroid Build Coastguard Worker**-i** flag or **-\-interactive** option. 2486*5a6e8488SAndroid Build Coastguard Worker 2487*5a6e8488SAndroid Build Coastguard WorkerThese exit statuses allow bc(1) to be used in shell scripting with error 2488*5a6e8488SAndroid Build Coastguard Workerchecking, and its normal behavior can be forced by using the **-i** flag or 2489*5a6e8488SAndroid Build Coastguard Worker**-\-interactive** option. 2490*5a6e8488SAndroid Build Coastguard Worker 2491*5a6e8488SAndroid Build Coastguard Worker# INTERACTIVE MODE 2492*5a6e8488SAndroid Build Coastguard Worker 2493*5a6e8488SAndroid Build Coastguard WorkerPer the standard (see the **STANDARDS** section), bc(1) has an interactive mode 2494*5a6e8488SAndroid Build Coastguard Workerand a non-interactive mode. Interactive mode is turned on automatically when 2495*5a6e8488SAndroid Build Coastguard Workerboth **stdin** and **stdout** are hooked to a terminal, but the **-i** flag and 2496*5a6e8488SAndroid Build Coastguard Worker**-\-interactive** option can turn it on in other situations. 2497*5a6e8488SAndroid Build Coastguard Worker 2498*5a6e8488SAndroid Build Coastguard WorkerIn interactive mode, bc(1) attempts to recover from errors (see the **RESET** 2499*5a6e8488SAndroid Build Coastguard Workersection), and in normal execution, flushes **stdout** as soon as execution is 2500*5a6e8488SAndroid Build Coastguard Workerdone for the current input. bc(1) may also reset on **SIGINT** instead of exit, 2501*5a6e8488SAndroid Build Coastguard Workerdepending on the contents of, or default for, the **BC_SIGINT_RESET** 2502*5a6e8488SAndroid Build Coastguard Workerenvironment variable (see the **ENVIRONMENT VARIABLES** section). 2503*5a6e8488SAndroid Build Coastguard Worker 2504*5a6e8488SAndroid Build Coastguard Worker# TTY MODE 2505*5a6e8488SAndroid Build Coastguard Worker 2506*5a6e8488SAndroid Build Coastguard WorkerIf **stdin**, **stdout**, and **stderr** are all connected to a TTY, then "TTY 2507*5a6e8488SAndroid Build Coastguard Workermode" is considered to be available, and thus, bc(1) can turn on TTY mode, 2508*5a6e8488SAndroid Build Coastguard Workersubject to some settings. 2509*5a6e8488SAndroid Build Coastguard Worker 2510*5a6e8488SAndroid Build Coastguard WorkerIf there is the environment variable **BC_TTY_MODE** in the environment (see the 2511*5a6e8488SAndroid Build Coastguard Worker**ENVIRONMENT VARIABLES** section), then if that environment variable contains a 2512*5a6e8488SAndroid Build Coastguard Workernon-zero integer, bc(1) will turn on TTY mode when **stdin**, **stdout**, and 2513*5a6e8488SAndroid Build Coastguard Worker**stderr** are all connected to a TTY. If the **BC_TTY_MODE** environment 2514*5a6e8488SAndroid Build Coastguard Workervariable exists but is *not* a non-zero integer, then bc(1) will not turn TTY 2515*5a6e8488SAndroid Build Coastguard Workermode on. 2516*5a6e8488SAndroid Build Coastguard Worker 2517*5a6e8488SAndroid Build Coastguard WorkerIf the environment variable **BC_TTY_MODE** does *not* exist, the default 2518*5a6e8488SAndroid Build Coastguard Workersetting is used. The default setting can be queried with the **-h** or 2519*5a6e8488SAndroid Build Coastguard Worker**-\-help** options. 2520*5a6e8488SAndroid Build Coastguard Worker 2521*5a6e8488SAndroid Build Coastguard WorkerTTY mode is different from interactive mode because interactive mode is required 2522*5a6e8488SAndroid Build Coastguard Workerin the bc(1) standard (see the **STANDARDS** section), and interactive mode 2523*5a6e8488SAndroid Build Coastguard Workerrequires only **stdin** and **stdout** to be connected to a terminal. 2524*5a6e8488SAndroid Build Coastguard Worker 2525*5a6e8488SAndroid Build Coastguard Worker{{ A E N EN }} 2526*5a6e8488SAndroid Build Coastguard Worker## Command-Line History 2527*5a6e8488SAndroid Build Coastguard Worker 2528*5a6e8488SAndroid Build Coastguard WorkerCommand-line history is only enabled if TTY mode is, i.e., that **stdin**, 2529*5a6e8488SAndroid Build Coastguard Worker**stdout**, and **stderr** are connected to a TTY and the **BC_TTY_MODE** 2530*5a6e8488SAndroid Build Coastguard Workerenvironment variable (see the **ENVIRONMENT VARIABLES** section) and its default 2531*5a6e8488SAndroid Build Coastguard Workerdo not disable TTY mode. See the **COMMAND LINE HISTORY** section for more 2532*5a6e8488SAndroid Build Coastguard Workerinformation. 2533*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2534*5a6e8488SAndroid Build Coastguard Worker 2535*5a6e8488SAndroid Build Coastguard Worker## Prompt 2536*5a6e8488SAndroid Build Coastguard Worker 2537*5a6e8488SAndroid Build Coastguard WorkerIf TTY mode is available, then a prompt can be enabled. Like TTY mode itself, it 2538*5a6e8488SAndroid Build Coastguard Workercan be turned on or off with an environment variable: **BC_PROMPT** (see the 2539*5a6e8488SAndroid Build Coastguard Worker**ENVIRONMENT VARIABLES** section). 2540*5a6e8488SAndroid Build Coastguard Worker 2541*5a6e8488SAndroid Build Coastguard WorkerIf the environment variable **BC_PROMPT** exists and is a non-zero integer, then 2542*5a6e8488SAndroid Build Coastguard Workerthe prompt is turned on when **stdin**, **stdout**, and **stderr** are connected 2543*5a6e8488SAndroid Build Coastguard Workerto a TTY and the **-P** and **-\-no-prompt** options were not used. The read 2544*5a6e8488SAndroid Build Coastguard Workerprompt will be turned on under the same conditions, except that the **-R** and 2545*5a6e8488SAndroid Build Coastguard Worker**-\-no-read-prompt** options must also not be used. 2546*5a6e8488SAndroid Build Coastguard Worker 2547*5a6e8488SAndroid Build Coastguard WorkerHowever, if **BC_PROMPT** does not exist, the prompt can be enabled or disabled 2548*5a6e8488SAndroid Build Coastguard Workerwith the **BC_TTY_MODE** environment variable, the **-P** and **-\-no-prompt** 2549*5a6e8488SAndroid Build Coastguard Workeroptions, and the **-R** and **-\-no-read-prompt** options. See the **ENVIRONMENT 2550*5a6e8488SAndroid Build Coastguard WorkerVARIABLES** and **OPTIONS** sections for more details. 2551*5a6e8488SAndroid Build Coastguard Worker 2552*5a6e8488SAndroid Build Coastguard Worker# SIGNAL HANDLING 2553*5a6e8488SAndroid Build Coastguard Worker 2554*5a6e8488SAndroid Build Coastguard WorkerSending a **SIGINT** will cause bc(1) to do one of two things. 2555*5a6e8488SAndroid Build Coastguard Worker 2556*5a6e8488SAndroid Build Coastguard WorkerIf bc(1) is not in interactive mode (see the **INTERACTIVE MODE** section), or 2557*5a6e8488SAndroid Build Coastguard Workerthe **BC_SIGINT_RESET** environment variable (see the **ENVIRONMENT VARIABLES** 2558*5a6e8488SAndroid Build Coastguard Workersection), or its default, is either not an integer or it is zero, bc(1) will 2559*5a6e8488SAndroid Build Coastguard Workerexit. 2560*5a6e8488SAndroid Build Coastguard Worker 2561*5a6e8488SAndroid Build Coastguard WorkerHowever, if bc(1) is in interactive mode, and the **BC_SIGINT_RESET** or its 2562*5a6e8488SAndroid Build Coastguard Workerdefault is an integer and non-zero, then bc(1) will stop executing the current 2563*5a6e8488SAndroid Build Coastguard Workerinput and reset (see the **RESET** section) upon receiving a **SIGINT**. 2564*5a6e8488SAndroid Build Coastguard Worker 2565*5a6e8488SAndroid Build Coastguard WorkerNote that "current input" can mean one of two things. If bc(1) is processing 2566*5a6e8488SAndroid Build Coastguard Workerinput from **stdin** in interactive mode, it will ask for more input. If bc(1) 2567*5a6e8488SAndroid Build Coastguard Workeris processing input from a file in interactive mode, it will stop processing the 2568*5a6e8488SAndroid Build Coastguard Workerfile and start processing the next file, if one exists, or ask for input from 2569*5a6e8488SAndroid Build Coastguard Worker**stdin** if no other file exists. 2570*5a6e8488SAndroid Build Coastguard Worker 2571*5a6e8488SAndroid Build Coastguard WorkerThis means that if a **SIGINT** is sent to bc(1) as it is executing a file, it 2572*5a6e8488SAndroid Build Coastguard Workercan seem as though bc(1) did not respond to the signal since it will immediately 2573*5a6e8488SAndroid Build Coastguard Workerstart executing the next file. This is by design; most files that users execute 2574*5a6e8488SAndroid Build Coastguard Workerwhen interacting with bc(1) have function definitions, which are quick to parse. 2575*5a6e8488SAndroid Build Coastguard WorkerIf a file takes a long time to execute, there may be a bug in that file. The 2576*5a6e8488SAndroid Build Coastguard Workerrest of the files could still be executed without problem, allowing the user to 2577*5a6e8488SAndroid Build Coastguard Workercontinue. 2578*5a6e8488SAndroid Build Coastguard Worker 2579*5a6e8488SAndroid Build Coastguard Worker**SIGTERM** and **SIGQUIT** cause bc(1) to clean up and exit, and it uses the 2580*5a6e8488SAndroid Build Coastguard Worker{{ A E N EN }} 2581*5a6e8488SAndroid Build Coastguard Workerdefault handler for all other signals. The one exception is **SIGHUP**; in that 2582*5a6e8488SAndroid Build Coastguard Workercase, and only when bc(1) is in TTY mode (see the **TTY MODE** section), a 2583*5a6e8488SAndroid Build Coastguard Worker**SIGHUP** will cause bc(1) to clean up and exit. 2584*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2585*5a6e8488SAndroid Build Coastguard Worker{{ H EH HN EHN }} 2586*5a6e8488SAndroid Build Coastguard Workerdefault handler for all other signals. 2587*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2588*5a6e8488SAndroid Build Coastguard Worker 2589*5a6e8488SAndroid Build Coastguard Worker{{ A E N EN }} 2590*5a6e8488SAndroid Build Coastguard Worker# COMMAND LINE HISTORY 2591*5a6e8488SAndroid Build Coastguard Worker 2592*5a6e8488SAndroid Build Coastguard Workerbc(1) supports interactive command-line editing. 2593*5a6e8488SAndroid Build Coastguard Worker 2594*5a6e8488SAndroid Build Coastguard WorkerIf bc(1) can be in TTY mode (see the **TTY MODE** section), history can be 2595*5a6e8488SAndroid Build Coastguard Workerenabled. This means that command-line history can only be enabled when 2596*5a6e8488SAndroid Build Coastguard Worker**stdin**, **stdout**, and **stderr** are all connected to a TTY. 2597*5a6e8488SAndroid Build Coastguard Worker 2598*5a6e8488SAndroid Build Coastguard WorkerLike TTY mode itself, it can be turned on or off with the environment variable 2599*5a6e8488SAndroid Build Coastguard Worker**BC_TTY_MODE** (see the **ENVIRONMENT VARIABLES** section). 2600*5a6e8488SAndroid Build Coastguard Worker 2601*5a6e8488SAndroid Build Coastguard WorkerIf history is enabled, previous lines can be recalled and edited with the arrow 2602*5a6e8488SAndroid Build Coastguard Workerkeys. 2603*5a6e8488SAndroid Build Coastguard Worker 2604*5a6e8488SAndroid Build Coastguard Worker**Note**: tabs are converted to 8 spaces. 2605*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2606*5a6e8488SAndroid Build Coastguard Worker 2607*5a6e8488SAndroid Build Coastguard Worker{{ A E H EH }} 2608*5a6e8488SAndroid Build Coastguard Worker# LOCALES 2609*5a6e8488SAndroid Build Coastguard Worker 2610*5a6e8488SAndroid Build Coastguard WorkerThis bc(1) ships with support for adding error messages for different locales 2611*5a6e8488SAndroid Build Coastguard Workerand thus, supports **LC_MESSAGES**. 2612*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2613*5a6e8488SAndroid Build Coastguard Worker 2614*5a6e8488SAndroid Build Coastguard Worker# SEE ALSO 2615*5a6e8488SAndroid Build Coastguard Worker 2616*5a6e8488SAndroid Build Coastguard Workerdc(1) 2617*5a6e8488SAndroid Build Coastguard Worker 2618*5a6e8488SAndroid Build Coastguard Worker# STANDARDS 2619*5a6e8488SAndroid Build Coastguard Worker 2620*5a6e8488SAndroid Build Coastguard Workerbc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification 2621*5a6e8488SAndroid Build Coastguard Workerat https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html . The 2622*5a6e8488SAndroid Build Coastguard Workerflags **-efghiqsvVw**, all long options, and the extensions noted above are 2623*5a6e8488SAndroid Build Coastguard Workerextensions to that specification. 2624*5a6e8488SAndroid Build Coastguard Worker 2625*5a6e8488SAndroid Build Coastguard WorkerIn addition, the behavior of the **quit** implements an interpretation of that 2626*5a6e8488SAndroid Build Coastguard Workerspecification that is different from all known implementations. For more 2627*5a6e8488SAndroid Build Coastguard Workerinformation see the **Statements** subsection of the **SYNTAX** section. 2628*5a6e8488SAndroid Build Coastguard Worker 2629*5a6e8488SAndroid Build Coastguard WorkerNote that the specification explicitly says that bc(1) only accepts numbers that 2630*5a6e8488SAndroid Build Coastguard Workeruse a period (**.**) as a radix point, regardless of the value of 2631*5a6e8488SAndroid Build Coastguard Worker**LC_NUMERIC**. 2632*5a6e8488SAndroid Build Coastguard Worker 2633*5a6e8488SAndroid Build Coastguard Worker{{ A E H EH }} 2634*5a6e8488SAndroid Build Coastguard WorkerThis bc(1) supports error messages for different locales, and thus, it supports 2635*5a6e8488SAndroid Build Coastguard Worker**LC_MESSAGES**. 2636*5a6e8488SAndroid Build Coastguard Worker{{ end }} 2637*5a6e8488SAndroid Build Coastguard Worker 2638*5a6e8488SAndroid Build Coastguard Worker# BUGS 2639*5a6e8488SAndroid Build Coastguard Worker 2640*5a6e8488SAndroid Build Coastguard WorkerBefore version **6.1.0**, this bc(1) had incorrect behavior for the **quit** 2641*5a6e8488SAndroid Build Coastguard Workerstatement. 2642*5a6e8488SAndroid Build Coastguard Worker 2643*5a6e8488SAndroid Build Coastguard WorkerNo other bugs are known. Report bugs at https://git.gavinhoward.com/gavin/bc . 2644*5a6e8488SAndroid Build Coastguard Worker 2645*5a6e8488SAndroid Build Coastguard Worker# AUTHORS 2646*5a6e8488SAndroid Build Coastguard Worker 2647*5a6e8488SAndroid Build Coastguard WorkerGavin D. Howard <[email protected]> and contributors. 2648