Lines Matching +full:non +full:- +full:negative
1 <!---
3 SPDX-License-Identifier: BSD-2-Clause
5 Copyright (c) 2018-2024 Gavin D. Howard and contributors.
29 -->
33 bc - arbitrary-precision decimal arithmetic language and calculator
37 …-cCghilPqRsvVw**] [**-\-digit-clamp**] [**-\-no-digit-clamp**] [**-\-global-stacks**] [**-\-help**…
43 precision decimal arithmetic and is somewhat C-like, but there are differences.
49 This bc(1) is a drop-in replacement for *any* bc(1), including (and
56 command-line option **-r** *keyword*, where *keyword* is the keyword that is
66 **-C**, **-\-no-digit-clamp**
75 If this and/or the **-c** or **-\-digit-clamp** options are given multiple
80 with the **-h** or **-\-help** options.
82 This is a **non-portable extension**.
84 **-c**, **-\-digit-clamp**
94 If this and/or the **-C** or **-\-no-digit-clamp** options are given
99 with the **-h** or **-\-help** options.
101 This is a **non-portable extension**.
103 **-E** *seed*, **-\-seed**=*seed*
110 This is a **non-portable extension**.
112 **-e** *expr*, **-\-expression**=*expr*
115 order. If files are given as well (see the **-f** and **-\-file** options),
120 If this option is given on the command-line (i.e., not in **BC_ENV_ARGS**,
122 expressions and files, bc(1) will exit, unless **-** (**stdin**) was given
123 as an argument at least once to **-f** or **-\-file**, whether on the
124 command-line or in **BC_ENV_ARGS**. However, if any other **-e**,
125 **-\-expression**, **-f**, or **-\-file** arguments are given after **-f-**
128 This is a **non-portable extension**.
130 **-f** *file*, **-\-file**=*file*
133 through **stdin**. If expressions are also given (see the **-e** and
134 **-\-expression** options), the expressions are evaluated in the order
137 If this option is given on the command-line (i.e., not in **BC_ENV_ARGS**,
139 expressions and files, bc(1) will exit, unless **-** (**stdin**) was given
140 as an argument at least once to **-f** or **-\-file**. However, if any other
141 **-e**, **-\-expression**, **-f**, or **-\-file** arguments are given after
142 **-f-** or equivalent is given, bc(1) will give a fatal error and exit.
144 This is a **non-portable extension**.
146 **-g**, **-\-global-stacks**
186 alias d2o="bc -e ibase=A -e obase=8"
187 alias h2b="bc -e ibase=G -e obase=2"
196 pseudo-random numbers that they see will not be the same sequence of
197 pseudo-random numbers that any parent sees. This is only the case once
200 If a function desires to not affect the sequence of pseudo-random numbers
210 If **-s**, **-w**, or any equivalents are used, this option is ignored.
212 This is a **non-portable extension**.
214 **-h**, **-\-help**
218 **-I** *ibase*, **-\-ibase**=*ibase*
225 This is a **non-portable extension**.
227 **-i**, **-\-interactive**
231 This is a **non-portable extension**.
233 **-L**, **-\-no-line-length**
239 This is a **non-portable extension**.
241 **-l**, **-\-mathlib**
249 **-O** *obase*, **-\-obase**=*obase*
256 This is a **non-portable extension**.
258 **-P**, **-\-no-prompt**
269 This is a **non-portable extension**.
271 **-q**, **-\-quiet**
274 (https://www.gnu.org/software/bc/); it is a no-op. Without this option, GNU
276 if one or more of the **-v**, **-V**, or **-\-version** options are given
277 unless the **BC_BANNER** environment variable is set and contains a non-zero
282 This is a **non-portable extension**.
284 **-R**, **-\-no-read-prompt**
294 only used when the **read()** built-in function is called.
300 This is a **non-portable extension**.
302 **-r** *keyword*, **-\-redefine**=*keyword*
341 **-S** *scale*, **-\-scale**=*scale*
348 This is a **non-portable extension**.
350 **-s**, **-\-standard**
355 This is a **non-portable extension**.
357 **-v**, **-V**, **-\-version**
361 This is a **non-portable extension**.
363 **-w**, **-\-warn**
365 : Like **-s** and **-\-standard**, except that warnings (and not errors) are
366 printed for non-standard extensions and execution continues normally.
368 This is a **non-portable extension**.
370 **-z**, **-\-leading-zeroes**
372 : Makes bc(1) print all numbers greater than **-1** and less than **1**, and
379 This is a **non-portable extension**.
381 All long options are **non-portable extensions**.
385 If no files or expressions are given by the **-f**, **-\-file**, **-e**, or
386 **-\-expression** options, then bc(1) reads from **stdin**.
401 Any non-error output is written to **stdout**. In addition, if history (see the
407 **stdout** is closed, as in **bc <file> >&-**, it will quit with an error. This
421 **stderr** is closed, as in **bc <file> 2>&-**, it will quit with an error. This
431 The syntax for bc(1) programs is mostly C-like, with some differences. This
440 number (up to **BC_NAME_MAX-1**) of lowercase letters (**a-z**), digits
441 (**0-9**), and underscores (**\_**). The regex is **\[a-z\]\[a-z0-9\_\]\***.
443 **non-portable extension**.
447 **ibase** is initially **10**. If the **-s** (**-\-standard**) and **-w**
448 (**-\-warn**) flags were not given on the command line, the max allowable value
451 bc(1) programs with the **maxibase()** built-in function.
456 can be queried in bc(1) programs with the **maxobase()** built-in function. The
461 Outputting in scientific and engineering notations are **non-portable
467 **0**. **scale** cannot be negative. The max allowable value for **scale** is
469 built-in function.
488 **non-portable extensions**.
498 is a **non-portable extension**.
512 Numbers 6 and 7 are **non-portable extensions**.
514 The meaning of **seed** is dependent on the current pseudo-random number
520 pseudo-random number generator is guaranteed to produce the same sequence of
521 pseudo-random numbers as it did when the **seed** value was previously used.
526 produce the same sequence of pseudo-random numbers. This means that certain
527 values assigned to **seed** will *not* produce unique sequences of pseudo-random
530 parameter passed to **irand(E)** is **0**, **1**, or negative.
551 4. **sqrt(E)**: The square root of **E**. **E** must be non-negative.
554 string is returned. Passing a string to **length(E)** is a **non-portable
557 **non-portable extension**.
559 8. **abs(E)**: The absolute value of **E**. This is a **non-portable
562 string. This is a **non-portable extension**.
564 number. This is a **non-portable extension**.
567 three values must be integers. The second argument must be non-negative. The
568 third argument must be non-zero. This is a **non-portable extension**.
571 divisor, which must be non-zero. The return value is the quotient, and the
573 This is a **non-portable extension**.
576 and returns that number as a one-character string. This is a **non-portable
580 by the argument. This allows creating multi-character strings and storing
581 them. This is a **non-portable extension**.
583 a non-**void** function (see the *Void Functions* subsection of the
590 **non-portable extension**.
591 16. **maxibase()**: The max allowable **ibase**. This is a **non-portable
593 17. **maxobase()**: The max allowable **obase**. This is a **non-portable
595 18. **maxscale()**: The max allowable **scale**. This is a **non-portable
598 **ENVIRONMENT VARIABLES** section). This is a **non-portable extension**.
599 20. **global_stacks()**: **0** if global stacks are not enabled with the **-g**
600 or **-\-global-stacks** options, non-zero otherwise. See the **OPTIONS**
601 section. This is a **non-portable extension**.
602 21. **leading_zero()**: **0** if leading zeroes are not enabled with the **-z**
603 or **--leading-zeroes** options, non-zero otherwise. See the **OPTIONS**
604 section. This is a **non-portable extension**.
605 22. **rand()**: A pseudo-random integer between **0** (inclusive) and
607 **seed**. This is a **non-portable extension**.
608 23. **irand(E)**: A pseudo-random integer between **0** (inclusive) and the
609 value of **E** (exclusive). If **E** is negative or is a non-integer
613 pseudo-random integers, multiplying them by appropriate powers of
618 **non-portable extension**.
620 **non-portable extension**.
623 unbiased as possible, subject to the limitations of the pseudo-random number
626 **Note**: The values returned by the pseudo-random number generator with
628 This is a consequence of using a seeded pseudo-random number generator. However,
630 means that the pseudo-random values from bc(1) should only be used where a
631 reproducible stream of pseudo-random numbers is *ESSENTIAL*. In any other case,
632 use a non-seeded pseudo-random number generator.
643 behavior depends on the existence of the **-c**/**-\-digit-clamp** or
644 **-C**/**-\-no-digit-clamp** options (see the **OPTIONS** section), the
647 the **-h**/**-\-help** option.
662 There is one exception to clamping: single-character numbers (i.e., **A**
676 Negative exponents are also allowed, so **4.2890e-3** is equal to **0.0042890**.
678 Using scientific notation is an error or warning if the **-s** or **-w**,
679 respectively, command-line options (or equivalents) are given.
686 number string **10e-4**, the resulting decimal number will be **0.0016**.
688 Accepting input as scientific notation is a **non-portable extension**.
696 **++** **-\-**
704 **-** **!**
744 **+** **-**
760 **=** **\<\<=** **\>\>=** **+=** **-=** **\*=** **/=** **%=** **\^=** **\@=**
794 **++** **-\-**
803 **-**
817 This is a **non-portable extension**.
824 This is a **non-portable extension**.
834 The second expression must be an integer (no *scale*) and non-negative.
836 This is a **non-portable extension**.
845 negative, the first value must be non-zero.
860 The second expression must be non-zero.
866 result of step 1 to calculate **a-(a/b)\*b** to *scale*
869 The second expression must be non-zero.
876 **-**
888 The second expression must be an integer (no *scale*) and non-negative.
890 This is a **non-portable extension**.
898 The second expression must be an integer (no *scale*) and non-negative.
900 This is a **non-portable extension**.
902 **=** **\<\<=** **\>\>=** **+=** **-=** **\*=** **/=** **%=** **\^=** **\@=**
912 extensions are themselves **non-portable extensions**.
926 allowance is a **non-portable extension**.
931 expressions are non-zero, **0** otherwise.
933 This is *not* a short-circuit operator.
935 This is a **non-portable extension**.
940 of the expressions is non-zero, **0** otherwise.
942 This is *not* a short-circuit operator.
944 This is a **non-portable extension**.
972 Numbers 4, 9, 11, 12, 14, 15, and 16 are **non-portable extensions**.
974 Also, as a **non-portable extension**, any or all of the expressions in the
988 not be executed (it is a compile-time command).
1008 is like the **quit** statement in that it is a compile-time command.
1018 either the **-s** or **-w** command-line options (or equivalents).
1021 **non-portable extension**.
1040 are **non-portable extensions**.
1067 be printed as-is.
1069 Any non-string expression in a print statement shall be assigned to **last**,
1082 **256** and each digit is interpreted as an 8-bit ASCII character, making it a
1123 As a **non-portable extension**, the opening brace of a **define** statement may
1126 As a **non-portable extension**, the return statement may also be in one of the
1159 This is a **non-portable extension**.
1174 This is a **non-portable extension**.
1180 **-l** or **-\-mathlib** command-line flags are given, except that the extended
1181 math library is not available when the **-s** option, the **-w** option, or
1233 The extended library is *not* loaded when the **-s**/**-\-standard** or
1234 **-w**/**-\-warn** options are given since they are not part of the library
1237 The extended library is a **non-portable extension**.
1244 It is an error if **y** is negative and **x** is **0**.
1317 If **r** is **0** or negative, this raises an error and causes bc(1) to
1319 to reset if **r** is even and **x** is negative.
1352 is less than **0**, it returns **a(y/x)-pi**. If **x** is equal to **0**,
1354 **0**, and **y** is less than **0**, it returns **-pi/2**.
1384 If **x** is equal to **1** or **-1**, this raises an error and causes bc(1)
1408 is less than **0**, it returns **a(y/x)-pi**. If **x** is equal to **0**,
1410 **0**, and **y** is less than **0**, it returns **-pi/2**.
1436 : Generates a pseudo-random number between **0** (inclusive) and **1**
1444 : Generates a pseudo-random number that is between **0** (inclusive) and the
1454 bounds to enerate a pseudo-random integer. If the difference of the
1495 and returns the result of **a** bit-shifted left by **b** places.
1503 and returns the truncated result of **a** bit-shifted right by **b** places.
1559 has the same number of 8-bit bytes as the truncated absolute value of **n**.
1607 though it has the same number of unsigned 8-bit bytes as the truncated
1610 binary digits in **n** 8-bit bytes.
1658 though it has the minimum number of power of two unsigned 8-bit bytes, by
1661 8-bit bytes.
1669 though it has the same number of unsigned 8-bit bytes as the truncated
1672 binary digits in **n** 8-bit bytes.
1720 though it has the minimum number of power of two unsigned 8-bit bytes, by
1723 8-bit bytes.
1771 : Assumes **t** is a bitwise-reversed number with an extra set bit one place
1781 : If **x** is not equal to **0** and greater that **-1** and less than **1**,
1782 it is printed with a leading zero, regardless of the use of the **-z**
1789 : If **x** is not equal to **0** and greater that **-1** and less than **1**,
1790 it is printed with a leading zero, regardless of the use of the **-z**
1797 : If **x** is not equal to **0** and greater that **-1** and less than **1**,
1798 it is printed without a leading zero, regardless of the use of the **-z**
1805 : If **x** is not equal to **0** and greater that **-1** and less than **1**,
1806 it is printed without a leading zero, regardless of the use of the **-z**
1818 : Returns the numbers of signed, two's-complement integer bytes required to
1823 : Returns **x** if it is non-negative. If it *is* negative, then it calculates
1824 what **x** would be as a 2's-complement signed integer and returns the
1825 non-negative integer that would have the same representation in binary.
1829 : Returns **x** if it is non-negative. If it *is* negative, then it calculates
1830 what **x** would be as a 2's-complement signed integer with **n** bytes and
1831 returns the non-negative integer that would have the same representation in
1832 binary. If **x** cannot fit into **n** 2's-complement signed bytes, it is
1862 If **x** is not an integer or is negative, an error message is printed
1871 two's-complement integer in as few power of two bytes as possible. Both
1886 If **x** is not an integer, is negative, or cannot fit into **n** bytes, an
1896 two's-complement integer in **n** bytes. Both outputs are split into bytes
1911 If **x** is not an integer, is negative, or cannot fit into **1** byte, an
1921 two's-complement integer in **1** byte. Both outputs are split into bytes
1936 If **x** is not an integer, is negative, or cannot fit into **2** bytes, an
1946 two's-complement integer in **2** bytes. Both outputs are split into bytes
1961 If **x** is not an integer, is negative, or cannot fit into **4** bytes, an
1971 two's-complement integer in **4** bytes. Both outputs are split into bytes
1986 If **x** is not an integer, is negative, or cannot fit into **8** bytes, an
1996 two's-complement integer in **8** bytes. Both outputs are split into bytes
2035 the least significant byte and **number_of_bytes - 1** is the most
2081 When bc(1) encounters an error or a signal that it has a non-default handler
2148 : The maximum size of arrays. Set at **SIZE_MAX-1**.
2152 : The maximum **scale**. Set at **BC_OVERFLOW_MAX-1**.
2156 : The maximum length of strings. Set at **BC_OVERFLOW_MAX-1**.
2160 : The maximum length of identifiers. Set at **BC_OVERFLOW_MAX-1**.
2165 after the decimal point. Set at **BC_OVERFLOW_MAX-1**.
2170 **2\^BC_LONG_BIT-1**.
2174 : The maximum allowable exponent (positive or negative). Set at
2179 : The maximum number of vars/arrays. Set at **SIZE_MAX-1**.
2183 These limits are meant to be effectively non-existent; the limits are so large
2184 (at least on 64-bit machines) that there should not be any point at which they
2190 As **non-portable extensions**, bc(1) recognizes the following environment
2196 the **-s** option was given.
2200 : This is another way to give command-line arguments to bc(1). They should be
2201 in the same format as all other command-line arguments. These are always
2203 before arguments and files given on the command-line. This gives the user
2219 command-line where the parsing is done by the shell.
2224 than **1** and is less than **UINT16_MAX** (**2\^16-1**), bc(1) will output
2233 : If this environment variable exists and contains an integer, then a non-zero
2242 the **-h** or **-\-help** options.
2251 variable exists and contains an integer, a non-zero value makes bc(1) reset
2257 the **-h** or **-\-help** options.
2265 exists and contains an integer, then a non-zero value makes bc(1) use TTY
2269 the **-h** or **-\-help** options.
2277 exists and contains an integer, a non-zero value makes bc(1) use a prompt,
2278 and zero or a non-integer makes bc(1) not use a prompt. If this environment
2283 override the default, which can be queried with the **-h** or **-\-help**
2288 : If any expressions or expression files are given on the command-line with
2289 **-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
2290 variable exists and contains an integer, a non-zero value makes bc(1) exit
2295 the **-h** or **-\-help** options.
2300 integer, a non-zero value makes bc(1) clamp digits that are greater than or
2306 This never applies to single-digit numbers, as per the standard (see the
2310 the **-h** or **-\-help** options.
2326 Math errors include divide by **0**, taking the square root of a negative
2327 number, using a negative number as a bound for the pseudo-random number
2328 generator, attempting to convert a negative number to a hardware integer,
2330 calculating the size of a number, and attempting to use a non-integer where
2349 variable as a reference, and using any extensions when the option **-s** or
2370 and giving invalid command-line options.
2379 **-i** flag or **-\-interactive** option.
2382 checking, and its normal behavior can be forced by using the **-i** flag or
2383 **-\-interactive** option.
2388 and a non-interactive mode. Interactive mode is turned on automatically when
2389 both **stdin** and **stdout** are hooked to a terminal, but the **-i** flag and
2390 **-\-interactive** option can turn it on in other situations.
2406 non-zero integer, bc(1) will turn on TTY mode when **stdin**, **stdout**, and
2408 variable exists but is *not* a non-zero integer, then bc(1) will not turn TTY
2412 setting is used. The default setting can be queried with the **-h** or
2413 **-\-help** options.
2425 If the environment variable **BC_PROMPT** exists and is a non-zero integer, then
2427 to a TTY and the **-P** and **-\-no-prompt** options were not used. The read
2428 prompt will be turned on under the same conditions, except that the **-R** and
2429 **-\-no-read-prompt** options must also not be used.
2432 with the **BC_TTY_MODE** environment variable, the **-P** and **-\-no-prompt**
2433 options, and the **-R** and **-\-no-read-prompt** options. See the **ENVIRONMENT
2446 default is an integer and non-zero, then bc(1) will stop executing the current
2472 bc(1) is compliant with the IEEE Std 1003.1-2017 (“POSIX.1-2017”) specification
2474 flags **-efghiqsvVw**, all long options, and the extensions noted above are