Lines Matching +full:a +full:- +full:f

2 .\" SPDX-License-Identifier: BSD-2-Clause
4 .\" Copyright (c) 2018-2024 Gavin D. Howard and contributors.
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 dc \- arbitrary\-precision decimal reverse\-Polish notation calculator
34 \f[B]dc\f[R] [\f[B]\-cChiPRvVx\f[R]] [\f[B]\-\-version\f[R]]
35 [\f[B]\-\-help\f[R]] [\f[B]\-\-digit\-clamp\f[R]]
36 [\f[B]\-\-no\-digit\-clamp\f[R]] [\f[B]\-\-interactive\f[R]]
37 [\f[B]\-\-no\-prompt\f[R]] [\f[B]\-\-no\-read\-prompt\f[R]]
38 [\f[B]\-\-extended\-register\f[R]] [\f[B]\-e\f[R] \f[I]expr\f[R]]
39 [\f[B]\-\-expression\f[R]=\f[I]expr\f[R]\&...]
40 [\f[B]\-f\f[R] \f[I]file\f[R]\&...]
41 [\f[B]\-\-file\f[R]=\f[I]file\f[R]\&...]
42 [\f[I]file\f[R]\&...]
44 dc(1) is an arbitrary\-precision calculator.
45 It uses a stack (reverse Polish notation) to store numbers and results
50 If no files are given on the command\-line, then dc(1) reads from
51 \f[B]stdin\f[R] (see the \f[B]STDIN\f[R] section).
54 If a user wants to set up a standard environment, they can use
55 \f[B]DC_ENV_ARGS\f[R] (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
56 For example, if a user wants the \f[B]scale\f[R] always set to
57 \f[B]10\f[R], they can set \f[B]DC_ENV_ARGS\f[R] to \f[B]\-e 10k\f[R],
58 and this dc(1) will always start with a \f[B]scale\f[R] of \f[B]10\f[R].
62 \f[B]\-C\f[R], \f[B]\-\-no\-digit\-clamp\f[R]
64 \f[B]ibase\f[R] when parsing numbers.
67 This means that the value added to a number from a digit is always that
72 If this and/or the \f[B]\-c\f[R] or \f[B]\-\-digit\-clamp\f[R] options
75 This option overrides the \f[B]DC_DIGIT_CLAMP\f[R] environment variable
76 (see the \f[B]ENVIRONMENT VARIABLES\f[R] section) and the default, which
77 can be queried with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
79 This is a \f[B]non\-portable extension\f[R].
82 \f[B]\-c\f[R], \f[B]\-\-digit\-clamp\f[R]
84 \f[B]ibase\f[R] when parsing numbers.
87 This means that digits that the value added to a number from a digit
93 If this and/or the \f[B]\-C\f[R] or \f[B]\-\-no\-digit\-clamp\f[R]
96 This option overrides the \f[B]DC_DIGIT_CLAMP\f[R] environment variable
97 (see the \f[B]ENVIRONMENT VARIABLES\f[R] section) and the default, which
98 can be queried with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
100 This is a \f[B]non\-portable extension\f[R].
103 \f[B]\-e\f[R] \f[I]expr\f[R], \f[B]\-\-expression\f[R]=\f[I]expr\f[R]
104 Evaluates \f[I]expr\f[R].
108 This means that if a file is given before an expression, the file is
112 If this option is given on the command\-line (i.e., not in
113 \f[B]DC_ENV_ARGS\f[R], see the \f[B]ENVIRONMENT VARIABLES\f[R] section),
115 \f[B]\-\f[R] (\f[B]stdin\f[R]) was given as an argument at least once to
116 \f[B]\-f\f[R] or \f[B]\-\-file\f[R], whether on the command\-line or in
117 \f[B]DC_ENV_ARGS\f[R].
118 However, if any other \f[B]\-e\f[R], \f[B]\-\-expression\f[R],
119 \f[B]\-f\f[R], or \f[B]\-\-file\f[R] arguments are given after
120 \f[B]\-f\-\f[R] or equivalent is given, dc(1) will give a fatal error
123 This is a \f[B]non\-portable extension\f[R].
126 \f[B]\-f\f[R] \f[I]file\f[R], \f[B]\-\-file\f[R]=\f[I]file\f[R]
127 Reads in \f[I]file\f[R] and evaluates it, line by line, as though it
128 were read through \f[B]stdin\f[R].
133 If this option is given on the command\-line (i.e., not in
134 \f[B]DC_ENV_ARGS\f[R], see the \f[B]ENVIRONMENT VARIABLES\f[R] section),
136 \f[B]\-\f[R] (\f[B]stdin\f[R]) was given as an argument at least once to
137 \f[B]\-f\f[R] or \f[B]\-\-file\f[R].
138 However, if any other \f[B]\-e\f[R], \f[B]\-\-expression\f[R],
139 \f[B]\-f\f[R], or \f[B]\-\-file\f[R] arguments are given after
140 \f[B]\-f\-\f[R] or equivalent is given, dc(1) will give a fatal error
143 This is a \f[B]non\-portable extension\f[R].
146 \f[B]\-h\f[R], \f[B]\-\-help\f[R]
147 Prints a usage message and exits.
149 \f[B]\-I\f[R] \f[I]ibase\f[R], \f[B]\-\-ibase\f[R]=\f[I]ibase\f[R]
150 Sets the builtin variable \f[B]ibase\f[R] to the value \f[I]ibase\f[R]
151 assuming that \f[I]ibase\f[R] is in base 10.
152 It is a fatal error if \f[I]ibase\f[R] is not a valid number.
157 This is a \f[B]non\-portable extension\f[R].
160 \f[B]\-i\f[R], \f[B]\-\-interactive\f[R]
162 (See the \f[B]INTERACTIVE MODE\f[R] section.)
165 This is a \f[B]non\-portable extension\f[R].
168 \f[B]\-L\f[R], \f[B]\-\-no\-line\-length\f[R]
171 In other words, this option sets \f[B]BC_LINE_LENGTH\f[R] to \f[B]0\f[R]
172 (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
175 This is a \f[B]non\-portable extension\f[R].
178 \f[B]\-O\f[R] \f[I]obase\f[R], \f[B]\-\-obase\f[R]=\f[I]obase\f[R]
179 Sets the builtin variable \f[B]obase\f[R] to the value \f[I]obase\f[R]
180 assuming that \f[I]obase\f[R] is in base 10.
181 It is a fatal error if \f[I]obase\f[R] is not a valid number.
186 This is a \f[B]non\-portable extension\f[R].
189 \f[B]\-P\f[R], \f[B]\-\-no\-prompt\f[R]
192 See the \f[B]TTY MODE\f[R] section.)
193 This is mostly for those users that do not want a prompt or are not used
196 \f[B]DC_ENV_ARGS\f[R].
199 These options override the \f[B]DC_PROMPT\f[R] and \f[B]DC_TTY_MODE\f[R]
200 environment variables (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
202 This is a \f[B]non\-portable extension\f[R].
205 \f[B]\-R\f[R], \f[B]\-\-no\-read\-prompt\f[R]
208 See the \f[B]TTY MODE\f[R] section.)
209 This is mostly for those users that do not want a read prompt or are not
212 \f[B]BC_ENV_ARGS\f[R] (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
218 is only used when the \f[B]?\f[R] command is used.
220 These options \f[I]do\f[R] override the \f[B]DC_PROMPT\f[R] and
221 \f[B]DC_TTY_MODE\f[R] environment variables (see the \f[B]ENVIRONMENT
222 VARIABLES\f[R] section), but only for the read prompt.
224 This is a \f[B]non\-portable extension\f[R].
227 \f[B]\-S\f[R] \f[I]scale\f[R], \f[B]\-\-scale\f[R]=\f[I]scale\f[R]
228 Sets the builtin variable \f[B]scale\f[R] to the value \f[I]scale\f[R]
229 assuming that \f[I]scale\f[R] is in base 10.
230 It is a fatal error if \f[I]scale\f[R] is not a valid number.
235 This is a \f[B]non\-portable extension\f[R].
238 \f[B]\-v\f[R], \f[B]\-V\f[R], \f[B]\-\-version\f[R]
241 \f[B]\-x\f[R] \f[B]\-\-extended\-register\f[R]
243 See the \f[I]Extended Register Mode\f[R] subsection of the
244 \f[B]REGISTERS\f[R] section for more information.
247 This is a \f[B]non\-portable extension\f[R].
250 \f[B]\-z\f[R], \f[B]\-\-leading\-zeroes\f[R]
251 Makes dc(1) print all numbers greater than \f[B]\-1\f[R] and less than
252 \f[B]1\f[R], and not equal to \f[B]0\f[R], with a leading zero.
255 This is a \f[B]non\-portable extension\f[R].
258 All long options are \f[B]non\-portable extensions\f[R].
260 If no files are given on the command\-line and no files or expressions
261 are given by the \f[B]\-f\f[R], \f[B]\-\-file\f[R], \f[B]\-e\f[R], or
262 \f[B]\-\-expression\f[R] options, then dc(1) reads from \f[B]stdin\f[R].
264 However, there is a caveat to this.
266 First, \f[B]stdin\f[R] is evaluated a line at a time.
267 The only exception to this is if a string has been finished, but not
272 Any non\-error output is written to \f[B]stdout\f[R].
273 In addition, if history (see the \f[B]HISTORY\f[R] section) and the
274 prompt (see the \f[B]TTY MODE\f[R] section) are enabled, both are output
275 to \f[B]stdout\f[R].
277 \f[B]Note\f[R]: Unlike other dc(1) implementations, this dc(1) will
278 issue a fatal error (see the \f[B]EXIT STATUS\f[R] section) if it cannot
279 write to \f[B]stdout\f[R], so if \f[B]stdout\f[R] is closed, as in
280 \f[B]dc >&\-\f[R], it will quit with an error.
281 This is done so that dc(1) can report problems when \f[B]stdout\f[R] is
282 redirected to a file.
286 redirect \f[B]stdout\f[R] to \f[B]/dev/null\f[R].
288 Any error output is written to \f[B]stderr\f[R].
290 \f[B]Note\f[R]: Unlike other dc(1) implementations, this dc(1) will
291 issue a fatal error (see the \f[B]EXIT STATUS\f[R] section) if it cannot
292 write to \f[B]stderr\f[R], so if \f[B]stderr\f[R] is closed, as in
293 \f[B]dc 2>&\-\f[R], it will quit with an error.
295 \f[B]stderr\f[R] is redirected to a file.
299 redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
301 Each item in the input source code, either a number (see the
302 \f[B]NUMBERS\f[R] section) or a command (see the \f[B]COMMANDS\f[R]
306 \f[B]ibase\f[R] is a register (see the \f[B]REGISTERS\f[R] section) that
310 \f[B]ibase\f[R] is initially \f[B]10\f[R].
311 The max allowable value for \f[B]ibase\f[R] is \f[B]16\f[R].
312 The min allowable value for \f[B]ibase\f[R] is \f[B]2\f[R].
313 The max allowable value for \f[B]ibase\f[R] can be queried in dc(1)
314 programs with the \f[B]T\f[R] command.
316 \f[B]obase\f[R] is a register (see the \f[B]REGISTERS\f[R] section) that
320 \f[B]obase\f[R] is initially \f[B]10\f[R].
321 The max allowable value for \f[B]obase\f[R] is \f[B]DC_BASE_MAX\f[R] and
322 can be queried with the \f[B]U\f[R] command.
323 The min allowable value for \f[B]obase\f[R] is \f[B]2\f[R].
326 The \f[I]scale\f[R] of an expression is the number of digits in the
327 result of the expression right of the decimal point, and \f[B]scale\f[R]
328 is a register (see the \f[B]REGISTERS\f[R] section) that sets the
330 \f[B]scale\f[R] is initially \f[B]0\f[R].
331 \f[B]scale\f[R] cannot be negative.
332 The max allowable value for \f[B]scale\f[R] can be queried in dc(1)
333 programs with the \f[B]V\f[R] command.
335 Comments go from \f[B]#\f[R] until, and not including, the next newline.
336 This is a \f[B]non\-portable extension\f[R].
339 \f[B]F\f[R], and at most \f[B]1\f[R] period for a radix.
340 Numbers can have up to \f[B]DC_NUM_MAX\f[R] digits.
341 Uppercase letters are equal to \f[B]9\f[R] plus their position in the
342 alphabet (i.e., \f[B]A\f[R] equals \f[B]10\f[R], or \f[B]9+1\f[R]).
344 If a digit or letter makes no sense with the current value of
345 \f[B]ibase\f[R] (i.e., they are greater than or equal to the current
346 value of \f[B]ibase\f[R]), then the behavior depends on the existence of
347 the \f[B]\-c\f[R]/\f[B]\-\-digit\-clamp\f[R] or
348 \f[B]\-C\f[R]/\f[B]\-\-no\-digit\-clamp\f[R] options (see the
349 \f[B]OPTIONS\f[R] section), the existence and setting of the
350 \f[B]DC_DIGIT_CLAMP\f[R] environment variable (see the \f[B]ENVIRONMENT
351 VARIABLES\f[R] section), or the default, which can be queried with the
352 \f[B]\-h\f[R]/\f[B]\-\-help\f[R] option.
355 equal to the current value of \f[B]ibase\f[R] are not changed.
357 \f[B]ibase\f[R] and added into the number.
358 This means that, with an \f[B]ibase\f[R] of \f[B]3\f[R], the number
359 \f[B]AB\f[R] is equal to \f[B]3\[ha]1*A+3\[ha]0*B\f[R], which is
360 \f[B]3\f[R] times \f[B]10\f[R] plus \f[B]11\f[R], or \f[B]41\f[R].
363 to the current value of \f[B]ibase\f[R] are set to the value of the
364 highest valid digit in \f[B]ibase\f[R] before being multiplied by the
365 appropriate power of \f[B]ibase\f[R] and added into the number.
366 This means that, with an \f[B]ibase\f[R] of \f[B]3\f[R], the number
367 \f[B]AB\f[R] is equal to \f[B]3\[ha]1*2+3\[ha]0*2\f[R], which is
368 \f[B]3\f[R] times \f[B]2\f[R] plus \f[B]2\f[R], or \f[B]8\f[R].
370 There is one exception to clamping: single\-character numbers (i.e.,
371 \f[B]A\f[R] alone).
373 in the highest possible \f[B]ibase\f[R].
374 This means that \f[B]A\f[R] alone always equals decimal \f[B]10\f[R] and
375 \f[B]Z\f[R] alone always equals decimal \f[B]35\f[R].
378 \f[B]ibase\f[R] (with the \f[B]i\f[R] command) regardless of the current
379 value of \f[B]ibase\f[R].
381 If clamping is on, and the clamped value of a character is needed, use a
382 leading zero, i.e., for \f[B]A\f[R], use \f[B]0A\f[R].
388 \f[B]p\f[R]
390 prints a newline after.
396 \f[B]n\f[R]
400 \f[B]P\f[R]
401 Pops a value off the stack.
404 If the value is a number, it is truncated and the absolute value of the
405 result is printed as though \f[B]obase\f[R] is \f[B]256\f[R] and each
406 digit is interpreted as an 8\-bit ASCII character, making it a byte
409 If the value is a string, it is printed without a trailing newline.
411 This is a \f[B]non\-portable extension\f[R].
414 \f[B]f\f[R]
424 \f[B]+\f[R]
427 The \f[I]scale\f[R] of the result is equal to the max \f[I]scale\f[R] of
430 \f[B]\-\f[R]
433 The \f[I]scale\f[R] of the result is equal to the max \f[I]scale\f[R] of
436 \f[B]*\f[R]
439 If \f[B]a\f[R] is the \f[I]scale\f[R] of the first expression and
440 \f[B]b\f[R] is the \f[I]scale\f[R] of the second expression, the
441 \f[I]scale\f[R] of the result is equal to
442 \f[B]min(a+b,max(scale,a,b))\f[R] where \f[B]min()\f[R] and
443 \f[B]max()\f[R] return the obvious values.
445 \f[B]/\f[R]
448 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
451 The first value popped off of the stack must be non\-zero.
454 \f[B]%\f[R]
459 Remaindering is equivalent to 1) Computing \f[B]a/b\f[R] to current
460 \f[B]scale\f[R], and 2) Using the result of step 1 to calculate
461 \f[B]a\-(a/b)*b\f[R] to \f[I]scale\f[R]
462 \f[B]max(scale+scale(b),scale(a))\f[R].
464 The first value popped off of the stack must be non\-zero.
467 \f[B]\[ti]\f[R]
471 This is equivalent to \f[B]x y / x y %\f[R] except that \f[B]x\f[R] and
472 \f[B]y\f[R] are only evaluated once.
475 The first value popped off of the stack must be non\-zero.
477 This is a \f[B]non\-portable extension\f[R].
480 \f[B]\[ha]\f[R]
483 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
488 non\-zero.
491 \f[B]v\f[R]
494 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
497 The value popped off of the stack must be non\-negative.
500 \f[B]_\f[R]
501 If this command \f[I]immediately\f[R] precedes a number (i.e., no spaces
502 or other commands), then that number is input as a negative number.
507 This behavior without a number is a \f[B]non\-portable extension\f[R].
510 \f[B]b\f[R]
516 This is a \f[B]non\-portable extension\f[R].
519 \f[B]|\f[R]
520 The top three values are popped off the stack, a modular exponentiation
525 integer and non\-zero.
527 and non\-negative.
530 This is a \f[B]non\-portable extension\f[R].
533 \f[B]G\f[R]
534 The top two values are popped off of the stack, they are compared, and a
535 \f[B]1\f[R] is pushed if they are equal, or \f[B]0\f[R] otherwise.
538 This is a \f[B]non\-portable extension\f[R].
541 \f[B]N\f[R]
542 The top value is popped off of the stack, and if it a \f[B]0\f[R], a
543 \f[B]1\f[R] is pushed; otherwise, a \f[B]0\f[R] is pushed.
546 This is a \f[B]non\-portable extension\f[R].
549 \f[B](\f[R]
550 The top two values are popped off of the stack, they are compared, and a
551 \f[B]1\f[R] is pushed if the first is less than the second, or
552 \f[B]0\f[R] otherwise.
555 This is a \f[B]non\-portable extension\f[R].
558 \f[B]{\f[R]
559 The top two values are popped off of the stack, they are compared, and a
560 \f[B]1\f[R] is pushed if the first is less than or equal to the second,
561 or \f[B]0\f[R] otherwise.
564 This is a \f[B]non\-portable extension\f[R].
567 \f[B])\f[R]
568 The top two values are popped off of the stack, they are compared, and a
569 \f[B]1\f[R] is pushed if the first is greater than the second, or
570 \f[B]0\f[R] otherwise.
573 This is a \f[B]non\-portable extension\f[R].
576 \f[B]}\f[R]
577 The top two values are popped off of the stack, they are compared, and a
578 \f[B]1\f[R] is pushed if the first is greater than or equal to the
579 second, or \f[B]0\f[R] otherwise.
582 This is a \f[B]non\-portable extension\f[R].
585 \f[B]M\f[R]
587 If they are both non\-zero, a \f[B]1\f[R] is pushed onto the stack.
588 If either of them is zero, or both of them are, then a \f[B]0\f[R] is
592 This is like the \f[B]&&\f[R] operator in bc(1), and it is \f[I]not\f[R]
593 a short\-circuit operator.
595 This is a \f[B]non\-portable extension\f[R].
598 \f[B]m\f[R]
600 If at least one of them is non\-zero, a \f[B]1\f[R] is pushed onto the
602 If both of them are zero, then a \f[B]0\f[R] is pushed onto the stack.
605 This is like the \f[B]||\f[R] operator in bc(1), and it is \f[I]not\f[R]
606 a short\-circuit operator.
608 This is a \f[B]non\-portable extension\f[R].
613 \f[B]c\f[R]
616 \f[B]d\f[R]
620 \f[B]r\f[R]
623 \f[B]R\f[R]
626 These commands control registers (see the \f[B]REGISTERS\f[R] section).
628 \f[B]s\f[R]\f[I]r\f[R]
630 \f[I]r\f[R].
632 \f[B]l\f[R]\f[I]r\f[R]
633 Copies the value in register \f[I]r\f[R] and pushes it onto the stack.
634 This does not alter the contents of \f[I]r\f[R].
636 \f[B]S\f[R]\f[I]r\f[R]
638 stack of register \f[I]r\f[R].
641 \f[B]L\f[R]\f[I]r\f[R]
642 Pops the value off the top of the stack for register \f[I]r\f[R] and
644 The previous value in the stack for register \f[I]r\f[R], if any, is now
645 accessible via the \f[B]l\f[R]\f[I]r\f[R] command.
647 These commands control the values of \f[B]ibase\f[R], \f[B]obase\f[R],
648 and \f[B]scale\f[R].
649 Also see the \f[B]SYNTAX\f[R] section.
651 \f[B]i\f[R]
653 \f[B]ibase\f[R], which must be between \f[B]2\f[R] and \f[B]16\f[R],
657 If the value on top of the stack has any \f[I]scale\f[R], the
658 \f[I]scale\f[R] is ignored.
661 \f[B]o\f[R]
663 \f[B]obase\f[R], which must be between \f[B]2\f[R] and
664 \f[B]DC_BASE_MAX\f[R], inclusive (see the \f[B]LIMITS\f[R] section).
667 If the value on top of the stack has any \f[I]scale\f[R], the
668 \f[I]scale\f[R] is ignored.
671 \f[B]k\f[R]
673 \f[B]scale\f[R], which must be non\-negative.
676 If the value on top of the stack has any \f[I]scale\f[R], the
677 \f[I]scale\f[R] is ignored.
680 \f[B]I\f[R]
681 Pushes the current value of \f[B]ibase\f[R] onto the main stack.
683 \f[B]O\f[R]
684 Pushes the current value of \f[B]obase\f[R] onto the main stack.
686 \f[B]K\f[R]
687 Pushes the current value of \f[B]scale\f[R] onto the main stack.
689 \f[B]T\f[R]
690 Pushes the maximum allowable value of \f[B]ibase\f[R] onto the main
694 This is a \f[B]non\-portable extension\f[R].
697 \f[B]U\f[R]
698 Pushes the maximum allowable value of \f[B]obase\f[R] onto the main
702 This is a \f[B]non\-portable extension\f[R].
705 \f[B]V\f[R]
706 Pushes the maximum allowable value of \f[B]scale\f[R] onto the main
710 This is a \f[B]non\-portable extension\f[R].
716 \f[B]REGISTERS\f[R] section) can hold both strings and numbers.
717 dc(1) always knows whether the contents of a register are a string or a
721 error if given a string, other commands accept strings.
724 For example, if the string \f[B][1pR]\f[R] is executed as a macro, then
725 the code \f[B]1pR\f[R] is executed, meaning that the \f[B]1\f[R] will be
726 printed with a newline after and then popped from the stack.
728 \f[B][\f[R]\f[I]characters\f[R]\f[B]]\f[R]
729 Makes a string containing \f[I]characters\f[R] and pushes it onto the
733 If there are brackets (\f[B][\f[R] and \f[B]]\f[R]) in the string, then
735 Unbalanced brackets can be escaped using a backslash (\f[B]\[rs]\f[R])
738 If there is a backslash character in the string, the character after it
743 \f[B]a\f[R]
747 If it is a number, it is truncated and its absolute value is taken.
748 The result mod \f[B]256\f[R] is calculated.
749 If that result is \f[B]0\f[R], push an empty string; otherwise, push a
750 one\-character string where the character is the result of the mod
753 If it is a string, then a new string is made.
756 create the new string as a one\-character string.
759 This is a \f[B]non\-portable extension\f[R].
762 \f[B]x\f[R]
763 Pops a value off of the top of the stack.
766 If it is a number, it is pushed back onto the stack.
768 If it is a string, it is executed as a macro.
770 This behavior is the norm whenever a macro is executed, whether by this
774 \f[B]>\f[R]\f[I]r\f[R]
777 register \f[I]r\f[R] are executed.
780 For example, \f[B]0 1>a\f[R] will execute the contents of register
781 \f[B]a\f[R], and \f[B]1 0>a\f[R] will not.
784 error and reset (see the \f[B]RESET\f[R] section).
787 \f[B]>\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
788 Like the above, but will execute register \f[I]s\f[R] if the comparison
793 error and reset (see the \f[B]RESET\f[R] section).
795 This is a \f[B]non\-portable extension\f[R].
798 \f[B]!>\f[R]\f[I]r\f[R]
801 to), then the contents of register \f[I]r\f[R] are executed.
805 error and reset (see the \f[B]RESET\f[R] section).
808 \f[B]!>\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
809 Like the above, but will execute register \f[I]s\f[R] if the comparison
814 error and reset (see the \f[B]RESET\f[R] section).
816 This is a \f[B]non\-portable extension\f[R].
819 \f[B]<\f[R]\f[I]r\f[R]
822 register \f[I]r\f[R] are executed.
826 error and reset (see the \f[B]RESET\f[R] section).
829 \f[B]<\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
830 Like the above, but will execute register \f[I]s\f[R] if the comparison
835 error and reset (see the \f[B]RESET\f[R] section).
837 This is a \f[B]non\-portable extension\f[R].
840 \f[B]!<\f[R]\f[I]r\f[R]
843 to), then the contents of register \f[I]r\f[R] are executed.
847 error and reset (see the \f[B]RESET\f[R] section).
850 \f[B]!<\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
851 Like the above, but will execute register \f[I]s\f[R] if the comparison
856 error and reset (see the \f[B]RESET\f[R] section).
858 This is a \f[B]non\-portable extension\f[R].
861 \f[B]=\f[R]\f[I]r\f[R]
864 \f[I]r\f[R] are executed.
868 error and reset (see the \f[B]RESET\f[R] section).
871 \f[B]=\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
872 Like the above, but will execute register \f[I]s\f[R] if the comparison
877 error and reset (see the \f[B]RESET\f[R] section).
879 This is a \f[B]non\-portable extension\f[R].
882 \f[B]!=\f[R]\f[I]r\f[R]
885 register \f[I]r\f[R] are executed.
889 error and reset (see the \f[B]RESET\f[R] section).
892 \f[B]!=\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
893 Like the above, but will execute register \f[I]s\f[R] if the comparison
898 error and reset (see the \f[B]RESET\f[R] section).
900 This is a \f[B]non\-portable extension\f[R].
903 \f[B]?\f[R]
904 Reads a line from the \f[B]stdin\f[R] and executes it.
907 \f[B]q\f[R]
908 During execution of a macro, this exits the execution of that macro and
912 \f[B]Q\f[R]
913 Pops a value from the stack which must be non\-negative and is used the
918 \f[B],\f[R]
922 to make dc(1) exit with the \f[B]Q\f[R] command, so the sequence
923 \f[B],Q\f[R] will make dc(1) exit.
926 This is a \f[B]non\-portable extension\f[R].
931 \f[B]Z\f[R]
932 Pops a value off of the stack.
935 If it is a number, calculates the number of significant decimal digits
937 It will push \f[B]1\f[R] if the argument is \f[B]0\f[R] with no decimal
940 If it is a string, pushes the number of characters the string has.
943 \f[B]X\f[R]
944 Pops a value off of the stack.
947 If it is a number, pushes the \f[I]scale\f[R] of the value onto the
950 If it is a string, pushes \f[B]0\f[R].
953 \f[B]u\f[R]
955 If the value is a number, this pushes \f[B]1\f[R] onto the stack.
956 Otherwise (if it is a string), it pushes \f[B]0\f[R].
959 This is a \f[B]non\-portable extension\f[R].
962 \f[B]t\f[R]
964 If the value is a string, this pushes \f[B]1\f[R] onto the stack.
965 Otherwise (if it is a number), it pushes \f[B]0\f[R].
968 This is a \f[B]non\-portable extension\f[R].
971 \f[B]z\f[R]
975 \f[B]y\f[R]\f[I]r\f[R]
976 Pushes the current stack depth of the register \f[I]r\f[R] onto the main
980 Because each register has a depth of \f[B]1\f[R] (with the value
981 \f[B]0\f[R] in the top item) when dc(1) starts, dc(1) requires that each
983 an error and reset otherwise (see the \f[B]RESET\f[R] section).
984 This means that this command will never push \f[B]0\f[R].
986 This is a \f[B]non\-portable extension\f[R].
991 \f[B]:\f[R]\f[I]r\f[R]
993 The second value will be stored in the array \f[I]r\f[R] (see the
994 \f[B]REGISTERS\f[R] section), indexed by the first value.
996 \f[B];\f[R]\f[I]r\f[R]
998 array \f[I]r\f[R].
1001 \f[B]Y\f[R]\f[I]r\f[R]
1002 Pushes the length of the array \f[I]r\f[R] onto the stack.
1005 This is a \f[B]non\-portable extension\f[R].
1010 and all of them begin with the letter \f[B]g\f[R].
1011 Only the characters below are allowed after the character \f[B]g\f[R];
1012 any other character produces a parse error (see the \f[B]ERRORS\f[R]
1015 \f[B]gl\f[R]
1016 Pushes the line length set by \f[B]DC_LINE_LENGTH\f[R] (see the
1017 \f[B]ENVIRONMENT VARIABLES\f[R] section) onto the stack.
1019 \f[B]gx\f[R]
1020 Pushes \f[B]1\f[R] onto the stack if extended register mode is on,
1021 \f[B]0\f[R] otherwise.
1022 See the \f[I]Extended Register Mode\f[R] subsection of the
1023 \f[B]REGISTERS\f[R] section for more information.
1025 \f[B]gz\f[R]
1026 Pushes \f[B]0\f[R] onto the stack if the leading zero setting has not
1027 been enabled with the \f[B]\-z\f[R] or \f[B]\-\-leading\-zeroes\f[R]
1028 options (see the \f[B]OPTIONS\f[R] section), non\-zero otherwise.
1035 All registers, when first referenced, have one value (\f[B]0\f[R]) in
1036 their stack, and it is a runtime error to attempt to pop that item off
1039 In non\-extended register mode, a register name is just the single
1040 character that follows any command that needs a register name.
1041 The only exceptions are: a newline (\f[B]`\[rs]n'\f[R]) and a left
1042 bracket (\f[B]`['\f[R]); it is a parse error for a newline or a left
1043 bracket to be used as a register name.
1048 If extended register mode is enabled (\f[B]\-x\f[R] or
1049 \f[B]\-\-extended\-register\f[R] command\-line arguments are given),
1050 then normal single character registers are used \f[I]unless\f[R] the
1051 character immediately following a command that needs a register name is
1052 a space (according to \f[B]isspace()\f[R]) and not a newline
1053 (\f[B]`\[rs]n'\f[R]).
1056 \f[B][a\-z][a\-z0\-9_]*\f[R] (like bc(1) identifiers), and it is a parse
1057 error if the next non\-space characters do not match that regex.
1059 When dc(1) encounters an error or a signal that it has a non\-default
1069 However, the stack of values is \f[I]not\f[R] cleared; in interactive
1074 Then, if it is interactive mode, and the error was not a fatal error
1075 (see the \f[B]EXIT STATUS\f[R] section), it asks for more input;
1078 Most dc(1) implementations use \f[B]char\f[R] types to calculate the
1079 value of \f[B]1\f[R] decimal digit at a time, but that can be slow.
1082 It uses large integers to calculate more than \f[B]1\f[R] decimal digit
1083 at a time.
1084 If built in a environment where \f[B]DC_LONG_BIT\f[R] (see the
1085 \f[B]LIMITS\f[R] section) is \f[B]64\f[R], then each integer has
1086 \f[B]9\f[R] decimal digits.
1087 If built in an environment where \f[B]DC_LONG_BIT\f[R] is \f[B]32\f[R]
1088 then each integer has \f[B]4\f[R] decimal digits.
1090 \f[B]DC_BASE_DIGS\f[R].
1094 This integer type depends on the value of \f[B]DC_LONG_BIT\f[R], but is
1099 \f[B]DC_LONG_BIT\f[R]
1100 The number of bits in the \f[B]long\f[R] type in the environment where
1102 This determines how many decimal digits can be stored in a single large
1103 integer (see the \f[B]PERFORMANCE\f[R] section).
1105 \f[B]DC_BASE_DIGS\f[R]
1107 \f[B]PERFORMANCE\f[R] section).
1108 Depends on \f[B]DC_LONG_BIT\f[R].
1110 \f[B]DC_BASE_POW\f[R]
1112 \f[B]DC_BASE_DIGS\f[R]) plus \f[B]1\f[R].
1113 Depends on \f[B]DC_BASE_DIGS\f[R].
1115 \f[B]DC_OVERFLOW_MAX\f[R]
1116 The max number that the overflow type (see the \f[B]PERFORMANCE\f[R]
1118 Depends on \f[B]DC_LONG_BIT\f[R].
1120 \f[B]DC_BASE_MAX\f[R]
1122 Set at \f[B]DC_BASE_POW\f[R].
1124 \f[B]DC_DIM_MAX\f[R]
1126 Set at \f[B]SIZE_MAX\-1\f[R].
1128 \f[B]DC_SCALE_MAX\f[R]
1129 The maximum \f[B]scale\f[R].
1130 Set at \f[B]DC_OVERFLOW_MAX\-1\f[R].
1132 \f[B]DC_STRING_MAX\f[R]
1134 Set at \f[B]DC_OVERFLOW_MAX\-1\f[R].
1136 \f[B]DC_NAME_MAX\f[R]
1138 Set at \f[B]DC_OVERFLOW_MAX\-1\f[R].
1140 \f[B]DC_NUM_MAX\f[R]
1141 The maximum length of a number (in decimal digits), which includes
1143 Set at \f[B]DC_OVERFLOW_MAX\-1\f[R].
1147 Set at \f[B]DC_OVERFLOW_MAX\f[R].
1151 Set at \f[B]SIZE_MAX\-1\f[R].
1153 These limits are meant to be effectively non\-existent; the limits are
1154 so large (at least on 64\-bit machines) that there should not be any
1155 point at which they become a problem.
1158 As \f[B]non\-portable extensions\f[R], dc(1) recognizes the following
1161 \f[B]DC_ENV_ARGS\f[R]
1162 This is another way to give command\-line arguments to dc(1).
1163 They should be in the same format as all other command\-line arguments.
1165 \f[B]DC_ENV_ARGS\f[R] will be processed before arguments and files given
1166 on the command\-line.
1171 Another use would be to use the \f[B]\-e\f[R] option to set
1172 \f[B]scale\f[R] to a value other than \f[B]0\f[R].
1175 The code that parses \f[B]DC_ENV_ARGS\f[R] will correctly handle quoted
1177 For example, the string \f[B]\[lq]/home/gavin/some dc file.dc\[rq]\f[R]
1178 will be correctly parsed, but the string \f[B]\[lq]/home/gavin/some
1179 \[dq]dc\[dq] file.dc\[rq]\f[R] will include the backslashes.
1181 The quote parsing will handle either kind of quotes, \f[B]\[cq]\f[R] or
1182 \f[B]\[lq]\f[R].
1183 Thus, if you have a file with any number of single quotes in the name,
1184 you can use double quotes as the outside quotes, as in \f[B]\[lq]some
1185 `dc' file.dc\[rq]\f[R], and vice versa if you have a file with double
1187 However, handling a file with both kinds of quotes in
1188 \f[B]DC_ENV_ARGS\f[R] is not supported due to the complexity of the
1189 parsing, though such files are still supported on the command\-line
1193 \f[B]DC_LINE_LENGTH\f[R]
1195 greater than \f[B]1\f[R] and is less than \f[B]UINT16_MAX\f[R]
1196 (\f[B]2\[ha]16\-1\f[R]), dc(1) will output lines to that length,
1198 The default line length is \f[B]70\f[R].
1201 The special value of \f[B]0\f[R] will disable line length checking and
1206 \f[B]DC_SIGINT_RESET\f[R]
1207 If dc(1) is not in interactive mode (see the \f[B]INTERACTIVE MODE\f[R]
1209 exits on \f[B]SIGINT\f[R] when not in interactive mode.
1213 variable exists and contains an integer, a non\-zero value makes dc(1)
1214 reset on \f[B]SIGINT\f[R], rather than exit, and zero makes dc(1) exit.
1215 If this environment variable exists and is \f[I]not\f[R] an integer,
1216 then dc(1) will exit on \f[B]SIGINT\f[R].
1219 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
1222 \f[B]DC_TTY_MODE\f[R]
1223 If TTY mode is \f[I]not\f[R] available (see the \f[B]TTY MODE\f[R]
1228 exists and contains an integer, then a non\-zero value makes dc(1) use
1232 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
1235 \f[B]DC_PROMPT\f[R]
1236 If TTY mode is \f[I]not\f[R] available (see the \f[B]TTY MODE\f[R]
1241 exists and contains an integer, a non\-zero value makes dc(1) use a
1242 prompt, and zero or a non\-integer makes dc(1) not use a prompt.
1243 If this environment variable does not exist and \f[B]DC_TTY_MODE\f[R]
1244 does, then the value of the \f[B]DC_TTY_MODE\f[R] environment variable
1247 This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
1249 \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
1252 \f[B]DC_EXPR_EXIT\f[R]
1253 If any expressions or expression files are given on the command\-line
1254 with \f[B]\-e\f[R], \f[B]\-\-expression\f[R], \f[B]\-f\f[R], or
1255 \f[B]\-\-file\f[R], then if this environment variable exists and
1256 contains an integer, a non\-zero value makes dc(1) exit after executing
1257 the expressions and expression files, and a zero value makes dc(1) not
1262 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
1265 \f[B]DC_DIGIT_CLAMP\f[R]
1267 contains an integer, a non\-zero value makes dc(1) clamp digits that are
1268 greater than or equal to the current \f[B]ibase\f[R] so that all such
1269 digits are considered equal to the \f[B]ibase\f[R] minus 1, and a zero
1271 their value, which is multiplied by the power of the \f[B]ibase\f[R].
1274 This never applies to single\-digit numbers, as per the bc(1) standard
1275 (see the \f[B]STANDARDS\f[R] section).
1278 with the \f[B]\-h\f[R] or \f[B]\-\-help\f[R] options.
1283 \f[B]0\f[R]
1286 \f[B]1\f[R]
1287 A math error occurred.
1288 This follows standard practice of using \f[B]1\f[R] for expected errors,
1292 Math errors include divide by \f[B]0\f[R], taking the square root of a
1293 negative number, attempting to convert a negative number to a hardware
1294 integer, overflow when converting a number to a hardware integer,
1295 overflow when calculating the size of a number, and attempting to use a
1296 non\-integer where an integer is required.
1298 Converting to a hardware integer happens for the second operand of the
1299 power (\f[B]\[ha]\f[R]) operator.
1302 \f[B]2\f[R]
1303 A parse error occurred.
1306 Parse errors include unexpected \f[B]EOF\f[R], using an invalid
1307 character, failing to find the end of a string or comment, and using a
1311 \f[B]3\f[R]
1312 A runtime error occurred.
1316 (\f[B]ibase\f[R], \f[B]obase\f[R], or \f[B]scale\f[R]), giving a bad
1317 expression to a \f[B]read()\f[R] call, calling \f[B]read()\f[R] inside
1318 of a \f[B]read()\f[R] call, type errors (including attempting to execute
1319 a number), and attempting an operation when the stack has too few
1323 \f[B]4\f[R]
1324 A fatal error occurred.
1329 characters (dc(1) only accepts ASCII characters), attempting to open a
1330 directory as a file, and giving invalid command\-line options.
1333 The exit status \f[B]4\f[R] is special; when a fatal error occurs, dc(1)
1334 always exits and returns \f[B]4\f[R], no matter what mode dc(1) is in.
1337 interactive mode (see the \f[B]INTERACTIVE MODE\f[R] section), since
1338 dc(1) resets its state (see the \f[B]RESET\f[R] section) and accepts
1341 \f[B]\-i\f[R] flag or \f[B]\-\-interactive\f[R] option.
1345 \f[B]\-i\f[R] flag or \f[B]\-\-interactive\f[R] option.
1347 Like bc(1), dc(1) has an interactive mode and a non\-interactive mode.
1348 Interactive mode is turned on automatically when both \f[B]stdin\f[R]
1349 and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]\-i\f[R]
1350 flag and \f[B]\-\-interactive\f[R] option can turn it on in other
1354 \f[B]RESET\f[R] section), and in normal execution, flushes
1355 \f[B]stdout\f[R] as soon as execution is done for the current input.
1356 dc(1) may also reset on \f[B]SIGINT\f[R] instead of exit, depending on
1357 the contents of, or default for, the \f[B]DC_SIGINT_RESET\f[R]
1358 environment variable (see the \f[B]ENVIRONMENT VARIABLES\f[R] section).
1360 If \f[B]stdin\f[R], \f[B]stdout\f[R], and \f[B]stderr\f[R] are all
1361 connected to a TTY, then \[lq]TTY mode\[rq] is considered to be
1365 If there is the environment variable \f[B]DC_TTY_MODE\f[R] in the
1366 environment (see the \f[B]ENVIRONMENT VARIABLES\f[R] section), then if
1367 that environment variable contains a non\-zero integer, dc(1) will turn
1368 on TTY mode when \f[B]stdin\f[R], \f[B]stdout\f[R], and \f[B]stderr\f[R]
1369 are all connected to a TTY.
1370 If the \f[B]DC_TTY_MODE\f[R] environment variable exists but is
1371 \f[I]not\f[R] a non\-zero integer, then dc(1) will not turn TTY mode on.
1373 If the environment variable \f[B]DC_TTY_MODE\f[R] does \f[I]not\f[R]
1375 The default setting can be queried with the \f[B]\-h\f[R] or
1376 \f[B]\-\-help\f[R] options.
1379 required in the bc(1) specification (see the \f[B]STANDARDS\f[R]
1380 section), and interactive mode requires only \f[B]stdin\f[R] and
1381 \f[B]stdout\f[R] to be connected to a terminal.
1382 .SS Command\-Line History
1383 Command\-line history is only enabled if TTY mode is, i.e., that
1384 \f[B]stdin\f[R], \f[B]stdout\f[R], and \f[B]stderr\f[R] are connected to
1385 a TTY and the \f[B]DC_TTY_MODE\f[R] environment variable (see the
1386 \f[B]ENVIRONMENT VARIABLES\f[R] section) and its default do not disable
1388 See the \f[B]COMMAND LINE HISTORY\f[R] section for more information.
1390 If TTY mode is available, then a prompt can be enabled.
1392 variable: \f[B]DC_PROMPT\f[R] (see the \f[B]ENVIRONMENT VARIABLES\f[R]
1395 If the environment variable \f[B]DC_PROMPT\f[R] exists and is a
1396 non\-zero integer, then the prompt is turned on when \f[B]stdin\f[R],
1397 \f[B]stdout\f[R], and \f[B]stderr\f[R] are connected to a TTY and the
1398 \f[B]\-P\f[R] and \f[B]\-\-no\-prompt\f[R] options were not used.
1400 the \f[B]\-R\f[R] and \f[B]\-\-no\-read\-prompt\f[R] options must also
1403 However, if \f[B]DC_PROMPT\f[R] does not exist, the prompt can be
1404 enabled or disabled with the \f[B]DC_TTY_MODE\f[R] environment variable,
1405 the \f[B]\-P\f[R] and \f[B]\-\-no\-prompt\f[R] options, and the
1406 \f[B]\-R\f[R] and \f[B]\-\-no\-read\-prompt\f[R] options.
1407 See the \f[B]ENVIRONMENT VARIABLES\f[R] and \f[B]OPTIONS\f[R] sections
1410 Sending a \f[B]SIGINT\f[R] will cause dc(1) to do one of two things.
1412 If dc(1) is not in interactive mode (see the \f[B]INTERACTIVE MODE\f[R]
1413 section), or the \f[B]DC_SIGINT_RESET\f[R] environment variable (see the
1414 \f[B]ENVIRONMENT VARIABLES\f[R] section), or its default, is either not
1418 \f[B]DC_SIGINT_RESET\f[R] or its default is an integer and non\-zero,
1420 \f[B]RESET\f[R] section) upon receiving a \f[B]SIGINT\f[R].
1423 If dc(1) is processing input from \f[B]stdin\f[R] in interactive mode,
1425 If dc(1) is processing input from a file in interactive mode, it will
1427 exists, or ask for input from \f[B]stdin\f[R] if no other file exists.
1429 This means that if a \f[B]SIGINT\f[R] is sent to dc(1) as it is
1430 executing a file, it can seem as though dc(1) did not respond to the
1434 If a file takes a long time to execute, there may be a bug in that file.
1438 \f[B]SIGTERM\f[R] and \f[B]SIGQUIT\f[R] cause dc(1) to clean up and
1440 The one exception is \f[B]SIGHUP\f[R]; in that case, and only when dc(1)
1441 is in TTY mode (see the \f[B]TTY MODE\f[R] section), a \f[B]SIGHUP\f[R]
1444 dc(1) supports interactive command\-line editing.
1446 If dc(1) can be in TTY mode (see the \f[B]TTY MODE\f[R] section),
1448 This means that command\-line history can only be enabled when
1449 \f[B]stdin\f[R], \f[B]stdout\f[R], and \f[B]stderr\f[R] are all
1450 connected to a TTY.
1453 variable \f[B]DC_TTY_MODE\f[R] (see the \f[B]ENVIRONMENT VARIABLES\f[R]
1456 \f[B]Note\f[R]: tabs are converted to 8 spaces.
1459 locales and thus, supports \f[B]LC_MESSAGES\f[R].
1464 operators in the IEEE Std 1003.1\-2017 (\[lq]POSIX.1\-2017\[rq]) bc(1)