xref: /freebsd/contrib/bc/gen/bc_help.txt (revision a970610a3af63b3f4df5b69d91c6b4093a00ed8f)
1252884aeSStefan Eßer/*
2252884aeSStefan Eßer * *****************************************************************************
3252884aeSStefan Eßer *
43aa99676SStefan Eßer * SPDX-License-Identifier: BSD-2-Clause
5252884aeSStefan Eßer *
6*a970610aSStefan Eßer * Copyright (c) 2018-2024 Gavin D. Howard and contributors.
7252884aeSStefan Eßer *
8252884aeSStefan Eßer * Redistribution and use in source and binary forms, with or without
9252884aeSStefan Eßer * modification, are permitted provided that the following conditions are met:
10252884aeSStefan Eßer *
11252884aeSStefan Eßer * * Redistributions of source code must retain the above copyright notice, this
12252884aeSStefan Eßer *   list of conditions and the following disclaimer.
13252884aeSStefan Eßer *
14252884aeSStefan Eßer * * Redistributions in binary form must reproduce the above copyright notice,
15252884aeSStefan Eßer *   this list of conditions and the following disclaimer in the documentation
16252884aeSStefan Eßer *   and/or other materials provided with the distribution.
17252884aeSStefan Eßer *
18252884aeSStefan Eßer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19252884aeSStefan Eßer * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20252884aeSStefan Eßer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21252884aeSStefan Eßer * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22252884aeSStefan Eßer * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23252884aeSStefan Eßer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24252884aeSStefan Eßer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25252884aeSStefan Eßer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26252884aeSStefan Eßer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27252884aeSStefan Eßer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28252884aeSStefan Eßer * POSSIBILITY OF SUCH DAMAGE.
29252884aeSStefan Eßer *
30252884aeSStefan Eßer * *****************************************************************************
31252884aeSStefan Eßer *
32252884aeSStefan Eßer * The bc help text.
33252884aeSStefan Eßer *
34252884aeSStefan Eßer */
35252884aeSStefan Eßer
36252884aeSStefan Eßerusage: %s [options] [file...]
37252884aeSStefan Eßer
38252884aeSStefan Eßerbc is a command-line, arbitrary-precision calculator with a Turing-complete
397e5c51e5SStefan Eßerlanguage. For details, use `man %s` or see the online documentation at
404fca8e0fSStefan Eßerhttps://git.gavinhoward.com/gavin/bc/src/tag/%s/manuals/bc/%s.1.md.
41252884aeSStefan Eßer
42252884aeSStefan EßerThis bc is compatible with both the GNU bc and the POSIX bc spec. See the GNU bc
43252884aeSStefan Eßermanual (https://www.gnu.org/software/bc/manual/bc.html) and bc spec
44252884aeSStefan Eßer(http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
45252884aeSStefan Eßerfor details.
46252884aeSStefan Eßer
47252884aeSStefan EßerThis bc has three differences to the GNU bc:
48252884aeSStefan Eßer
49252884aeSStefan Eßer  1) Arrays can be passed to the builtin "length" function to get the number of
50252884aeSStefan Eßer     elements currently in the array. The following example prints "1":
51252884aeSStefan Eßer
52252884aeSStefan Eßer       a[0] = 0
53252884aeSStefan Eßer       length(a[])
54252884aeSStefan Eßer
55252884aeSStefan Eßer  2) The precedence of the boolean "not" operator (!) is equal to that of the
56252884aeSStefan Eßer     unary minus (-), or negation, operator. This still allows POSIX-compliant
57252884aeSStefan Eßer     scripts to work while somewhat preserving expected behavior (versus C) and
58252884aeSStefan Eßer     making parsing easier.
59252884aeSStefan Eßer  3) This bc has many more extensions than the GNU bc does. For details, see the
607e5c51e5SStefan Eßer     man page or online documentation.
61252884aeSStefan Eßer
623aa99676SStefan EßerThis bc also implements the dot (.) extension of the BSD bc.
633aa99676SStefan Eßer
64252884aeSStefan EßerOptions:
65d101cdd6SStefan Eßer
66d101cdd6SStefan Eßer  -C  --no-digit-clamp
67d101cdd6SStefan Eßer
68d101cdd6SStefan Eßer      Disables clamping of digits that are larger than or equal to the current
69d101cdd6SStefan Eßer      ibase when parsing numbers.
70d101cdd6SStefan Eßer
71d101cdd6SStefan Eßer      This means that the value added to a number from a digit is always that
72d101cdd6SStefan Eßer      digit's value multiplied by the value of ibase raised to the power of the
73d101cdd6SStefan Eßer      digit's position, which starts from 0 at the least significant digit.
74d101cdd6SStefan Eßer
75d101cdd6SStefan Eßer      If multiple of this option and the -c option are given, the last is used.
76d101cdd6SStefan Eßer
77d101cdd6SStefan Eßer  -c  --digit-clamp
78d101cdd6SStefan Eßer
79d101cdd6SStefan Eßer      Enables clamping of digits that are larger than or equal to the current
80d101cdd6SStefan Eßer      ibase when parsing numbers.
81d101cdd6SStefan Eßer
82d101cdd6SStefan Eßer      This means that digits that the value added to a number from a digit that
83d101cdd6SStefan Eßer      is greater than or equal to the ibase is the value of ibase minus 1 all
84d101cdd6SStefan Eßer      multiplied by the value of ibase raised to the power of the digit's
85d101cdd6SStefan Eßer      position, which starts from 0 at the least significant digit.
86d101cdd6SStefan Eßer
87d101cdd6SStefan Eßer      If multiple of this option and the -C option are given, the last is used.
8878bc019dSStefan Eßer{{ A H N HN }}
8978bc019dSStefan Eßer
9078bc019dSStefan Eßer  -E  seed  --seed=seed
9178bc019dSStefan Eßer
9278bc019dSStefan Eßer      Sets the builtin variable seed to the given value assuming that the given
9378bc019dSStefan Eßer      value is in base 10. It is a fatal error if the given value is not a valid
9478bc019dSStefan Eßer      number.
9578bc019dSStefan Eßer{{ end }}
96252884aeSStefan Eßer
97252884aeSStefan Eßer  -e  expr  --expression=expr
98252884aeSStefan Eßer
99252884aeSStefan Eßer      Run "expr" and quit. If multiple expressions or files (see below) are
100252884aeSStefan Eßer      given, they are all run before executing from stdin.
101252884aeSStefan Eßer
102252884aeSStefan Eßer  -f  file  --file=file
103252884aeSStefan Eßer
104252884aeSStefan Eßer      Run the bc code in "file" and exit. See above as well.
105252884aeSStefan Eßer
106252884aeSStefan Eßer  -g  --global-stacks
107252884aeSStefan Eßer
108252884aeSStefan Eßer      Turn scale, ibase, and obase into stacks. This makes the value of each be
1097e5c51e5SStefan Eßer      be restored on returning from functions. See the man page or online
1107e5c51e5SStefan Eßer      documentation for more details.
111252884aeSStefan Eßer
112252884aeSStefan Eßer  -h  --help
113252884aeSStefan Eßer
114252884aeSStefan Eßer      Print this usage message and exit.
115252884aeSStefan Eßer
11678bc019dSStefan Eßer  -I  ibase  --ibase=ibase
11778bc019dSStefan Eßer
11878bc019dSStefan Eßer      Sets the builtin variable ibase to the given value assuming that the given
11978bc019dSStefan Eßer      value is in base 10. It is a fatal error if the given value is not a valid
12078bc019dSStefan Eßer      number.
12178bc019dSStefan Eßer
122252884aeSStefan Eßer  -i  --interactive
123252884aeSStefan Eßer
124252884aeSStefan Eßer      Force interactive mode.
125252884aeSStefan Eßer
126d43fa8efSStefan Eßer  -L  --no-line-length
127d43fa8efSStefan Eßer
128d43fa8efSStefan Eßer      Disable line length checking.
129d43fa8efSStefan Eßer
130252884aeSStefan Eßer  -l  --mathlib
131252884aeSStefan Eßer
132252884aeSStefan Eßer      Use predefined math routines:
133252884aeSStefan Eßer
134252884aeSStefan Eßer          s(expr)  =  sine of expr in radians
135252884aeSStefan Eßer          c(expr)  =  cosine of expr in radians
136252884aeSStefan Eßer          a(expr)  =  arctangent of expr, returning radians
137252884aeSStefan Eßer          l(expr)  =  natural log of expr
138252884aeSStefan Eßer          e(expr)  =  raises e to the power of expr
139252884aeSStefan Eßer          j(n, x)  =  Bessel function of integer order n of x
140252884aeSStefan Eßer
1417e5c51e5SStefan Eßer      This bc may load more functions with these options. See the manpage or
1427e5c51e5SStefan Eßer      online documentation for details.
1433aa99676SStefan Eßer
14478bc019dSStefan Eßer  -O  obase  --obase=obase
14578bc019dSStefan Eßer
14678bc019dSStefan Eßer      Sets the builtin variable obase to the given value assuming that the given
14778bc019dSStefan Eßer      value is in base 10. It is a fatal error if the given value is not a valid
14878bc019dSStefan Eßer      number.
14978bc019dSStefan Eßer
150252884aeSStefan Eßer  -P  --no-prompt
151252884aeSStefan Eßer
1527e5c51e5SStefan Eßer      Disable the prompts in interactive mode.
1537e5c51e5SStefan Eßer
1547e5c51e5SStefan Eßer  -R  --no-read-prompt
1557e5c51e5SStefan Eßer
1567e5c51e5SStefan Eßer      Disable the read prompt in interactive mode.
157252884aeSStefan Eßer
15844d4804dSStefan Eßer  -r  keyword  --redefine=keyword
15944d4804dSStefan Eßer
16044d4804dSStefan Eßer      Redefines "keyword" and allows it to be used as a function, variable, and
16144d4804dSStefan Eßer      array name. This is useful when this bc gives parse errors on scripts
16244d4804dSStefan Eßer      meant for other bc implementations.
16344d4804dSStefan Eßer
16444d4804dSStefan Eßer      Only keywords that are not in the POSIX bc spec may be redefined.
16544d4804dSStefan Eßer
16644d4804dSStefan Eßer      It is a fatal error to attempt to redefine a keyword that cannot be
16744d4804dSStefan Eßer      redefined or does not exist.
16844d4804dSStefan Eßer
169252884aeSStefan Eßer  -q  --quiet
170252884aeSStefan Eßer
171252884aeSStefan Eßer      Don't print version and copyright.
172252884aeSStefan Eßer
17378bc019dSStefan Eßer  -S  scale  --scale=scale
17478bc019dSStefan Eßer
17578bc019dSStefan Eßer      Sets the builtin variable scale to the given value assuming that the given
17678bc019dSStefan Eßer      value is in base 10. It is a fatal error if the given value is not a valid
17778bc019dSStefan Eßer      number.
17878bc019dSStefan Eßer
179252884aeSStefan Eßer  -s  --standard
180252884aeSStefan Eßer
181252884aeSStefan Eßer      Error if any non-POSIX extensions are used.
182252884aeSStefan Eßer
183252884aeSStefan Eßer  -w  --warn
184252884aeSStefan Eßer
185252884aeSStefan Eßer      Warn if any non-POSIX extensions are used.
186252884aeSStefan Eßer
187252884aeSStefan Eßer  -v  --version
188252884aeSStefan Eßer
189252884aeSStefan Eßer      Print version information and copyright and exit.
19044d4804dSStefan Eßer
191d43fa8efSStefan Eßer  -z  --leading-zeroes
192d43fa8efSStefan Eßer
193d43fa8efSStefan Eßer      Enable leading zeroes on numbers greater than -1 and less than 1.
194d43fa8efSStefan Eßer
19544d4804dSStefan EßerEnvironment variables:
19644d4804dSStefan Eßer
19744d4804dSStefan Eßer  POSIXLY_CORRECT
19844d4804dSStefan Eßer
19944d4804dSStefan Eßer      Error if any non-POSIX extensions are used.
20044d4804dSStefan Eßer
20144d4804dSStefan Eßer  BC_ENV_ARGS
20244d4804dSStefan Eßer
20344d4804dSStefan Eßer      Command-line arguments to use on every run.
20444d4804dSStefan Eßer
20544d4804dSStefan Eßer  BC_LINE_LENGTH
20644d4804dSStefan Eßer
20744d4804dSStefan Eßer      If an integer, the number of characters to print on a line before
208d43fa8efSStefan Eßer      wrapping. Using 0 will disable line length checking.
20944d4804dSStefan Eßer
21044d4804dSStefan Eßer  BC_BANNER
21144d4804dSStefan Eßer
21244d4804dSStefan Eßer      If an integer and non-zero, display the copyright banner in interactive
21344d4804dSStefan Eßer      mode.
21444d4804dSStefan Eßer
215d101cdd6SStefan Eßer      If zero, disable the banner.
216d101cdd6SStefan Eßer
21744d4804dSStefan Eßer      Overrides the default, which is %s print the banner.
21844d4804dSStefan Eßer
21944d4804dSStefan Eßer  BC_SIGINT_RESET
22044d4804dSStefan Eßer
22144d4804dSStefan Eßer      If an integer and non-zero, reset on SIGINT, rather than exit, when in
22244d4804dSStefan Eßer      interactive mode.
22344d4804dSStefan Eßer
224d101cdd6SStefan Eßer      If zero, do not reset on SIGINT in all cases, but exit instead.
225d101cdd6SStefan Eßer
22644d4804dSStefan Eßer      Overrides the default, which is %s.
22744d4804dSStefan Eßer
22844d4804dSStefan Eßer  BC_TTY_MODE
22944d4804dSStefan Eßer
23044d4804dSStefan Eßer      If an integer and non-zero, enable TTY mode when it is available.
23144d4804dSStefan Eßer
232d101cdd6SStefan Eßer      If zero, disable TTY mode in all cases.
233d101cdd6SStefan Eßer
23444d4804dSStefan Eßer      Overrides the default, which is TTY mode %s.
23544d4804dSStefan Eßer
23644d4804dSStefan Eßer  BC_PROMPT
23744d4804dSStefan Eßer
23844d4804dSStefan Eßer      If an integer and non-zero, enable prompt when TTY mode is possible.
23944d4804dSStefan Eßer
240d101cdd6SStefan Eßer      If zero, disable prompt in all cases.
241d101cdd6SStefan Eßer
24244d4804dSStefan Eßer      Overrides the default, which is prompt %s.
24310041e99SStefan Eßer
24410041e99SStefan Eßer  BC_EXPR_EXIT
24510041e99SStefan Eßer
24610041e99SStefan Eßer      If an integer and non-zero, exit when expressions or expression files are
24710041e99SStefan Eßer      given on the command-line, and does not exit when an integer and zero.
24810041e99SStefan Eßer
24910041e99SStefan Eßer      Overrides the default, which is %s.
250d101cdd6SStefan Eßer
251d101cdd6SStefan Eßer  BC_DIGIT_CLAMP
252d101cdd6SStefan Eßer
253d101cdd6SStefan Eßer      If an integer and non-zero, clamp digits larger than or equal to the
254d101cdd6SStefan Eßer      current ibase when parsing numbers.
255d101cdd6SStefan Eßer
256d101cdd6SStefan Eßer      Overrides the default, which is %s.
257