Lines Matching +full:- +full:r

2 .\" SPDX-License-Identifier: BSD-2-Clause
4 .\" Copyright (c) 2018-2024 Gavin D. Howard and contributors.
32 bc \- arbitrary\-precision decimal arithmetic language and calculator
34 \f[B]bc\f[R] [\f[B]\-cCghilPqRsvVw\f[R]] [\f[B]\-\-digit\-clamp\f[R]]
35 [\f[B]\-\-no\-digit\-clamp\f[R]] [\f[B]\-\-global\-stacks\f[R]]
36 [\f[B]\-\-help\f[R]] [\f[B]\-\-interactive\f[R]] [\f[B]\-\-mathlib\f[R]]
37 [\f[B]\-\-no\-prompt\f[R]] [\f[B]\-\-no\-read\-prompt\f[R]]
38 [\f[B]\-\-quiet\f[R]] [\f[B]\-\-standard\f[R]] [\f[B]\-\-warn\f[R]]
39 [\f[B]\-\-version\f[R]] [\f[B]\-e\f[R] \f[I]expr\f[R]]
40 [\f[B]\-\-expression\f[R]=\f[I]expr\f[R]\&...]
41 [\f[B]\-f\f[R] \f[I]file\f[R]\&...]
42 [\f[B]\-\-file\f[R]=\f[I]file\f[R]\&...]
43 [\f[I]file\f[R]\&...]
44 [\f[B]\-I\f[R] \f[I]ibase\f[R]] [\f[B]\-\-ibase\f[R]=\f[I]ibase\f[R]]
45 [\f[B]\-O\f[R] \f[I]obase\f[R]] [\f[B]\-\-obase\f[R]=\f[I]obase\f[R]]
46 [\f[B]\-S\f[R] \f[I]scale\f[R]] [\f[B]\-\-scale\f[R]=\f[I]scale\f[R]]
47 [\f[B]\-E\f[R] \f[I]seed\f[R]] [\f[B]\-\-seed\f[R]=\f[I]seed\f[R]]
51 (See the \f[B]STANDARDS\f[R] section.)
53 somewhat C\-like, but there are differences.
57 the command line and executes them before reading from \f[B]stdin\f[R].
59 This bc(1) is a drop\-in replacement for \f[I]any\f[R] bc(1), including
64 \f[B]Note\f[R]: If running this bc(1) on \f[I]any\f[R] script meant for
68 To fix that, use the command\-line option \f[B]\-r\f[R]
69 \f[I]keyword\f[R], where \f[I]keyword\f[R] is the keyword that is used
71 For more information, see the \f[B]OPTIONS\f[R] section.
75 See the \f[B]BUGS\f[R] section.
79 \f[B]\-C\f[R], \f[B]\-\-no\-digit\-clamp\f[R]
81 \f[B]ibase\f[R] when parsing numbers.
89 If this and/or the \f[B]\-c\f[R] or \f[B]\-\-digit\-clamp\f[R] options
92 This option overrides the \f[B]BC_DIGIT_CLAMP\f[R] environment variable
93 (see the \f[B]ENVIRONMENT VARIABLES\f[R] section) and the default, which
94 can be queried with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
96 This is a \f[B]non\-portable extension\f[R].
99 \f[B]\-c\f[R], \f[B]\-\-digit\-clamp\f[R]
101 \f[B]ibase\f[R] when parsing numbers.
110 If this and/or the \f[B]\-C\f[R] or \f[B]\-\-no\-digit\-clamp\f[R]
113 This option overrides the \f[B]BC_DIGIT_CLAMP\f[R] environment variable
114 (see the \f[B]ENVIRONMENT VARIABLES\f[R] section) and the default, which
115 can be queried with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
117 This is a \f[B]non\-portable extension\f[R].
120 \f[B]\-E\f[R] \f[I]seed\f[R], \f[B]\-\-seed\f[R]=\f[I]seed\f[R]
121 Sets the builtin variable \f[B]seed\f[R] to the value \f[I]seed\f[R]
122 assuming that \f[I]seed\f[R] is in base 10.
123 It is a fatal error if \f[I]seed\f[R] is not a valid number.
128 This is a \f[B]non\-portable extension\f[R].
131 \f[B]\-e\f[R] \f[I]expr\f[R], \f[B]\-\-expression\f[R]=\f[I]expr\f[R]
132 Evaluates \f[I]expr\f[R].
134 If files are given as well (see the \f[B]\-f\f[R] and \f[B]\-\-file\f[R]
140 If this option is given on the command\-line (i.e., not in
141 \f[B]BC_ENV_ARGS\f[R], see the \f[B]ENVIRONMENT VARIABLES\f[R] section),
143 \f[B]\-\f[R] (\f[B]stdin\f[R]) was given as an argument at least once to
144 \f[B]\-f\f[R] or \f[B]\-\-file\f[R], whether on the command\-line or in
145 \f[B]BC_ENV_ARGS\f[R].
146 However, if any other \f[B]\-e\f[R], \f[B]\-\-expression\f[R],
147 \f[B]\-f\f[R], or \f[B]\-\-file\f[R] arguments are given after
148 \f[B]\-f\-\f[R] or equivalent is given, bc(1) will give a fatal error
151 This is a \f[B]non\-portable extension\f[R].
154 \f[B]\-f\f[R] \f[I]file\f[R], \f[B]\-\-file\f[R]=\f[I]file\f[R]
155 Reads in \f[I]file\f[R] and evaluates it, line by line, as though it
156 were read through \f[B]stdin\f[R].
157 If expressions are also given (see the \f[B]\-e\f[R] and
158 \f[B]\-\-expression\f[R] options), the expressions are evaluated in the
162 If this option is given on the command\-line (i.e., not in
163 \f[B]BC_ENV_ARGS\f[R], see the \f[B]ENVIRONMENT VARIABLES\f[R] section),
165 \f[B]\-\f[R] (\f[B]stdin\f[R]) was given as an argument at least once to
166 \f[B]\-f\f[R] or \f[B]\-\-file\f[R].
167 However, if any other \f[B]\-e\f[R], \f[B]\-\-expression\f[R],
168 \f[B]\-f\f[R], or \f[B]\-\-file\f[R] arguments are given after
169 \f[B]\-f\-\f[R] or equivalent is given, bc(1) will give a fatal error
172 This is a \f[B]non\-portable extension\f[R].
175 \f[B]\-g\f[R], \f[B]\-\-global\-stacks\f[R]
176 Turns the globals \f[B]ibase\f[R], \f[B]obase\f[R], \f[B]scale\f[R], and
177 \f[B]seed\f[R] into stacks.
185 Thus, a hypothetical function named \f[B]output(x,b)\f[R] that simply
186 printed \f[B]x\f[R] in base \f[B]b\f[R] could be written like this:
209 (\f[B]Note\f[R]: the function \f[B]output(x,b)\f[R] exists in the
211 See the \f[B]LIBRARY\f[R] section.)
214 \f[B]ibase\f[R], \f[B]obase\f[R], \f[B]scale\f[R], or \f[B]seed\f[R]
224 alias d2o=\[dq]bc \-e ibase=A \-e obase=8\[dq]
225 alias h2b=\[dq]bc \-e ibase=G \-e obase=2\[dq]
228 Second, if the purpose of a function is to set \f[B]ibase\f[R],
229 \f[B]obase\f[R], \f[B]scale\f[R], or \f[B]seed\f[R] globally for any
234 For functions that set \f[B]seed\f[R], the value assigned to
235 \f[B]seed\f[R] is not propagated to parent functions.
236 This means that the sequence of pseudo\-random numbers that they see
237 will not be the same sequence of pseudo\-random numbers that any parent
239 This is only the case once \f[B]seed\f[R] has been set.
241 If a function desires to not affect the sequence of pseudo\-random
242 numbers of its parents, but wants to use the same \f[B]seed\f[R], it can
250 users could make sure to define \f[B]BC_ENV_ARGS\f[R] and include this
251 option (see the \f[B]ENVIRONMENT VARIABLES\f[R] section for more
254 If \f[B]\-s\f[R], \f[B]\-w\f[R], or any equivalents are used, this
257 This is a \f[B]non\-portable extension\f[R].
260 \f[B]\-h\f[R], \f[B]\-\-help\f[R]
263 \f[B]\-I\f[R] \f[I]ibase\f[R], \f[B]\-\-ibase\f[R]=\f[I]ibase\f[R]
264 Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
265 assuming that \f[I]ibase\f[R] is in base 10.
266 It is a fatal error if \f[I]ibase\f[R] is not a valid number.
271 This is a \f[B]non\-portable extension\f[R].
274 \f[B]\-i\f[R], \f[B]\-\-interactive\f[R]
276 (See the \f[B]INTERACTIVE MODE\f[R] section.)
279 This is a \f[B]non\-portable extension\f[R].
282 \f[B]\-L\f[R], \f[B]\-\-no\-line\-length\f[R]
285 In other words, this option sets \f[B]BC_LINE_LENGTH\f[R] to \f[B]0\f[R]
286 (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
289 This is a \f[B]non\-portable extension\f[R].
292 \f[B]\-l\f[R], \f[B]\-\-mathlib\f[R]
293 Sets \f[B]scale\f[R] (see the \f[B]SYNTAX\f[R] section) to \f[B]20\f[R]
299 To learn what is in the libraries, see the \f[B]LIBRARY\f[R] section.
302 \f[B]\-O\f[R] \f[I]obase\f[R], \f[B]\-\-obase\f[R]=\f[I]obase\f[R]
303 Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
304 assuming that \f[I]obase\f[R] is in base 10.
305 It is a fatal error if \f[I]obase\f[R] is not a valid number.
310 This is a \f[B]non\-portable extension\f[R].
313 \f[B]\-P\f[R], \f[B]\-\-no\-prompt\f[R]
316 See the \f[B]TTY MODE\f[R] section.)
320 \f[B]BC_ENV_ARGS\f[R] (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
323 These options override the \f[B]BC_PROMPT\f[R] and \f[B]BC_TTY_MODE\f[R]
324 environment variables (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
326 This is a \f[B]non\-portable extension\f[R].
329 \f[B]\-q\f[R], \f[B]\-\-quiet\f[R]
331 (https://www.gnu.org/software/bc/); it is a no\-op.
334 \f[B]\-v\f[R], \f[B]\-V\f[R], or \f[B]\-\-version\f[R] options are given
335 unless the \f[B]BC_BANNER\f[R] environment variable is set and contains
336 a non\-zero integer or if this bc(1) was built with the header displayed
338 If \f[I]any\f[R] of that is the case, then this option \f[I]does\f[R]
342 This is a \f[B]non\-portable extension\f[R].
345 \f[B]\-R\f[R], \f[B]\-\-no\-read\-prompt\f[R]
348 See the \f[B]TTY MODE\f[R] section.)
352 \f[B]BC_ENV_ARGS\f[R] (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
358 is only used when the \f[B]read()\f[R] built\-in function is called.
360 These options \f[I]do\f[R] override the \f[B]BC_PROMPT\f[R] and
361 \f[B]BC_TTY_MODE\f[R] environment variables (see the \f[B]ENVIRONMENT
362 VARIABLES\f[R] section), but only for the read prompt.
364 This is a \f[B]non\-portable extension\f[R].
367 \f[B]\-r\f[R] \f[I]keyword\f[R], \f[B]\-\-redefine\f[R]=\f[I]keyword\f[R]
368 Redefines \f[I]keyword\f[R] in order to allow it to be used as a
376 \f[B]abs\f[R]
378 \f[B]asciify\f[R]
380 \f[B]continue\f[R]
382 \f[B]divmod\f[R]
384 \f[B]else\f[R]
386 \f[B]halt\f[R]
388 \f[B]irand\f[R]
390 \f[B]last\f[R]
392 \f[B]limits\f[R]
394 \f[B]maxibase\f[R]
396 \f[B]maxobase\f[R]
398 \f[B]maxrand\f[R]
400 \f[B]maxscale\f[R]
402 \f[B]modexp\f[R]
404 \f[B]print\f[R]
406 \f[B]rand\f[R]
408 \f[B]read\f[R]
410 \f[B]seed\f[R]
412 \f[B]stream\f[R]
419 Keywords are \f[I]not\f[R] redefined when parsing the builtin math
420 library (see the \f[B]LIBRARY\f[R] section).
423 (see the \f[B]STANDARDS\f[R] section).
428 \f[B]\-S\f[R] \f[I]scale\f[R], \f[B]\-\-scale\f[R]=\f[I]scale\f[R]
429 Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
430 assuming that \f[I]scale\f[R] is in base 10.
431 It is a fatal error if \f[I]scale\f[R] is not a valid number.
436 This is a \f[B]non\-portable extension\f[R].
439 \f[B]\-s\f[R], \f[B]\-\-standard\f[R]
441 \f[B]STANDARDS\f[R] section) and error if any extensions are used.
444 This is a \f[B]non\-portable extension\f[R].
447 \f[B]\-v\f[R], \f[B]\-V\f[R], \f[B]\-\-version\f[R]
451 This is a \f[B]non\-portable extension\f[R].
454 \f[B]\-w\f[R], \f[B]\-\-warn\f[R]
455 Like \f[B]\-s\f[R] and \f[B]\-\-standard\f[R], except that warnings (and
456 not errors) are printed for non\-standard extensions and execution
460 This is a \f[B]non\-portable extension\f[R].
463 \f[B]\-z\f[R], \f[B]\-\-leading\-zeroes\f[R]
464 Makes bc(1) print all numbers greater than \f[B]\-1\f[R] and less than
465 \f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
468 This can be set for individual numbers with the \f[B]plz(x)\f[R],
469 \f[B]plznl(x)\f[R], \f[B]pnlz(x)\f[R], and \f[B]pnlznl(x)\f[R] functions
470 in the extended math library (see the \f[B]LIBRARY\f[R] section).
472 This is a \f[B]non\-portable extension\f[R].
475 All long options are \f[B]non\-portable extensions\f[R].
477 If no files or expressions are given by the \f[B]\-f\f[R],
478 \f[B]\-\-file\f[R], \f[B]\-e\f[R], or \f[B]\-\-expression\f[R] options,
479 then bc(1) reads from \f[B]stdin\f[R].
483 First, \f[B]stdin\f[R] is evaluated a line at a time.
486 function, \f[B]if\f[R] statement, or loop without ending it will also
489 Second, after an \f[B]if\f[R] statement, bc(1) doesn\[cq]t know if an
490 \f[B]else\f[R] statement will follow, so it will not execute until it
491 knows there will not be an \f[B]else\f[R] statement.
493 Any non\-error output is written to \f[B]stdout\f[R].
494 In addition, if history (see the \f[B]HISTORY\f[R] section) and the
495 prompt (see the \f[B]TTY MODE\f[R] section) are enabled, both are output
496 to \f[B]stdout\f[R].
498 \f[B]Note\f[R]: Unlike other bc(1) implementations, this bc(1) will
499 issue a fatal error (see the \f[B]EXIT STATUS\f[R] section) if it cannot
500 write to \f[B]stdout\f[R], so if \f[B]stdout\f[R] is closed, as in
501 \f[B]bc >&\-\f[R], it will quit with an error.
502 This is done so that bc(1) can report problems when \f[B]stdout\f[R] is
507 redirect \f[B]stdout\f[R] to \f[B]/dev/null\f[R].
509 Any error output is written to \f[B]stderr\f[R].
511 \f[B]Note\f[R]: Unlike other bc(1) implementations, this bc(1) will
512 issue a fatal error (see the \f[B]EXIT STATUS\f[R] section) if it cannot
513 write to \f[B]stderr\f[R], so if \f[B]stderr\f[R] is closed, as in
514 \f[B]bc 2>&\-\f[R], it will quit with an error.
516 \f[B]stderr\f[R] is redirected to a file.
520 redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
522 The syntax for bc(1) programs is mostly C\-like, with some differences.
523 This bc(1) follows the POSIX standard (see the \f[B]STANDARDS\f[R]
529 In the sections below, \f[B]E\f[R] means expression, \f[B]S\f[R] means
530 statement, and \f[B]I\f[R] means identifier.
532 Identifiers (\f[B]I\f[R]) start with a lowercase letter and can be
533 followed by any number (up to \f[B]BC_NAME_MAX\-1\f[R]) of lowercase
534 letters (\f[B]a\-z\f[R]), digits (\f[B]0\-9\f[R]), and underscores
535 (\f[B]_\f[R]).
536 The regex is \f[B][a\-z][a\-z0\-9_]*\f[R].
538 \f[B]non\-portable extension\f[R].
540 \f[B]ibase\f[R] is a global variable determining how to interpret
544 \f[B]ibase\f[R] is initially \f[B]10\f[R].
545 If the \f[B]\-s\f[R] (\f[B]\-\-standard\f[R]) and \f[B]\-w\f[R]
546 (\f[B]\-\-warn\f[R]) flags were not given on the command line, the max
547 allowable value for \f[B]ibase\f[R] is \f[B]36\f[R].
548 Otherwise, it is \f[B]16\f[R].
549 The min allowable value for \f[B]ibase\f[R] is \f[B]2\f[R].
550 The max allowable value for \f[B]ibase\f[R] can be queried in bc(1)
551 programs with the \f[B]maxibase()\f[R] built\-in function.
553 \f[B]obase\f[R] is a global variable determining how to output results.
556 \f[B]obase\f[R] is initially \f[B]10\f[R].
557 The max allowable value for \f[B]obase\f[R] is \f[B]BC_BASE_MAX\f[R] and
558 can be queried in bc(1) programs with the \f[B]maxobase()\f[R] built\-in
560 The min allowable value for \f[B]obase\f[R] is \f[B]0\f[R].
561 If \f[B]obase\f[R] is \f[B]0\f[R], values are output in scientific
562 notation, and if \f[B]obase\f[R] is \f[B]1\f[R], values are output in
567 \f[B]non\-portable extensions\f[R].
569 The \f[I]scale\f[R] of an expression is the number of digits in the
570 result of the expression right of the decimal point, and \f[B]scale\f[R]
573 \f[B]scale\f[R] is initially \f[B]0\f[R].
574 \f[B]scale\f[R] cannot be negative.
575 The max allowable value for \f[B]scale\f[R] is \f[B]BC_SCALE_MAX\f[R]
576 and can be queried in bc(1) programs with the \f[B]maxscale()\f[R]
577 built\-in function.
579 bc(1) has both \f[I]global\f[R] variables and \f[I]local\f[R] variables.
580 All \f[I]local\f[R] variables are local to the function; they are
581 parameters or are introduced in the \f[B]auto\f[R] list of a function
582 (see the \f[B]FUNCTIONS\f[R] section).
584 \f[B]auto\f[R] list, it is assumed to be \f[I]global\f[R].
585 If a parent function has a \f[I]local\f[R] variable version of a
586 variable that a child function considers \f[I]global\f[R], the value of
587 that \f[I]global\f[R] variable in the child function is the value of the
589 \f[I]global\f[R] variable.
595 operator is an assignment operator \f[I]and\f[R] the expression is
599 \f[B]last\f[R].
600 A single dot (\f[B].\f[R]) may also be used as a synonym for
601 \f[B]last\f[R].
602 These are \f[B]non\-portable extensions\f[R].
608 Block comments are enclosed in \f[B]/*\f[R] and \f[B]*/\f[R].
610 Line comments go from \f[B]#\f[R] until, and not including, the next
612 This is a \f[B]non\-portable extension\f[R].
616 Variables: \f[B]I\f[R]
618 Array Elements: \f[B]I[E]\f[R]
620 \f[B]ibase\f[R]
622 \f[B]obase\f[R]
624 \f[B]scale\f[R]
626 \f[B]seed\f[R]
628 \f[B]last\f[R] or a single dot (\f[B].\f[R])
630 Numbers 6 and 7 are \f[B]non\-portable extensions\f[R].
632 The meaning of \f[B]seed\f[R] is dependent on the current pseudo\-random
636 The \f[I]scale\f[R] and sign of the value may be significant.
638 If a previously used \f[B]seed\f[R] value is assigned to \f[B]seed\f[R]
639 and used again, the pseudo\-random number generator is guaranteed to
640 produce the same sequence of pseudo\-random numbers as it did when the
641 \f[B]seed\f[R] value was previously used.
643 The exact value assigned to \f[B]seed\f[R] is not guaranteed to be
644 returned if \f[B]seed\f[R] is queried again immediately.
645 However, if \f[B]seed\f[R] \f[I]does\f[R] return a different value, both
646 values, when assigned to \f[B]seed\f[R], are guaranteed to produce the
647 same sequence of pseudo\-random numbers.
648 This means that certain values assigned to \f[B]seed\f[R] will
649 \f[I]not\f[R] produce unique sequences of pseudo\-random numbers.
650 The value of \f[B]seed\f[R] will change after any use of the
651 \f[B]rand()\f[R] and \f[B]irand(E)\f[R] operands (see the
652 \f[I]Operands\f[R] subsection below), except if the parameter passed to
653 \f[B]irand(E)\f[R] is \f[B]0\f[R], \f[B]1\f[R], or negative.
656 or \f[I]scale\f[R] of the value that can be assigned to \f[B]seed\f[R].
660 This also applies to functions (see the \f[B]FUNCTIONS\f[R] section), so
666 \f[B]increment\f[R]/\f[B]decrement\f[R] operators and as the left side
667 of \f[B]assignment\f[R] operators (see the \f[I]Operators\f[R]
672 Numbers (see the \f[I]Numbers\f[R] subsection below).
674 Array indices (\f[B]I[E]\f[R]).
676 \f[B](E)\f[R]: The value of \f[B]E\f[R] (used to change precedence).
678 \f[B]sqrt(E)\f[R]: The square root of \f[B]E\f[R].
679 \f[B]E\f[R] must be non\-negative.
681 \f[B]length(E)\f[R]: The number of significant decimal digits in
682 \f[B]E\f[R].
683 Returns \f[B]1\f[R] for \f[B]0\f[R] with no decimal places.
685 Passing a string to \f[B]length(E)\f[R] is a \f[B]non\-portable
686 extension\f[R].
688 \f[B]length(I[])\f[R]: The number of elements in the array \f[B]I\f[R].
689 This is a \f[B]non\-portable extension\f[R].
691 \f[B]scale(E)\f[R]: The \f[I]scale\f[R] of \f[B]E\f[R].
693 \f[B]abs(E)\f[R]: The absolute value of \f[B]E\f[R].
694 This is a \f[B]non\-portable extension\f[R].
696 \f[B]is_number(E)\f[R]: \f[B]1\f[R] if the given argument is a number,
697 \f[B]0\f[R] if it is a string.
698 This is a \f[B]non\-portable extension\f[R].
700 \f[B]is_string(E)\f[R]: \f[B]1\f[R] if the given argument is a string,
701 \f[B]0\f[R] if it is a number.
702 This is a \f[B]non\-portable extension\f[R].
704 \f[B]modexp(E, E, E)\f[R]: Modular exponentiation, where the first
708 The second argument must be non\-negative.
709 The third argument must be non\-zero.
710 This is a \f[B]non\-portable extension\f[R].
712 \f[B]divmod(E, E, I[])\f[R]: Division and modulus in one operation.
715 which must be non\-zero.
717 \f[B]0\f[R] of the provided array (the last argument).
718 This is a \f[B]non\-portable extension\f[R].
720 \f[B]asciify(E)\f[R]: If \f[B]E\f[R] is a string, returns a string that
722 If it is a number, calculates the number mod \f[B]256\f[R] and returns
723 that number as a one\-character string.
724 This is a \f[B]non\-portable extension\f[R].
726 \f[B]asciify(I[])\f[R]: A string that is made up of the characters that
727 would result from running \f[B]asciify(E)\f[R] on each element of the
729 This allows creating multi\-character strings and storing them.
730 This is a \f[B]non\-portable extension\f[R].
732 \f[B]I()\f[R], \f[B]I(E)\f[R], \f[B]I(E, E)\f[R], and so on, where
733 \f[B]I\f[R] is an identifier for a non\-\f[B]void\f[R] function (see the
734 \f[I]Void Functions\f[R] subsection of the \f[B]FUNCTIONS\f[R] section).
735 The \f[B]E\f[R] argument(s) may also be arrays of the form
736 \f[B]I[]\f[R], which will automatically be turned into array references
737 (see the \f[I]Array References\f[R] subsection of the
738 \f[B]FUNCTIONS\f[R] section) if the corresponding parameter in the
741 \f[B]read()\f[R]: Reads a line from \f[B]stdin\f[R] and uses that as an
743 The result of that expression is the result of the \f[B]read()\f[R]
745 This is a \f[B]non\-portable extension\f[R].
747 \f[B]maxibase()\f[R]: The max allowable \f[B]ibase\f[R].
748 This is a \f[B]non\-portable extension\f[R].
750 \f[B]maxobase()\f[R]: The max allowable \f[B]obase\f[R].
751 This is a \f[B]non\-portable extension\f[R].
753 \f[B]maxscale()\f[R]: The max allowable \f[B]scale\f[R].
754 This is a \f[B]non\-portable extension\f[R].
756 \f[B]line_length()\f[R]: The line length set with
757 \f[B]BC_LINE_LENGTH\f[R] (see the \f[B]ENVIRONMENT VARIABLES\f[R]
759 This is a \f[B]non\-portable extension\f[R].
761 \f[B]global_stacks()\f[R]: \f[B]0\f[R] if global stacks are not enabled
762 with the \f[B]\-g\f[R] or \f[B]\-\-global\-stacks\f[R] options,
763 non\-zero otherwise.
764 See the \f[B]OPTIONS\f[R] section.
765 This is a \f[B]non\-portable extension\f[R].
767 \f[B]leading_zero()\f[R]: \f[B]0\f[R] if leading zeroes are not enabled
768 with the \f[B]\-z\f[R] or \f[B]\[en]leading\-zeroes\f[R] options,
769 non\-zero otherwise.
770 See the \f[B]OPTIONS\f[R] section.
771 This is a \f[B]non\-portable extension\f[R].
773 \f[B]rand()\f[R]: A pseudo\-random integer between \f[B]0\f[R]
774 (inclusive) and \f[B]BC_RAND_MAX\f[R] (inclusive).
775 Using this operand will change the value of \f[B]seed\f[R].
776 This is a \f[B]non\-portable extension\f[R].
778 \f[B]irand(E)\f[R]: A pseudo\-random integer between \f[B]0\f[R]
779 (inclusive) and the value of \f[B]E\f[R] (exclusive).
780 If \f[B]E\f[R] is negative or is a non\-integer (\f[B]E\f[R]\[cq]s
781 \f[I]scale\f[R] is not \f[B]0\f[R]), an error is raised, and bc(1)
782 resets (see the \f[B]RESET\f[R] section) while \f[B]seed\f[R] remains
784 If \f[B]E\f[R] is larger than \f[B]BC_RAND_MAX\f[R], the higher bound is
785 honored by generating several pseudo\-random integers, multiplying them
786 by appropriate powers of \f[B]BC_RAND_MAX+1\f[R], and adding them
790 Using this operand will change the value of \f[B]seed\f[R], unless the
791 value of \f[B]E\f[R] is \f[B]0\f[R] or \f[B]1\f[R].
792 In that case, \f[B]0\f[R] is returned, and \f[B]seed\f[R] is
793 \f[I]not\f[R] changed.
794 This is a \f[B]non\-portable extension\f[R].
796 \f[B]maxrand()\f[R]: The max integer returned by \f[B]rand()\f[R].
797 This is a \f[B]non\-portable extension\f[R].
799 The integers generated by \f[B]rand()\f[R] and \f[B]irand(E)\f[R] are
801 the pseudo\-random number generator.
803 \f[B]Note\f[R]: The values returned by the pseudo\-random number
804 generator with \f[B]rand()\f[R] and \f[B]irand(E)\f[R] are guaranteed to
805 \f[I]NOT\f[R] be cryptographically secure.
806 This is a consequence of using a seeded pseudo\-random number generator.
807 However, they \f[I]are\f[R] guaranteed to be reproducible with identical
808 \f[B]seed\f[R] values.
809 This means that the pseudo\-random values from bc(1) should only be used
810 where a reproducible stream of pseudo\-random numbers is
811 \f[I]ESSENTIAL\f[R].
812 In any other case, use a non\-seeded pseudo\-random number generator.
815 \f[B]1\f[R] period for a radix.
816 Numbers can have up to \f[B]BC_NUM_MAX\f[R] digits.
817 Uppercase letters are equal to \f[B]9\f[R] plus their position in the
818 alphabet, starting from \f[B]1\f[R] (i.e., \f[B]A\f[R] equals
819 \f[B]10\f[R], or \f[B]9+1\f[R]).
822 \f[B]ibase\f[R] (i.e., they are greater than or equal to the current
823 value of \f[B]ibase\f[R]), then the behavior depends on the existence of
824 the \f[B]\-c\f[R]/\f[B]\-\-digit\-clamp\f[R] or
825 \f[B]\-C\f[R]/\f[B]\-\-no\-digit\-clamp\f[R] options (see the
826 \f[B]OPTIONS\f[R] section), the existence and setting of the
827 \f[B]BC_DIGIT_CLAMP\f[R] environment variable (see the \f[B]ENVIRONMENT
828 VARIABLES\f[R] section), or the default, which can be queried with the
829 \f[B]\-h\f[R]/\f[B]\-\-help\f[R] option.
832 equal to the current value of \f[B]ibase\f[R] are not changed.
834 \f[B]ibase\f[R] and added into the number.
835 This means that, with an \f[B]ibase\f[R] of \f[B]3\f[R], the number
836 \f[B]AB\f[R] is equal to \f[B]3\[ha]1*A+3\[ha]0*B\f[R], which is
837 \f[B]3\f[R] times \f[B]10\f[R] plus \f[B]11\f[R], or \f[B]41\f[R].
840 to the current value of \f[B]ibase\f[R] are set to the value of the
841 highest valid digit in \f[B]ibase\f[R] before being multiplied by the
842 appropriate power of \f[B]ibase\f[R] and added into the number.
843 This means that, with an \f[B]ibase\f[R] of \f[B]3\f[R], the number
844 \f[B]AB\f[R] is equal to \f[B]3\[ha]1*2+3\[ha]0*2\f[R], which is
845 \f[B]3\f[R] times \f[B]2\f[R] plus \f[B]2\f[R], or \f[B]8\f[R].
847 There is one exception to clamping: single\-character numbers (i.e.,
848 \f[B]A\f[R] alone).
850 in the highest possible \f[B]ibase\f[R].
851 This means that \f[B]A\f[R] alone always equals decimal \f[B]10\f[R] and
852 \f[B]Z\f[R] alone always equals decimal \f[B]35\f[R].
854 and is meant to provide an easy way to set the current \f[B]ibase\f[R]
855 (with the \f[B]i\f[R] command) regardless of the current value of
856 \f[B]ibase\f[R].
859 leading zero, i.e., for \f[B]A\f[R], use \f[B]0A\f[R].
862 These have the form \f[B]<number>e<integer>\f[R].
863 The exponent (the portion after the \f[B]e\f[R]) must be an integer.
864 An example is \f[B]1.89237e9\f[R], which is equal to
865 \f[B]1892370000\f[R].
866 Negative exponents are also allowed, so \f[B]4.2890e\-3\f[R] is equal to
867 \f[B]0.0042890\f[R].
869 Using scientific notation is an error or warning if the \f[B]\-s\f[R] or
870 \f[B]\-w\f[R], respectively, command\-line options (or equivalents) are
873 \f[B]WARNING\f[R]: Both the number and the exponent in scientific
874 notation are interpreted according to the current \f[B]ibase\f[R], but
875 the number is still multiplied by \f[B]10\[ha]exponent\f[R] regardless
876 of the current \f[B]ibase\f[R].
877 For example, if \f[B]ibase\f[R] is \f[B]16\f[R] and bc(1) is given the
878 number string \f[B]FFeA\f[R], the resulting decimal number will be
879 \f[B]2550000000000\f[R], and if bc(1) is given the number string
880 \f[B]10e\-4\f[R], the resulting decimal number will be \f[B]0.0016\f[R].
882 Accepting input as scientific notation is a \f[B]non\-portable
883 extension\f[R].
889 \f[B]++\f[R] \f[B]\-\-\f[R]
895 Description: \f[B]increment\f[R], \f[B]decrement\f[R]
898 \f[B]\-\f[R] \f[B]!\f[R]
904 Description: \f[B]negation\f[R], \f[B]boolean not\f[R]
907 \f[B]$\f[R]
913 Description: \f[B]truncation\f[R]
916 \f[B]\[at]\f[R]
922 Description: \f[B]set precision\f[R]
925 \f[B]\[ha]\f[R]
931 Description: \f[B]power\f[R]
934 \f[B]*\f[R] \f[B]/\f[R] \f[B]%\f[R]
940 Description: \f[B]multiply\f[R], \f[B]divide\f[R], \f[B]modulus\f[R]
943 \f[B]+\f[R] \f[B]\-\f[R]
949 Description: \f[B]add\f[R], \f[B]subtract\f[R]
952 \f[B]<<\f[R] \f[B]>>\f[R]
958 Description: \f[B]shift left\f[R], \f[B]shift right\f[R]
961 \f[B]=\f[R] \f[B]<<=\f[R] \f[B]>>=\f[R] \f[B]+=\f[R] \f[B]\-=\f[R] \f[B]*=\f[R] \f[B]/=\f[R] \f[B]%…
967 Description: \f[B]assignment\f[R]
970 \f[B]==\f[R] \f[B]<=\f[R] \f[B]>=\f[R] \f[B]!=\f[R] \f[B]<\f[R] \f[B]>\f[R]
976 Description: \f[B]relational\f[R]
979 \f[B]&&\f[R]
985 Description: \f[B]boolean and\f[R]
988 \f[B]||\f[R]
994 Description: \f[B]boolean or\f[R]
999 \f[B]++\f[R] \f[B]\-\-\f[R]
1000 The prefix and postfix \f[B]increment\f[R] and \f[B]decrement\f[R]
1002 expression (see the \f[I]Named Expressions\f[R] subsection) as an
1010 \f[B]\-\f[R]
1011 The \f[B]negation\f[R] operator returns \f[B]0\f[R] if a user attempts
1012 to negate any expression with the value \f[B]0\f[R].
1015 \f[B]!\f[R]
1016 The \f[B]boolean not\f[R] operator returns \f[B]1\f[R] if the expression
1017 is \f[B]0\f[R], or \f[B]0\f[R] otherwise.
1020 \f[B]Warning\f[R]: This operator has a \f[B]different precedence\f[R]
1024 This is a \f[B]non\-portable extension\f[R].
1027 \f[B]$\f[R]
1028 The \f[B]truncation\f[R] operator returns a copy of the given expression
1029 with all of its \f[I]scale\f[R] removed.
1032 This is a \f[B]non\-portable extension\f[R].
1035 \f[B]\[at]\f[R]
1036 The \f[B]set precision\f[R] operator takes two expressions and returns a
1037 copy of the first with its \f[I]scale\f[R] equal to the value of the
1040 the \f[I]scale\f[R] of the first expression matches the value of the
1045 The second expression must be an integer (no \f[I]scale\f[R]) and
1046 non\-negative.
1048 This is a \f[B]non\-portable extension\f[R].
1051 \f[B]\[ha]\f[R]
1052 The \f[B]power\f[R] operator (not the \f[B]exclusive or\f[R] operator,
1055 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
1058 The second expression must be an integer (no \f[I]scale\f[R]), and if it
1059 is negative, the first value must be non\-zero.
1062 \f[B]*\f[R]
1063 The \f[B]multiply\f[R] operator takes two expressions, multiplies them,
1065 If \f[B]a\f[R] is the \f[I]scale\f[R] of the first expression and
1066 \f[B]b\f[R] is the \f[I]scale\f[R] of the second expression, the
1067 \f[I]scale\f[R] of the result is equal to
1068 \f[B]min(a+b,max(scale,a,b))\f[R] where \f[B]min()\f[R] and
1069 \f[B]max()\f[R] return the obvious values.
1071 \f[B]/\f[R]
1072 The \f[B]divide\f[R] operator takes two expressions, divides them, and
1074 The \f[I]scale\f[R] of the result shall be the value of \f[B]scale\f[R].
1077 The second expression must be non\-zero.
1080 \f[B]%\f[R]
1081 The \f[B]modulus\f[R] operator takes two expressions, \f[B]a\f[R] and
1082 \f[B]b\f[R], and evaluates them by 1) Computing \f[B]a/b\f[R] to current
1083 \f[B]scale\f[R] and 2) Using the result of step 1 to calculate
1084 \f[B]a\-(a/b)*b\f[R] to \f[I]scale\f[R]
1085 \f[B]max(scale+scale(b),scale(a))\f[R].
1088 The second expression must be non\-zero.
1091 \f[B]+\f[R]
1092 The \f[B]add\f[R] operator takes two expressions, \f[B]a\f[R] and
1093 \f[B]b\f[R], and returns the sum, with a \f[I]scale\f[R] equal to the
1094 max of the \f[I]scale\f[R]s of \f[B]a\f[R] and \f[B]b\f[R].
1096 \f[B]\-\f[R]
1097 The \f[B]subtract\f[R] operator takes two expressions, \f[B]a\f[R] and
1098 \f[B]b\f[R], and returns the difference, with a \f[I]scale\f[R] equal to
1099 the max of the \f[I]scale\f[R]s of \f[B]a\f[R] and \f[B]b\f[R].
1101 \f[B]<<\f[R]
1102 The \f[B]left shift\f[R] operator takes two expressions, \f[B]a\f[R] and
1103 \f[B]b\f[R], and returns a copy of the value of \f[B]a\f[R] with its
1104 decimal point moved \f[B]b\f[R] places to the right.
1107 The second expression must be an integer (no \f[I]scale\f[R]) and
1108 non\-negative.
1110 This is a \f[B]non\-portable extension\f[R].
1113 \f[B]>>\f[R]
1114 The \f[B]right shift\f[R] operator takes two expressions, \f[B]a\f[R]
1115 and \f[B]b\f[R], and returns a copy of the value of \f[B]a\f[R] with its
1116 decimal point moved \f[B]b\f[R] places to the left.
1119 The second expression must be an integer (no \f[I]scale\f[R]) and
1120 non\-negative.
1122 This is a \f[B]non\-portable extension\f[R].
1125 \f[B]=\f[R] \f[B]<<=\f[R] \f[B]>>=\f[R] \f[B]+=\f[R] \f[B]\-=\f[R] \f[B]*=\f[R] \f[B]/=\f[R] \f[B]%…
1126 The \f[B]assignment\f[R] operators take two expressions, \f[B]a\f[R] and
1127 \f[B]b\f[R] where \f[B]a\f[R] is a named expression (see the \f[I]Named
1128 Expressions\f[R] subsection).
1131 For \f[B]=\f[R], \f[B]b\f[R] is copied and the result is assigned to
1132 \f[B]a\f[R].
1133 For all others, \f[B]a\f[R] and \f[B]b\f[R] are applied as operands to
1135 \f[B]a\f[R].
1137 The \f[B]assignment\f[R] operators that correspond to operators that are
1138 extensions are themselves \f[B]non\-portable extensions\f[R].
1141 \f[B]==\f[R] \f[B]<=\f[R] \f[B]>=\f[R] \f[B]!=\f[R] \f[B]<\f[R] \f[B]>\f[R]
1142 The \f[B]relational\f[R] operators compare two expressions, \f[B]a\f[R]
1143 and \f[B]b\f[R], and if the relation holds, according to C language
1144 semantics, the result is \f[B]1\f[R].
1145 Otherwise, it is \f[B]0\f[R].
1149 \f[B]assignment\f[R] operators, which means that \f[B]a=b>c\f[R] is
1150 interpreted as \f[B](a=b)>c\f[R].
1152 Also, unlike the standard (see the \f[B]STANDARDS\f[R] section)
1155 This allowance is a \f[B]non\-portable extension\f[R].
1158 \f[B]&&\f[R]
1159 The \f[B]boolean and\f[R] operator takes two expressions and returns
1160 \f[B]1\f[R] if both expressions are non\-zero, \f[B]0\f[R] otherwise.
1163 This is \f[I]not\f[R] a short\-circuit operator.
1165 This is a \f[B]non\-portable extension\f[R].
1168 \f[B]||\f[R]
1169 The \f[B]boolean or\f[R] operator takes two expressions and returns
1170 \f[B]1\f[R] if one of the expressions is non\-zero, \f[B]0\f[R]
1174 This is \f[I]not\f[R] a short\-circuit operator.
1176 This is a \f[B]non\-portable extension\f[R].
1181 \f[B]E\f[R]
1183 \f[B]{\f[R] \f[B]S\f[R] \f[B];\f[R] \&...
1184 \f[B];\f[R] \f[B]S\f[R] \f[B]}\f[R]
1186 \f[B]if\f[R] \f[B](\f[R] \f[B]E\f[R] \f[B])\f[R] \f[B]S\f[R]
1188 \f[B]if\f[R] \f[B](\f[R] \f[B]E\f[R] \f[B])\f[R] \f[B]S\f[R]
1189 \f[B]else\f[R] \f[B]S\f[R]
1191 \f[B]while\f[R] \f[B](\f[R] \f[B]E\f[R] \f[B])\f[R] \f[B]S\f[R]
1193 \f[B]for\f[R] \f[B](\f[R] \f[B]E\f[R] \f[B];\f[R] \f[B]E\f[R]
1194 \f[B];\f[R] \f[B]E\f[R] \f[B])\f[R] \f[B]S\f[R]
1198 \f[B]break\f[R]
1200 \f[B]continue\f[R]
1202 \f[B]quit\f[R]
1204 \f[B]halt\f[R]
1206 \f[B]limits\f[R]
1210 \f[B]print\f[R] \f[B]E\f[R] \f[B],\f[R] \&...
1211 \f[B],\f[R] \f[B]E\f[R]
1213 \f[B]stream\f[R] \f[B]E\f[R] \f[B],\f[R] \&...
1214 \f[B],\f[R] \f[B]E\f[R]
1216 \f[B]I()\f[R], \f[B]I(E)\f[R], \f[B]I(E, E)\f[R], and so on, where
1217 \f[B]I\f[R] is an identifier for a \f[B]void\f[R] function (see the
1218 \f[I]Void Functions\f[R] subsection of the \f[B]FUNCTIONS\f[R] section).
1219 The \f[B]E\f[R] argument(s) may also be arrays of the form
1220 \f[B]I[]\f[R], which will automatically be turned into array references
1221 (see the \f[I]Array References\f[R] subsection of the
1222 \f[B]FUNCTIONS\f[R] section) if the corresponding parameter in the
1225 Numbers 4, 9, 11, 12, 14, 15, and 16 are \f[B]non\-portable
1226 extensions\f[R].
1228 Also, as a \f[B]non\-portable extension\f[R], any or all of the
1231 constant \f[B]1\f[R].
1233 The \f[B]break\f[R] statement causes a loop to stop iterating and resume
1237 The \f[B]continue\f[R] statement causes a loop iteration to stop early
1242 The \f[B]if\f[R] \f[B]else\f[R] statement does the same thing as in C.
1244 The \f[B]quit\f[R] statement causes bc(1) to quit, even if it is on a
1245 branch that will not be executed (it is a compile\-time command).
1247 \f[B]Warning\f[R]: The behavior of this bc(1) on \f[B]quit\f[R] is
1250 line that a \f[B]quit\f[R] command is on.
1252 occur before the \f[B]quit\f[R] statement before exiting.
1261 print \f[B]0\f[R], \f[B]1\f[R], and \f[B]2\f[R] on successive lines
1264 The \f[B]halt\f[R] statement causes bc(1) to quit, if it is executed.
1265 (Unlike \f[B]quit\f[R] if it is on a branch of an \f[B]if\f[R] statement
1268 The \f[B]limits\f[R] statement prints the limits that this bc(1) is
1270 This is like the \f[B]quit\f[R] statement in that it is a compile\-time
1277 Scientific notation is activated by assigning \f[B]0\f[R] to
1278 \f[B]obase\f[R], and engineering notation is activated by assigning
1279 \f[B]1\f[R] to \f[B]obase\f[R].
1280 To deactivate them, just assign a different value to \f[B]obase\f[R].
1283 run with either the \f[B]\-s\f[R] or \f[B]\-w\f[R] command\-line options
1287 \f[B]non\-portable extension\f[R].
1302 resets (see the \f[B]RESET\f[R] section).
1305 functions are \f[B]non\-portable extensions\f[R].
1307 The \[lq]expressions\[rq] in a \f[B]print\f[R] statement may also be
1314 \f[B]\[rs]a\f[R]: \f[B]\[rs]a\f[R]
1316 \f[B]\[rs]b\f[R]: \f[B]\[rs]b\f[R]
1318 \f[B]\[rs]\[rs]\f[R]: \f[B]\[rs]\f[R]
1320 \f[B]\[rs]e\f[R]: \f[B]\[rs]\f[R]
1322 \f[B]\[rs]f\f[R]: \f[B]\[rs]f\f[R]
1324 \f[B]\[rs]n\f[R]: \f[B]\[rs]n\f[R]
1326 \f[B]\[rs]q\f[R]: \f[B]\[lq]\f[R]
1328 \f[B]\[rs]r\f[R]: \f[B]\[rs]r\f[R]
1330 \f[B]\[rs]t\f[R]: \f[B]\[rs]t\f[R]
1333 character to be printed as\-is.
1335 Any non\-string expression in a print statement shall be assigned to
1336 \f[B]last\f[R], like any other expression that is printed.
1338 The expressions in a \f[B]stream\f[R] statement may also be strings.
1340 If a \f[B]stream\f[R] statement is given a string, it prints the string
1342 In other words, the \f[B]stream\f[R] statement prints strings normally,
1345 If a \f[B]stream\f[R] statement is given a number, a copy of it is
1347 The result is then printed as though \f[B]obase\f[R] is \f[B]256\f[R]
1348 and each digit is interpreted as an 8\-bit ASCII character, making it a
1353 This means, for example, assuming that \f[B]i\f[R] is equal to
1354 \f[B]0\f[R], in the expression
1360 the first (or 0th) element of \f[B]a\f[R] is set to \f[B]1\f[R], and
1361 \f[B]i\f[R] is equal to \f[B]2\f[R] at the end of the expression.
1364 Thus, assuming \f[B]i\f[R] is equal to \f[B]0\f[R], this means that in
1371 the first argument passed to \f[B]x()\f[R] is \f[B]0\f[R], and the
1372 second argument is \f[B]1\f[R], while \f[B]i\f[R] is equal to
1373 \f[B]2\f[R] before the function starts executing.
1385 Any \f[B]I\f[R] in the parameter list or \f[B]auto\f[R] list may be
1386 replaced with \f[B]I[]\f[R] to make a parameter or \f[B]auto\f[R] var an
1387 array, and any \f[B]I\f[R] in the parameter list may be replaced with
1388 \f[B]*I[]\f[R] to make a parameter an array reference.
1390 asterisk in the call; they must be called with just \f[B]I[]\f[R] like
1394 As a \f[B]non\-portable extension\f[R], the opening brace of a
1395 \f[B]define\f[R] statement may appear on the next line.
1397 As a \f[B]non\-portable extension\f[R], the return statement may also be
1400 \f[B]return\f[R]
1402 \f[B]return\f[R] \f[B](\f[R] \f[B])\f[R]
1404 \f[B]return\f[R] \f[B]E\f[R]
1406 The first two, or not specifying a \f[B]return\f[R] statement, is
1407 equivalent to \f[B]return (0)\f[R], unless the function is a
1408 \f[B]void\f[R] function (see the \f[I]Void Functions\f[R] subsection
1411 Functions can also be \f[B]void\f[R] functions, defined as follows:
1424 Void functions can only use the first two \f[B]return\f[R] statements
1429 possible to have variables, arrays, and functions named \f[B]void\f[R].
1431 \f[B]define\f[R] keyword.
1433 This is a \f[B]non\-portable extension\f[R].
1442 it is a \f[B]reference\f[R].
1448 This is a \f[B]non\-portable extension\f[R].
1451 library (see the \f[I]Extended Library\f[R] subsection below), are
1452 available when the \f[B]\-l\f[R] or \f[B]\-\-mathlib\f[R] command\-line
1454 when the \f[B]\-s\f[R] option, the \f[B]\-w\f[R] option, or equivalents
1457 The standard (see the \f[B]STANDARDS\f[R] section) defines the following
1460 \f[B]s(x)\f[R]
1461 Returns the sine of \f[B]x\f[R], which is assumed to be in radians.
1465 Functions\f[R] subsection below).
1468 \f[B]c(x)\f[R]
1469 Returns the cosine of \f[B]x\f[R], which is assumed to be in radians.
1473 Functions\f[R] subsection below).
1476 \f[B]a(x)\f[R]
1477 Returns the arctangent of \f[B]x\f[R], in radians.
1481 Functions\f[R] subsection below).
1484 \f[B]l(x)\f[R]
1485 Returns the natural logarithm of \f[B]x\f[R].
1489 Functions\f[R] subsection below).
1492 \f[B]e(x)\f[R]
1493 Returns the mathematical constant \f[B]e\f[R] raised to the power of
1494 \f[B]x\f[R].
1498 Functions\f[R] subsection below).
1501 \f[B]j(x, n)\f[R]
1502 Returns the bessel integer order \f[B]n\f[R] (truncated) of \f[B]x\f[R].
1506 Functions\f[R] subsection below).
1509 The extended library is \f[I]not\f[R] loaded when the
1510 \f[B]\-s\f[R]/\f[B]\-\-standard\f[R] or \f[B]\-w\f[R]/\f[B]\-\-warn\f[R]
1512 standard (see the \f[B]STANDARDS\f[R] section).
1514 The extended library is a \f[B]non\-portable extension\f[R].
1516 \f[B]p(x, y)\f[R]
1517 Calculates \f[B]x\f[R] to the power of \f[B]y\f[R], even if \f[B]y\f[R]
1519 \f[B]scale\f[R].
1522 It is an error if \f[B]y\f[R] is negative and \f[B]x\f[R] is
1523 \f[B]0\f[R].
1526 Functions\f[R] subsection below).
1529 \f[B]r(x, p)\f[R]
1530 Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
1531 the rounding mode round half away from \f[B]0\f[R]
1534 \f[B]ceil(x, p)\f[R]
1535 Returns \f[B]x\f[R] rounded to \f[B]p\f[R] decimal places according to
1536 the rounding mode round away from \f[B]0\f[R]
1539 \f[B]f(x)\f[R]
1540 Returns the factorial of the truncated absolute value of \f[B]x\f[R].
1542 \f[B]max(a, b)\f[R]
1543 Returns \f[B]a\f[R] if \f[B]a\f[R] is greater than \f[B]b\f[R];
1544 otherwise, returns \f[B]b\f[R].
1546 \f[B]min(a, b)\f[R]
1547 Returns \f[B]a\f[R] if \f[B]a\f[R] is less than \f[B]b\f[R]; otherwise,
1548 returns \f[B]b\f[R].
1550 \f[B]perm(n, k)\f[R]
1551 Returns the permutation of the truncated absolute value of \f[B]n\f[R]
1552 of the truncated absolute value of \f[B]k\f[R], if \f[B]k <= n\f[R].
1553 If not, it returns \f[B]0\f[R].
1555 \f[B]comb(n, k)\f[R]
1556 Returns the combination of the truncated absolute value of \f[B]n\f[R]
1557 of the truncated absolute value of \f[B]k\f[R], if \f[B]k <= n\f[R].
1558 If not, it returns \f[B]0\f[R].
1560 \f[B]fib(n)\f[R]
1562 \f[B]n\f[R].
1564 \f[B]l2(x)\f[R]
1565 Returns the logarithm base \f[B]2\f[R] of \f[B]x\f[R].
1569 Functions\f[R] subsection below).
1572 \f[B]l10(x)\f[R]
1573 Returns the logarithm base \f[B]10\f[R] of \f[B]x\f[R].
1577 Functions\f[R] subsection below).
1580 \f[B]log(x, b)\f[R]
1581 Returns the logarithm base \f[B]b\f[R] of \f[B]x\f[R].
1585 Functions\f[R] subsection below).
1588 \f[B]cbrt(x)\f[R]
1589 Returns the cube root of \f[B]x\f[R].
1591 \f[B]root(x, n)\f[R]
1592 Calculates the truncated value of \f[B]n\f[R], \f[B]r\f[R], and returns
1593 the \f[B]r\f[R]th root of \f[B]x\f[R] to the current \f[B]scale\f[R].
1596 If \f[B]r\f[R] is \f[B]0\f[R] or negative, this raises an error and
1597 causes bc(1) to reset (see the \f[B]RESET\f[R] section).
1598 It also raises an error and causes bc(1) to reset if \f[B]r\f[R] is even
1599 and \f[B]x\f[R] is negative.
1602 \f[B]gcd(a, b)\f[R]
1604 value of \f[B]a\f[R] and the truncated absolute value of \f[B]b\f[R].
1606 \f[B]lcm(a, b)\f[R]
1608 \f[B]a\f[R] and the truncated absolute value of \f[B]b\f[R].
1610 \f[B]pi(p)\f[R]
1611 Returns \f[B]pi\f[R] to \f[B]p\f[R] decimal places.
1615 Functions\f[R] subsection below).
1618 \f[B]t(x)\f[R]
1619 Returns the tangent of \f[B]x\f[R], which is assumed to be in radians.
1623 Functions\f[R] subsection below).
1626 \f[B]a2(y, x)\f[R]
1627 Returns the arctangent of \f[B]y/x\f[R], in radians.
1628 If both \f[B]y\f[R] and \f[B]x\f[R] are equal to \f[B]0\f[R], it raises
1629 an error and causes bc(1) to reset (see the \f[B]RESET\f[R] section).
1630 Otherwise, if \f[B]x\f[R] is greater than \f[B]0\f[R], it returns
1631 \f[B]a(y/x)\f[R].
1632 If \f[B]x\f[R] is less than \f[B]0\f[R], and \f[B]y\f[R] is greater than
1633 or equal to \f[B]0\f[R], it returns \f[B]a(y/x)+pi\f[R].
1634 If \f[B]x\f[R] is less than \f[B]0\f[R], and \f[B]y\f[R] is less than
1635 \f[B]0\f[R], it returns \f[B]a(y/x)\-pi\f[R].
1636 If \f[B]x\f[R] is equal to \f[B]0\f[R], and \f[B]y\f[R] is greater than
1637 \f[B]0\f[R], it returns \f[B]pi/2\f[R].
1638 If \f[B]x\f[R] is equal to \f[B]0\f[R], and \f[B]y\f[R] is less than
1639 \f[B]0\f[R], it returns \f[B]\-pi/2\f[R].
1642 This function is the same as the \f[B]atan2()\f[R] function in many
1646 Functions\f[R] subsection below).
1649 \f[B]sin(x)\f[R]
1650 Returns the sine of \f[B]x\f[R], which is assumed to be in radians.
1653 This is an alias of \f[B]s(x)\f[R].
1656 Functions\f[R] subsection below).
1659 \f[B]cos(x)\f[R]
1660 Returns the cosine of \f[B]x\f[R], which is assumed to be in radians.
1663 This is an alias of \f[B]c(x)\f[R].
1666 Functions\f[R] subsection below).
1669 \f[B]tan(x)\f[R]
1670 Returns the tangent of \f[B]x\f[R], which is assumed to be in radians.
1673 If \f[B]x\f[R] is equal to \f[B]1\f[R] or \f[B]\-1\f[R], this raises an
1674 error and causes bc(1) to reset (see the \f[B]RESET\f[R] section).
1676 This is an alias of \f[B]t(x)\f[R].
1679 Functions\f[R] subsection below).
1682 \f[B]atan(x)\f[R]
1683 Returns the arctangent of \f[B]x\f[R], in radians.
1686 This is an alias of \f[B]a(x)\f[R].
1689 Functions\f[R] subsection below).
1692 \f[B]atan2(y, x)\f[R]
1693 Returns the arctangent of \f[B]y/x\f[R], in radians.
1694 If both \f[B]y\f[R] and \f[B]x\f[R] are equal to \f[B]0\f[R], it raises
1695 an error and causes bc(1) to reset (see the \f[B]RESET\f[R] section).
1696 Otherwise, if \f[B]x\f[R] is greater than \f[B]0\f[R], it returns
1697 \f[B]a(y/x)\f[R].
1698 If \f[B]x\f[R] is less than \f[B]0\f[R], and \f[B]y\f[R] is greater than
1699 or equal to \f[B]0\f[R], it returns \f[B]a(y/x)+pi\f[R].
1700 If \f[B]x\f[R] is less than \f[B]0\f[R], and \f[B]y\f[R] is less than
1701 \f[B]0\f[R], it returns \f[B]a(y/x)\-pi\f[R].
1702 If \f[B]x\f[R] is equal to \f[B]0\f[R], and \f[B]y\f[R] is greater than
1703 \f[B]0\f[R], it returns \f[B]pi/2\f[R].
1704 If \f[B]x\f[R] is equal to \f[B]0\f[R], and \f[B]y\f[R] is less than
1705 \f[B]0\f[R], it returns \f[B]\-pi/2\f[R].
1708 This function is the same as the \f[B]atan2()\f[R] function in many
1711 This is an alias of \f[B]a2(y, x)\f[R].
1714 Functions\f[R] subsection below).
1717 \f[B]r2d(x)\f[R]
1718 Converts \f[B]x\f[R] from radians to degrees and returns the result.
1722 Functions\f[R] subsection below).
1725 \f[B]d2r(x)\f[R]
1726 Converts \f[B]x\f[R] from degrees to radians and returns the result.
1730 Functions\f[R] subsection below).
1733 \f[B]frand(p)\f[R]
1734 Generates a pseudo\-random number between \f[B]0\f[R] (inclusive) and
1735 \f[B]1\f[R] (exclusive) with the number of decimal digits after the
1736 decimal point equal to the truncated absolute value of \f[B]p\f[R].
1737 If \f[B]p\f[R] is not \f[B]0\f[R], then calling this function will
1738 change the value of \f[B]seed\f[R].
1739 If \f[B]p\f[R] is \f[B]0\f[R], then \f[B]0\f[R] is returned, and
1740 \f[B]seed\f[R] is \f[I]not\f[R] changed.
1742 \f[B]ifrand(i, p)\f[R]
1743 Generates a pseudo\-random number that is between \f[B]0\f[R]
1744 (inclusive) and the truncated absolute value of \f[B]i\f[R] (exclusive)
1746 truncated absolute value of \f[B]p\f[R].
1747 If the absolute value of \f[B]i\f[R] is greater than or equal to
1748 \f[B]2\f[R], and \f[B]p\f[R] is not \f[B]0\f[R], then calling this
1749 function will change the value of \f[B]seed\f[R]; otherwise, \f[B]0\f[R]
1750 is returned, and \f[B]seed\f[R] is not changed.
1752 \f[B]i2rand(a, b)\f[R]
1753 Takes the truncated value of \f[B]a\f[R] and \f[B]b\f[R] and uses them
1754 as inclusive bounds to enerate a pseudo\-random integer.
1755 If the difference of the truncated values of \f[B]a\f[R] and \f[B]b\f[R]
1756 is \f[B]0\f[R], then the truncated value is returned, and \f[B]seed\f[R]
1757 is \f[I]not\f[R] changed.
1758 Otherwise, this function will change the value of \f[B]seed\f[R].
1760 \f[B]srand(x)\f[R]
1761 Returns \f[B]x\f[R] with its sign flipped with probability
1762 \f[B]0.5\f[R].
1763 In other words, it randomizes the sign of \f[B]x\f[R].
1765 \f[B]brand()\f[R]
1766 Returns a random boolean value (either \f[B]0\f[R] or \f[B]1\f[R]).
1768 \f[B]band(a, b)\f[R]
1769 Takes the truncated absolute value of both \f[B]a\f[R] and \f[B]b\f[R]
1770 and calculates and returns the result of the bitwise \f[B]and\f[R]
1775 \f[B]s2u(x)\f[R] to convert.
1778 \f[B]bor(a, b)\f[R]
1779 Takes the truncated absolute value of both \f[B]a\f[R] and \f[B]b\f[R]
1780 and calculates and returns the result of the bitwise \f[B]or\f[R]
1785 \f[B]s2u(x)\f[R] to convert.
1788 \f[B]bxor(a, b)\f[R]
1789 Takes the truncated absolute value of both \f[B]a\f[R] and \f[B]b\f[R]
1790 and calculates and returns the result of the bitwise \f[B]xor\f[R]
1795 \f[B]s2u(x)\f[R] to convert.
1798 \f[B]bshl(a, b)\f[R]
1799 Takes the truncated absolute value of both \f[B]a\f[R] and \f[B]b\f[R]
1800 and calculates and returns the result of \f[B]a\f[R] bit\-shifted left
1801 by \f[B]b\f[R] places.
1805 \f[B]s2u(x)\f[R] to convert.
1808 \f[B]bshr(a, b)\f[R]
1809 Takes the truncated absolute value of both \f[B]a\f[R] and \f[B]b\f[R]
1810 and calculates and returns the truncated result of \f[B]a\f[R]
1811 bit\-shifted right by \f[B]b\f[R] places.
1815 \f[B]s2u(x)\f[R] to convert.
1818 \f[B]bnotn(x, n)\f[R]
1819 Takes the truncated absolute value of \f[B]x\f[R] and does a bitwise not
1821 value of \f[B]n\f[R].
1825 \f[B]s2u(x)\f[R] to convert.
1828 \f[B]bnot8(x)\f[R]
1829 Does a bitwise not of the truncated absolute value of \f[B]x\f[R] as
1830 though it has \f[B]8\f[R] binary digits (\f[B]1\f[R] unsigned byte).
1834 \f[B]s2u(x)\f[R] to convert.
1837 \f[B]bnot16(x)\f[R]
1838 Does a bitwise not of the truncated absolute value of \f[B]x\f[R] as
1839 though it has \f[B]16\f[R] binary digits (\f[B]2\f[R] unsigned bytes).
1843 \f[B]s2u(x)\f[R] to convert.
1846 \f[B]bnot32(x)\f[R]
1847 Does a bitwise not of the truncated absolute value of \f[B]x\f[R] as
1848 though it has \f[B]32\f[R] binary digits (\f[B]4\f[R] unsigned bytes).
1852 \f[B]s2u(x)\f[R] to convert.
1855 \f[B]bnot64(x)\f[R]
1856 Does a bitwise not of the truncated absolute value of \f[B]x\f[R] as
1857 though it has \f[B]64\f[R] binary digits (\f[B]8\f[R] unsigned bytes).
1861 \f[B]s2u(x)\f[R] to convert.
1864 \f[B]bnot(x)\f[R]
1865 Does a bitwise not of the truncated absolute value of \f[B]x\f[R] as
1870 \f[B]s2u(x)\f[R] to convert.
1873 \f[B]brevn(x, n)\f[R]
1874 Runs a bit reversal on the truncated absolute value of \f[B]x\f[R] as
1875 though it has the same number of 8\-bit bytes as the truncated absolute
1876 value of \f[B]n\f[R].
1880 \f[B]s2u(x)\f[R] to convert.
1883 \f[B]brev8(x)\f[R]
1884 Runs a bit reversal on the truncated absolute value of \f[B]x\f[R] as
1885 though it has 8 binary digits (\f[B]1\f[R] unsigned byte).
1889 \f[B]s2u(x)\f[R] to convert.
1892 \f[B]brev16(x)\f[R]
1893 Runs a bit reversal on the truncated absolute value of \f[B]x\f[R] as
1894 though it has 16 binary digits (\f[B]2\f[R] unsigned bytes).
1898 \f[B]s2u(x)\f[R] to convert.
1901 \f[B]brev32(x)\f[R]
1902 Runs a bit reversal on the truncated absolute value of \f[B]x\f[R] as
1903 though it has 32 binary digits (\f[B]4\f[R] unsigned bytes).
1907 \f[B]s2u(x)\f[R] to convert.
1910 \f[B]brev64(x)\f[R]
1911 Runs a bit reversal on the truncated absolute value of \f[B]x\f[R] as
1912 though it has 64 binary digits (\f[B]8\f[R] unsigned bytes).
1916 \f[B]s2u(x)\f[R] to convert.
1919 \f[B]brev(x)\f[R]
1920 Runs a bit reversal on the truncated absolute value of \f[B]x\f[R] as
1925 \f[B]s2u(x)\f[R] to convert.
1928 \f[B]broln(x, p, n)\f[R]
1930 \f[B]x\f[R], as though it has the same number of unsigned 8\-bit bytes
1931 as the truncated absolute value of \f[B]n\f[R], by the number of places
1932 equal to the truncated absolute value of \f[B]p\f[R] modded by the
1933 \f[B]2\f[R] to the power of the number of binary digits in \f[B]n\f[R]
1934 8\-bit bytes.
1938 \f[B]s2u(x)\f[R] to convert.
1941 \f[B]brol8(x, p)\f[R]
1943 \f[B]x\f[R], as though it has \f[B]8\f[R] binary digits (\f[B]1\f[R]
1945 value of \f[B]p\f[R] modded by \f[B]2\f[R] to the power of \f[B]8\f[R].
1949 \f[B]s2u(x)\f[R] to convert.
1952 \f[B]brol16(x, p)\f[R]
1954 \f[B]x\f[R], as though it has \f[B]16\f[R] binary digits (\f[B]2\f[R]
1956 value of \f[B]p\f[R] modded by \f[B]2\f[R] to the power of \f[B]16\f[R].
1960 \f[B]s2u(x)\f[R] to convert.
1963 \f[B]brol32(x, p)\f[R]
1965 \f[B]x\f[R], as though it has \f[B]32\f[R] binary digits (\f[B]4\f[R]
1967 value of \f[B]p\f[R] modded by \f[B]2\f[R] to the power of \f[B]32\f[R].
1971 \f[B]s2u(x)\f[R] to convert.
1974 \f[B]brol64(x, p)\f[R]
1976 \f[B]x\f[R], as though it has \f[B]64\f[R] binary digits (\f[B]8\f[R]
1978 value of \f[B]p\f[R] modded by \f[B]2\f[R] to the power of \f[B]64\f[R].
1982 \f[B]s2u(x)\f[R] to convert.
1985 \f[B]brol(x, p)\f[R]
1987 \f[B]x\f[R], as though it has the minimum number of power of two
1988 unsigned 8\-bit bytes, by the number of places equal to the truncated
1989 absolute value of \f[B]p\f[R] modded by 2 to the power of the number of
1990 binary digits in the minimum number of 8\-bit bytes.
1994 \f[B]s2u(x)\f[R] to convert.
1997 \f[B]brorn(x, p, n)\f[R]
1999 \f[B]x\f[R], as though it has the same number of unsigned 8\-bit bytes
2000 as the truncated absolute value of \f[B]n\f[R], by the number of places
2001 equal to the truncated absolute value of \f[B]p\f[R] modded by the
2002 \f[B]2\f[R] to the power of the number of binary digits in \f[B]n\f[R]
2003 8\-bit bytes.
2007 \f[B]s2u(x)\f[R] to convert.
2010 \f[B]bror8(x, p)\f[R]
2012 \f[B]x\f[R], as though it has \f[B]8\f[R] binary digits (\f[B]1\f[R]
2014 value of \f[B]p\f[R] modded by \f[B]2\f[R] to the power of \f[B]8\f[R].
2018 \f[B]s2u(x)\f[R] to convert.
2021 \f[B]bror16(x, p)\f[R]
2023 \f[B]x\f[R], as though it has \f[B]16\f[R] binary digits (\f[B]2\f[R]
2025 value of \f[B]p\f[R] modded by \f[B]2\f[R] to the power of \f[B]16\f[R].
2029 \f[B]s2u(x)\f[R] to convert.
2032 \f[B]bror32(x, p)\f[R]
2034 \f[B]x\f[R], as though it has \f[B]32\f[R] binary digits (\f[B]2\f[R]
2036 value of \f[B]p\f[R] modded by \f[B]2\f[R] to the power of \f[B]32\f[R].
2040 \f[B]s2u(x)\f[R] to convert.
2043 \f[B]bror64(x, p)\f[R]
2045 \f[B]x\f[R], as though it has \f[B]64\f[R] binary digits (\f[B]2\f[R]
2047 value of \f[B]p\f[R] modded by \f[B]2\f[R] to the power of \f[B]64\f[R].
2051 \f[B]s2u(x)\f[R] to convert.
2054 \f[B]bror(x, p)\f[R]
2056 \f[B]x\f[R], as though it has the minimum number of power of two
2057 unsigned 8\-bit bytes, by the number of places equal to the truncated
2058 absolute value of \f[B]p\f[R] modded by 2 to the power of the number of
2059 binary digits in the minimum number of 8\-bit bytes.
2063 \f[B]s2u(x)\f[R] to convert.
2066 \f[B]bmodn(x, n)\f[R]
2067 Returns the modulus of the truncated absolute value of \f[B]x\f[R] by
2068 \f[B]2\f[R] to the power of the multiplication of the truncated absolute
2069 value of \f[B]n\f[R] and \f[B]8\f[R].
2073 \f[B]s2u(x)\f[R] to convert.
2076 \f[B]bmod8(x, n)\f[R]
2077 Returns the modulus of the truncated absolute value of \f[B]x\f[R] by
2078 \f[B]2\f[R] to the power of \f[B]8\f[R].
2082 \f[B]s2u(x)\f[R] to convert.
2085 \f[B]bmod16(x, n)\f[R]
2086 Returns the modulus of the truncated absolute value of \f[B]x\f[R] by
2087 \f[B]2\f[R] to the power of \f[B]16\f[R].
2091 \f[B]s2u(x)\f[R] to convert.
2094 \f[B]bmod32(x, n)\f[R]
2095 Returns the modulus of the truncated absolute value of \f[B]x\f[R] by
2096 \f[B]2\f[R] to the power of \f[B]32\f[R].
2100 \f[B]s2u(x)\f[R] to convert.
2103 \f[B]bmod64(x, n)\f[R]
2104 Returns the modulus of the truncated absolute value of \f[B]x\f[R] by
2105 \f[B]2\f[R] to the power of \f[B]64\f[R].
2109 \f[B]s2u(x)\f[R] to convert.
2112 \f[B]bunrev(t)\f[R]
2113 Assumes \f[B]t\f[R] is a bitwise\-reversed number with an extra set bit
2123 \f[B]plz(x)\f[R]
2124 If \f[B]x\f[R] is not equal to \f[B]0\f[R] and greater that
2125 \f[B]\-1\f[R] and less than \f[B]1\f[R], it is printed with a leading
2126 zero, regardless of the use of the \f[B]\-z\f[R] option (see the
2127 \f[B]OPTIONS\f[R] section) and without a trailing newline.
2130 Otherwise, \f[B]x\f[R] is printed normally, without a trailing newline.
2133 \f[B]plznl(x)\f[R]
2134 If \f[B]x\f[R] is not equal to \f[B]0\f[R] and greater that
2135 \f[B]\-1\f[R] and less than \f[B]1\f[R], it is printed with a leading
2136 zero, regardless of the use of the \f[B]\-z\f[R] option (see the
2137 \f[B]OPTIONS\f[R] section) and with a trailing newline.
2140 Otherwise, \f[B]x\f[R] is printed normally, with a trailing newline.
2143 \f[B]pnlz(x)\f[R]
2144 If \f[B]x\f[R] is not equal to \f[B]0\f[R] and greater that
2145 \f[B]\-1\f[R] and less than \f[B]1\f[R], it is printed without a leading
2146 zero, regardless of the use of the \f[B]\-z\f[R] option (see the
2147 \f[B]OPTIONS\f[R] section) and without a trailing newline.
2150 Otherwise, \f[B]x\f[R] is printed normally, without a trailing newline.
2153 \f[B]pnlznl(x)\f[R]
2154 If \f[B]x\f[R] is not equal to \f[B]0\f[R] and greater that
2155 \f[B]\-1\f[R] and less than \f[B]1\f[R], it is printed without a leading
2156 zero, regardless of the use of the \f[B]\-z\f[R] option (see the
2157 \f[B]OPTIONS\f[R] section) and with a trailing newline.
2160 Otherwise, \f[B]x\f[R] is printed normally, with a trailing newline.
2163 \f[B]ubytes(x)\f[R]
2165 truncated absolute value of \f[B]x\f[R].
2167 \f[B]sbytes(x)\f[R]
2168 Returns the numbers of signed, two\[cq]s\-complement integer bytes
2169 required to hold the truncated value of \f[B]x\f[R].
2171 \f[B]s2u(x)\f[R]
2172 Returns \f[B]x\f[R] if it is non\-negative.
2173 If it \f[I]is\f[R] negative, then it calculates what \f[B]x\f[R] would
2174 be as a 2\[cq]s\-complement signed integer and returns the non\-negative
2177 \f[B]s2un(x,n)\f[R]
2178 Returns \f[B]x\f[R] if it is non\-negative.
2179 If it \f[I]is\f[R] negative, then it calculates what \f[B]x\f[R] would
2180 be as a 2\[cq]s\-complement signed integer with \f[B]n\f[R] bytes and
2181 returns the non\-negative integer that would have the same
2183 If \f[B]x\f[R] cannot fit into \f[B]n\f[R] 2\[cq]s\-complement signed
2186 \f[B]hex(x)\f[R]
2187 Outputs the hexadecimal (base \f[B]16\f[R]) representation of
2188 \f[B]x\f[R].
2191 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2192 subsection of the \f[B]FUNCTIONS\f[R] section).
2195 \f[B]binary(x)\f[R]
2196 Outputs the binary (base \f[B]2\f[R]) representation of \f[B]x\f[R].
2199 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2200 subsection of the \f[B]FUNCTIONS\f[R] section).
2203 \f[B]output(x, b)\f[R]
2204 Outputs the base \f[B]b\f[R] representation of \f[B]x\f[R].
2207 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2208 subsection of the \f[B]FUNCTIONS\f[R] section).
2211 \f[B]uint(x)\f[R]
2212 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2217 If \f[B]x\f[R] is not an integer or is negative, an error message is
2218 printed instead, but bc(1) is not reset (see the \f[B]RESET\f[R]
2221 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2222 subsection of the \f[B]FUNCTIONS\f[R] section).
2225 \f[B]int(x)\f[R]
2226 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2227 a signed, two\[cq]s\-complement integer in as few power of two bytes as
2232 If \f[B]x\f[R] is not an integer, an error message is printed instead,
2233 but bc(1) is not reset (see the \f[B]RESET\f[R] section).
2235 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2236 subsection of the \f[B]FUNCTIONS\f[R] section).
2239 \f[B]uintn(x, n)\f[R]
2240 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2241 an unsigned integer in \f[B]n\f[R] bytes.
2245 If \f[B]x\f[R] is not an integer, is negative, or cannot fit into
2246 \f[B]n\f[R] bytes, an error message is printed instead, but bc(1) is not
2247 reset (see the \f[B]RESET\f[R] section).
2249 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2250 subsection of the \f[B]FUNCTIONS\f[R] section).
2253 \f[B]intn(x, n)\f[R]
2254 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2255 a signed, two\[cq]s\-complement integer in \f[B]n\f[R] bytes.
2259 If \f[B]x\f[R] is not an integer or cannot fit into \f[B]n\f[R] bytes,
2261 \f[B]RESET\f[R] section).
2263 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2264 subsection of the \f[B]FUNCTIONS\f[R] section).
2267 \f[B]uint8(x)\f[R]
2268 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2269 an unsigned integer in \f[B]1\f[R] byte.
2273 If \f[B]x\f[R] is not an integer, is negative, or cannot fit into
2274 \f[B]1\f[R] byte, an error message is printed instead, but bc(1) is not
2275 reset (see the \f[B]RESET\f[R] section).
2277 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2278 subsection of the \f[B]FUNCTIONS\f[R] section).
2281 \f[B]int8(x)\f[R]
2282 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2283 a signed, two\[cq]s\-complement integer in \f[B]1\f[R] byte.
2287 If \f[B]x\f[R] is not an integer or cannot fit into \f[B]1\f[R] byte, an
2289 \f[B]RESET\f[R] section).
2291 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2292 subsection of the \f[B]FUNCTIONS\f[R] section).
2295 \f[B]uint16(x)\f[R]
2296 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2297 an unsigned integer in \f[B]2\f[R] bytes.
2301 If \f[B]x\f[R] is not an integer, is negative, or cannot fit into
2302 \f[B]2\f[R] bytes, an error message is printed instead, but bc(1) is not
2303 reset (see the \f[B]RESET\f[R] section).
2305 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2306 subsection of the \f[B]FUNCTIONS\f[R] section).
2309 \f[B]int16(x)\f[R]
2310 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2311 a signed, two\[cq]s\-complement integer in \f[B]2\f[R] bytes.
2315 If \f[B]x\f[R] is not an integer or cannot fit into \f[B]2\f[R] bytes,
2317 \f[B]RESET\f[R] section).
2319 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2320 subsection of the \f[B]FUNCTIONS\f[R] section).
2323 \f[B]uint32(x)\f[R]
2324 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2325 an unsigned integer in \f[B]4\f[R] bytes.
2329 If \f[B]x\f[R] is not an integer, is negative, or cannot fit into
2330 \f[B]4\f[R] bytes, an error message is printed instead, but bc(1) is not
2331 reset (see the \f[B]RESET\f[R] section).
2333 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2334 subsection of the \f[B]FUNCTIONS\f[R] section).
2337 \f[B]int32(x)\f[R]
2338 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2339 a signed, two\[cq]s\-complement integer in \f[B]4\f[R] bytes.
2343 If \f[B]x\f[R] is not an integer or cannot fit into \f[B]4\f[R] bytes,
2345 \f[B]RESET\f[R] section).
2347 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2348 subsection of the \f[B]FUNCTIONS\f[R] section).
2351 \f[B]uint64(x)\f[R]
2352 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2353 an unsigned integer in \f[B]8\f[R] bytes.
2357 If \f[B]x\f[R] is not an integer, is negative, or cannot fit into
2358 \f[B]8\f[R] bytes, an error message is printed instead, but bc(1) is not
2359 reset (see the \f[B]RESET\f[R] section).
2361 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2362 subsection of the \f[B]FUNCTIONS\f[R] section).
2365 \f[B]int64(x)\f[R]
2366 Outputs the representation, in binary and hexadecimal, of \f[B]x\f[R] as
2367 a signed, two\[cq]s\-complement integer in \f[B]8\f[R] bytes.
2371 If \f[B]x\f[R] is not an integer or cannot fit into \f[B]8\f[R] bytes,
2373 \f[B]RESET\f[R] section).
2375 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2376 subsection of the \f[B]FUNCTIONS\f[R] section).
2379 \f[B]hex_uint(x, n)\f[R]
2381 \f[B]x\f[R] as an unsigned integer in hexadecimal using \f[B]n\f[R]
2383 Not all of the value will be output if \f[B]n\f[R] is too small.
2386 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2387 subsection of the \f[B]FUNCTIONS\f[R] section).
2390 \f[B]binary_uint(x, n)\f[R]
2392 \f[B]x\f[R] as an unsigned integer in binary using \f[B]n\f[R] bytes.
2393 Not all of the value will be output if \f[B]n\f[R] is too small.
2396 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2397 subsection of the \f[B]FUNCTIONS\f[R] section).
2400 \f[B]output_uint(x, n)\f[R]
2402 \f[B]x\f[R] as an unsigned integer in the current \f[B]obase\f[R] (see
2403 the \f[B]SYNTAX\f[R] section) using \f[B]n\f[R] bytes.
2404 Not all of the value will be output if \f[B]n\f[R] is too small.
2407 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2408 subsection of the \f[B]FUNCTIONS\f[R] section).
2411 \f[B]output_byte(x, i)\f[R]
2412 Outputs byte \f[B]i\f[R] of the truncated absolute value of \f[B]x\f[R],
2413 where \f[B]0\f[R] is the least significant byte and \f[B]number_of_bytes
2414 \- 1\f[R] is the most significant byte.
2417 This is a \f[B]void\f[R] function (see the \f[I]Void Functions\f[R]
2418 subsection of the \f[B]FUNCTIONS\f[R] section).
2429 functions with the precision (\f[B]scale\f[R]) set to at least 1 higher
2431 If exact results are \f[I]absolutely\f[R] required, users can double the
2432 precision (\f[B]scale\f[R]) and then truncate.
2436 \f[B]s(x)\f[R]
2438 \f[B]c(x)\f[R]
2440 \f[B]a(x)\f[R]
2442 \f[B]l(x)\f[R]
2444 \f[B]e(x)\f[R]
2446 \f[B]j(x, n)\f[R]
2450 \f[B]l2(x)\f[R]
2452 \f[B]l10(x)\f[R]
2454 \f[B]log(x, b)\f[R]
2456 \f[B]pi(p)\f[R]
2458 \f[B]t(x)\f[R]
2460 \f[B]a2(y, x)\f[R]
2462 \f[B]sin(x)\f[R]
2464 \f[B]cos(x)\f[R]
2466 \f[B]tan(x)\f[R]
2468 \f[B]atan(x)\f[R]
2470 \f[B]atan2(y, x)\f[R]
2472 \f[B]r2d(x)\f[R]
2474 \f[B]d2r(x)\f[R]
2476 When bc(1) encounters an error or a signal that it has a non\-default
2489 (see the \f[B]EXIT STATUS\f[R] section), it asks for more input;
2496 Most bc(1) implementations use \f[B]char\f[R] types to calculate the
2497 value of \f[B]1\f[R] decimal digit at a time, but that can be slow.
2500 It uses large integers to calculate more than \f[B]1\f[R] decimal digit
2502 If built in a environment where \f[B]BC_LONG_BIT\f[R] (see the
2503 \f[B]LIMITS\f[R] section) is \f[B]64\f[R], then each integer has
2504 \f[B]9\f[R] decimal digits.
2505 If built in an environment where \f[B]BC_LONG_BIT\f[R] is \f[B]32\f[R]
2506 then each integer has \f[B]4\f[R] decimal digits.
2508 \f[B]BC_BASE_DIGS\f[R].
2510 The actual values of \f[B]BC_LONG_BIT\f[R] and \f[B]BC_BASE_DIGS\f[R]
2511 can be queried with the \f[B]limits\f[R] statement.
2515 This integer type depends on the value of \f[B]BC_LONG_BIT\f[R], but is
2520 \f[B]BC_LONG_BIT\f[R]
2521 The number of bits in the \f[B]long\f[R] type in the environment where
2524 integer (see the \f[B]PERFORMANCE\f[R] section).
2526 \f[B]BC_BASE_DIGS\f[R]
2528 \f[B]PERFORMANCE\f[R] section).
2529 Depends on \f[B]BC_LONG_BIT\f[R].
2531 \f[B]BC_BASE_POW\f[R]
2533 \f[B]BC_BASE_DIGS\f[R]) plus \f[B]1\f[R].
2534 Depends on \f[B]BC_BASE_DIGS\f[R].
2536 \f[B]BC_OVERFLOW_MAX\f[R]
2537 The max number that the overflow type (see the \f[B]PERFORMANCE\f[R]
2539 Depends on \f[B]BC_LONG_BIT\f[R].
2541 \f[B]BC_BASE_MAX\f[R]
2543 Set at \f[B]BC_BASE_POW\f[R].
2545 \f[B]BC_DIM_MAX\f[R]
2547 Set at \f[B]SIZE_MAX\-1\f[R].
2549 \f[B]BC_SCALE_MAX\f[R]
2550 The maximum \f[B]scale\f[R].
2551 Set at \f[B]BC_OVERFLOW_MAX\-1\f[R].
2553 \f[B]BC_STRING_MAX\f[R]
2555 Set at \f[B]BC_OVERFLOW_MAX\-1\f[R].
2557 \f[B]BC_NAME_MAX\f[R]
2559 Set at \f[B]BC_OVERFLOW_MAX\-1\f[R].
2561 \f[B]BC_NUM_MAX\f[R]
2564 Set at \f[B]BC_OVERFLOW_MAX\-1\f[R].
2566 \f[B]BC_RAND_MAX\f[R]
2567 The maximum integer (inclusive) returned by the \f[B]rand()\f[R]
2569 Set at \f[B]2\[ha]BC_LONG_BIT\-1\f[R].
2573 Set at \f[B]BC_OVERFLOW_MAX\f[R].
2577 Set at \f[B]SIZE_MAX\-1\f[R].
2579 The actual values can be queried with the \f[B]limits\f[R] statement.
2581 These limits are meant to be effectively non\-existent; the limits are
2582 so large (at least on 64\-bit machines) that there should not be any
2586 As \f[B]non\-portable extensions\f[R], bc(1) recognizes the following
2589 \f[B]POSIXLY_CORRECT\f[R]
2591 the \f[B]\-s\f[R] option was given.
2593 \f[B]BC_ENV_ARGS\f[R]
2594 This is another way to give command\-line arguments to bc(1).
2595 They should be in the same format as all other command\-line arguments.
2597 \f[B]BC_ENV_ARGS\f[R] will be processed before arguments and files given
2598 on the command\-line.
2605 The code that parses \f[B]BC_ENV_ARGS\f[R] will correctly handle quoted
2607 For example, the string \f[B]\[lq]/home/gavin/some bc file.bc\[rq]\f[R]
2609 \[dq]bc\[dq] file.bc\[rq]\f[R] will include the backslashes.
2611 The quote parsing will handle either kind of quotes, \f[B]\[cq]\f[R] or
2612 \f[B]\[lq]\f[R].
2615 `bc' file.bc\[rq]\f[R], and vice versa if you have a file with double
2618 \f[B]BC_ENV_ARGS\f[R] is not supported due to the complexity of the
2619 parsing, though such files are still supported on the command\-line
2623 \f[B]BC_LINE_LENGTH\f[R]
2625 greater than \f[B]1\f[R] and is less than \f[B]UINT16_MAX\f[R]
2626 (\f[B]2\[ha]16\-1\f[R]), bc(1) will output lines to that length,
2627 including the backslash (\f[B]\[rs]\f[R]).
2628 The default line length is \f[B]70\f[R].
2631 The special value of \f[B]0\f[R] will disable line length checking and
2636 \f[B]BC_BANNER\f[R]
2638 non\-zero value activates the copyright banner when bc(1) is in
2642 If bc(1) is not in interactive mode (see the \f[B]INTERACTIVE MODE\f[R]
2647 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
2650 \f[B]BC_SIGINT_RESET\f[R]
2651 If bc(1) is not in interactive mode (see the \f[B]INTERACTIVE MODE\f[R]
2653 exits on \f[B]SIGINT\f[R] when not in interactive mode.
2657 variable exists and contains an integer, a non\-zero value makes bc(1)
2658 reset on \f[B]SIGINT\f[R], rather than exit, and zero makes bc(1) exit.
2659 If this environment variable exists and is \f[I]not\f[R] an integer,
2660 then bc(1) will exit on \f[B]SIGINT\f[R].
2663 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
2666 \f[B]BC_TTY_MODE\f[R]
2667 If TTY mode is \f[I]not\f[R] available (see the \f[B]TTY MODE\f[R]
2672 exists and contains an integer, then a non\-zero value makes bc(1) use
2676 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
2679 \f[B]BC_PROMPT\f[R]
2680 If TTY mode is \f[I]not\f[R] available (see the \f[B]TTY MODE\f[R]
2685 exists and contains an integer, a non\-zero value makes bc(1) use a
2686 prompt, and zero or a non\-integer makes bc(1) not use a prompt.
2687 If this environment variable does not exist and \f[B]BC_TTY_MODE\f[R]
2688 does, then the value of the \f[B]BC_TTY_MODE\f[R] environment variable
2691 This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
2693 \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
2696 \f[B]BC_EXPR_EXIT\f[R]
2697 If any expressions or expression files are given on the command\-line
2698 with \f[B]\-e\f[R], \f[B]\-\-expression\f[R], \f[B]\-f\f[R], or
2699 \f[B]\-\-file\f[R], then if this environment variable exists and
2700 contains an integer, a non\-zero value makes bc(1) exit after executing
2706 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
2709 \f[B]BC_DIGIT_CLAMP\f[R]
2711 contains an integer, a non\-zero value makes bc(1) clamp digits that are
2712 greater than or equal to the current \f[B]ibase\f[R] so that all such
2713 digits are considered equal to the \f[B]ibase\f[R] minus 1, and a zero
2715 their value, which is multiplied by the power of the \f[B]ibase\f[R].
2718 This never applies to single\-digit numbers, as per the standard (see
2719 the \f[B]STANDARDS\f[R] section).
2722 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
2727 \f[B]0\f[R]
2730 \f[B]1\f[R]
2732 This follows standard practice of using \f[B]1\f[R] for expected errors,
2736 Math errors include divide by \f[B]0\f[R], taking the square root of a
2738 pseudo\-random number generator, attempting to convert a negative number
2741 to use a non\-integer where an integer is required.
2744 power (\f[B]\[ha]\f[R]), places (\f[B]\[at]\f[R]), left shift
2745 (\f[B]<<\f[R]), and right shift (\f[B]>>\f[R]) operators and their
2749 \f[B]2\f[R]
2753 Parse errors include unexpected \f[B]EOF\f[R], using an invalid
2758 \f[I]Named Expressions\f[R] subsection of the \f[B]SYNTAX\f[R] section),
2759 giving an invalid \f[B]auto\f[R] list, having a duplicate
2760 \f[B]auto\f[R]/function parameter, failing to find the end of a code
2761 block, attempting to return a value from a \f[B]void\f[R] function,
2763 when the option \f[B]\-s\f[R] or any equivalents were given.
2766 \f[B]3\f[R]
2771 (\f[B]ibase\f[R], \f[B]obase\f[R], or \f[B]scale\f[R]), giving a bad
2772 expression to a \f[B]read()\f[R] call, calling \f[B]read()\f[R] inside
2773 of a \f[B]read()\f[R] call, type errors, passing the wrong number of
2775 attempting to use a \f[B]void\f[R] function call as a value in an
2779 \f[B]4\f[R]
2786 directory as a file, and giving invalid command\-line options.
2789 The exit status \f[B]4\f[R] is special; when a fatal error occurs, bc(1)
2790 always exits and returns \f[B]4\f[R], no matter what mode bc(1) is in.
2793 interactive mode (see the \f[B]INTERACTIVE MODE\f[R] section), since
2794 bc(1) resets its state (see the \f[B]RESET\f[R] section) and accepts
2797 \f[B]\-i\f[R] flag or \f[B]\-\-interactive\f[R] option.
2801 \f[B]\-i\f[R] flag or \f[B]\-\-interactive\f[R] option.
2803 Per the standard (see the \f[B]STANDARDS\f[R] section), bc(1) has an
2804 interactive mode and a non\-interactive mode.
2805 Interactive mode is turned on automatically when both \f[B]stdin\f[R]
2806 and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]\-i\f[R]
2807 flag and \f[B]\-\-interactive\f[R] option can turn it on in other
2811 \f[B]RESET\f[R] section), and in normal execution, flushes
2812 \f[B]stdout\f[R] as soon as execution is done for the current input.
2813 bc(1) may also reset on \f[B]SIGINT\f[R] instead of exit, depending on
2814 the contents of, or default for, the \f[B]BC_SIGINT_RESET\f[R]
2815 environment variable (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
2817 If \f[B]stdin\f[R], \f[B]stdout\f[R], and \f[B]stderr\f[R] are all
2822 If there is the environment variable \f[B]BC_TTY_MODE\f[R] in the
2823 environment (see the \f[B]ENVIRONMENT VARIABLES\f[R] section), then if
2824 that environment variable contains a non\-zero integer, bc(1) will turn
2825 on TTY mode when \f[B]stdin\f[R], \f[B]stdout\f[R], and \f[B]stderr\f[R]
2827 If the \f[B]BC_TTY_MODE\f[R] environment variable exists but is
2828 \f[I]not\f[R] a non\-zero integer, then bc(1) will not turn TTY mode on.
2830 If the environment variable \f[B]BC_TTY_MODE\f[R] does \f[I]not\f[R]
2832 The default setting can be queried with the \f[B]\-h\f[R] or
2833 \f[B]\-\-help\f[R] options.
2836 required in the bc(1) standard (see the \f[B]STANDARDS\f[R] section),
2837 and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
2842 variable: \f[B]BC_PROMPT\f[R] (see the \f[B]ENVIRONMENT VARIABLES\f[R]
2845 If the environment variable \f[B]BC_PROMPT\f[R] exists and is a
2846 non\-zero integer, then the prompt is turned on when \f[B]stdin\f[R],
2847 \f[B]stdout\f[R], and \f[B]stderr\f[R] are connected to a TTY and the
2848 \f[B]\-P\f[R] and \f[B]\-\-no\-prompt\f[R] options were not used.
2850 the \f[B]\-R\f[R] and \f[B]\-\-no\-read\-prompt\f[R] options must also
2853 However, if \f[B]BC_PROMPT\f[R] does not exist, the prompt can be
2854 enabled or disabled with the \f[B]BC_TTY_MODE\f[R] environment variable,
2855 the \f[B]\-P\f[R] and \f[B]\-\-no\-prompt\f[R] options, and the
2856 \f[B]\-R\f[R] and \f[B]\-\-no\-read\-prompt\f[R] options.
2857 See the \f[B]ENVIRONMENT VARIABLES\f[R] and \f[B]OPTIONS\f[R] sections
2860 Sending a \f[B]SIGINT\f[R] will cause bc(1) to do one of two things.
2862 If bc(1) is not in interactive mode (see the \f[B]INTERACTIVE MODE\f[R]
2863 section), or the \f[B]BC_SIGINT_RESET\f[R] environment variable (see the
2864 \f[B]ENVIRONMENT VARIABLES\f[R] section), or its default, is either not
2868 \f[B]BC_SIGINT_RESET\f[R] or its default is an integer and non\-zero,
2870 \f[B]RESET\f[R] section) upon receiving a \f[B]SIGINT\f[R].
2873 If bc(1) is processing input from \f[B]stdin\f[R] in interactive mode,
2877 exists, or ask for input from \f[B]stdin\f[R] if no other file exists.
2879 This means that if a \f[B]SIGINT\f[R] is sent to bc(1) as it is
2888 \f[B]SIGTERM\f[R] and \f[B]SIGQUIT\f[R] cause bc(1) to clean up and
2892 locales and thus, supports \f[B]LC_MESSAGES\f[R].
2896 bc(1) is compliant with the IEEE Std 1003.1\-2017
2897 (\[lq]POSIX.1\-2017\[rq]) specification at
2899 The flags \f[B]\-efghiqsvVw\f[R], all long options, and the extensions
2902 In addition, the behavior of the \f[B]quit\f[R] implements an
2905 For more information see the \f[B]Statements\f[R] subsection of the
2906 \f[B]SYNTAX\f[R] section.
2909 numbers that use a period (\f[B].\f[R]) as a radix point, regardless of
2910 the value of \f[B]LC_NUMERIC\f[R].
2913 supports \f[B]LC_MESSAGES\f[R].
2915 Before version \f[B]6.1.0\f[R], this bc(1) had incorrect behavior for
2916 the \f[B]quit\f[R] statement.