]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bc/manuals/dc/EP.1
mlx4en(4): Fix wrong mbuf cluster size in mlx4_en_debugnet_init()
[FreeBSD/FreeBSD.git] / contrib / bc / manuals / dc / EP.1
1 .\"
2 .\" SPDX-License-Identifier: BSD-2-Clause
3 .\"
4 .\" Copyright (c) 2018-2021 Gavin D. Howard and contributors.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions are met:
8 .\"
9 .\" * Redistributions of source code must retain the above copyright notice,
10 .\"   this list of conditions and the following disclaimer.
11 .\"
12 .\" * Redistributions in binary form must reproduce the above copyright notice,
13 .\"   this list of conditions and the following disclaimer in the documentation
14 .\"   and/or other materials provided with the distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 .\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 .\" POSSIBILITY OF SUCH DAMAGE.
27 .\"
28 .TH "DC" "1" "April 2021" "Gavin D. Howard" "General Commands Manual"
29 .SH Name
30 .PP
31 dc - arbitrary-precision decimal reverse-Polish notation calculator
32 .SH SYNOPSIS
33 .PP
34 \f[B]dc\f[R] [\f[B]-hiPRvVx\f[R]] [\f[B]--version\f[R]]
35 [\f[B]--help\f[R]] [\f[B]--interactive\f[R]] [\f[B]--no-prompt\f[R]]
36 [\f[B]--no-read-prompt\f[R]] [\f[B]--extended-register\f[R]]
37 [\f[B]-e\f[R] \f[I]expr\f[R]] [\f[B]--expression\f[R]=\f[I]expr\f[R]...]
38 [\f[B]-f\f[R] \f[I]file\f[R]...] [\f[B]--file\f[R]=\f[I]file\f[R]...]
39 [\f[I]file\f[R]...]
40 .SH DESCRIPTION
41 .PP
42 dc(1) is an arbitrary-precision calculator.
43 It uses a stack (reverse Polish notation) to store numbers and results
44 of computations.
45 Arithmetic operations pop arguments off of the stack and push the
46 results.
47 .PP
48 If no files are given on the command-line as extra arguments (i.e., not
49 as \f[B]-f\f[R] or \f[B]--file\f[R] arguments), then dc(1) reads from
50 \f[B]stdin\f[R].
51 Otherwise, those files are processed, and dc(1) will then exit.
52 .PP
53 This is different from the dc(1) on OpenBSD and possibly other dc(1)
54 implementations, where \f[B]-e\f[R] (\f[B]--expression\f[R]) and
55 \f[B]-f\f[R] (\f[B]--file\f[R]) arguments cause dc(1) to execute them
56 and exit.
57 The reason for this is that this dc(1) allows users to set arguments in
58 the environment variable \f[B]DC_ENV_ARGS\f[R] (see the \f[B]ENVIRONMENT
59 VARIABLES\f[R] section).
60 Any expressions given on the command-line should be used to set up a
61 standard environment.
62 For example, if a user wants the \f[B]scale\f[R] always set to
63 \f[B]10\f[R], they can set \f[B]DC_ENV_ARGS\f[R] to \f[B]-e 10k\f[R],
64 and this dc(1) will always start with a \f[B]scale\f[R] of \f[B]10\f[R].
65 .PP
66 If users want to have dc(1) exit after processing all input from
67 \f[B]-e\f[R] and \f[B]-f\f[R] arguments (and their equivalents), then
68 they can just simply add \f[B]-e q\f[R] as the last command-line
69 argument or define the environment variable \f[B]DC_EXPR_EXIT\f[R].
70 .SH OPTIONS
71 .PP
72 The following are the options that dc(1) accepts.
73 .PP
74 \f[B]-h\f[R], \f[B]--help\f[R]
75 .PP
76 : Prints a usage message and quits.
77 .PP
78 \f[B]-v\f[R], \f[B]-V\f[R], \f[B]--version\f[R]
79 .PP
80 : Print the version information (copyright header) and exit.
81 .PP
82 \f[B]-i\f[R], \f[B]--interactive\f[R]
83 .PP
84 : Forces interactive mode.
85 (See the \f[B]INTERACTIVE MODE\f[R] section.)
86 .IP
87 .nf
88 \f[C]
89 This is a **non-portable extension**.
90 \f[R]
91 .fi
92 .PP
93 \f[B]-P\f[R], \f[B]--no-prompt\f[R]
94 .PP
95 : This option is a no-op.
96 .IP
97 .nf
98 \f[C]
99 This is a **non-portable extension**.
100 \f[R]
101 .fi
102 .PP
103 \f[B]-R\f[R], \f[B]--no-read-prompt\f[R]
104 .PP
105 : This option is a no-op.
106 .IP
107 .nf
108 \f[C]
109 This is a **non-portable extension**.
110 \f[R]
111 .fi
112 .PP
113 \f[B]-x\f[R] \f[B]--extended-register\f[R]
114 .PP
115 : Enables extended register mode.
116 See the \f[I]Extended Register Mode\f[R] subsection of the
117 \f[B]REGISTERS\f[R] section for more information.
118 .IP
119 .nf
120 \f[C]
121 This is a **non-portable extension**.
122 \f[R]
123 .fi
124 .PP
125 \f[B]-e\f[R] \f[I]expr\f[R], \f[B]--expression\f[R]=\f[I]expr\f[R]
126 .PP
127 : Evaluates \f[I]expr\f[R].
128 If multiple expressions are given, they are evaluated in order.
129 If files are given as well (see below), the expressions and files are
130 evaluated in the order given.
131 This means that if a file is given before an expression, the file is
132 read in and evaluated first.
133 .IP
134 .nf
135 \f[C]
136 If this option is given on the command-line (i.e., not in **DC_ENV_ARGS**,
137 see the **ENVIRONMENT VARIABLES** section), then after processing all
138 expressions and files, dc(1) will exit, unless **-** (**stdin**) was given
139 as an argument at least once to **-f** or **-\[rs]-file**, whether on the
140 command-line or in **DC_ENV_ARGS**. However, if any other **-e**,
141 **-\[rs]-expression**, **-f**, or **-\[rs]-file** arguments are given after **-f-**
142 or equivalent is given, dc(1) will give a fatal error and exit.
143
144 This is a **non-portable extension**.
145 \f[R]
146 .fi
147 .PP
148 \f[B]-f\f[R] \f[I]file\f[R], \f[B]--file\f[R]=\f[I]file\f[R]
149 .PP
150 : Reads in \f[I]file\f[R] and evaluates it, line by line, as though it
151 were read through \f[B]stdin\f[R].
152 If expressions are also given (see above), the expressions are evaluated
153 in the order given.
154 .IP
155 .nf
156 \f[C]
157 If this option is given on the command-line (i.e., not in **DC_ENV_ARGS**,
158 see the **ENVIRONMENT VARIABLES** section), then after processing all
159 expressions and files, dc(1) will exit, unless **-** (**stdin**) was given
160 as an argument at least once to **-f** or **-\[rs]-file**. However, if any other
161 **-e**, **-\[rs]-expression**, **-f**, or **-\[rs]-file** arguments are given after
162 **-f-** or equivalent is given, dc(1) will give a fatal error and exit.
163
164 This is a **non-portable extension**.
165 \f[R]
166 .fi
167 .PP
168 All long options are \f[B]non-portable extensions\f[R].
169 .SH STDOUT
170 .PP
171 Any non-error output is written to \f[B]stdout\f[R].
172 In addition, if history (see the \f[B]HISTORY\f[R] section) and the
173 prompt (see the \f[B]TTY MODE\f[R] section) are enabled, both are output
174 to \f[B]stdout\f[R].
175 .PP
176 \f[B]Note\f[R]: Unlike other dc(1) implementations, this dc(1) will
177 issue a fatal error (see the \f[B]EXIT STATUS\f[R] section) if it cannot
178 write to \f[B]stdout\f[R], so if \f[B]stdout\f[R] is closed, as in
179 \f[B]dc >&-\f[R], it will quit with an error.
180 This is done so that dc(1) can report problems when \f[B]stdout\f[R] is
181 redirected to a file.
182 .PP
183 If there are scripts that depend on the behavior of other dc(1)
184 implementations, it is recommended that those scripts be changed to
185 redirect \f[B]stdout\f[R] to \f[B]/dev/null\f[R].
186 .SH STDERR
187 .PP
188 Any error output is written to \f[B]stderr\f[R].
189 .PP
190 \f[B]Note\f[R]: Unlike other dc(1) implementations, this dc(1) will
191 issue a fatal error (see the \f[B]EXIT STATUS\f[R] section) if it cannot
192 write to \f[B]stderr\f[R], so if \f[B]stderr\f[R] is closed, as in
193 \f[B]dc 2>&-\f[R], it will quit with an error.
194 This is done so that dc(1) can exit with an error code when
195 \f[B]stderr\f[R] is redirected to a file.
196 .PP
197 If there are scripts that depend on the behavior of other dc(1)
198 implementations, it is recommended that those scripts be changed to
199 redirect \f[B]stderr\f[R] to \f[B]/dev/null\f[R].
200 .SH SYNTAX
201 .PP
202 Each item in the input source code, either a number (see the
203 \f[B]NUMBERS\f[R] section) or a command (see the \f[B]COMMANDS\f[R]
204 section), is processed and executed, in order.
205 Input is processed immediately when entered.
206 .PP
207 \f[B]ibase\f[R] is a register (see the \f[B]REGISTERS\f[R] section) that
208 determines how to interpret constant numbers.
209 It is the \[dq]input\[dq] base, or the number base used for interpreting
210 input numbers.
211 \f[B]ibase\f[R] is initially \f[B]10\f[R].
212 The max allowable value for \f[B]ibase\f[R] is \f[B]16\f[R].
213 The min allowable value for \f[B]ibase\f[R] is \f[B]2\f[R].
214 The max allowable value for \f[B]ibase\f[R] can be queried in dc(1)
215 programs with the \f[B]T\f[R] command.
216 .PP
217 \f[B]obase\f[R] is a register (see the \f[B]REGISTERS\f[R] section) that
218 determines how to output results.
219 It is the \[dq]output\[dq] base, or the number base used for outputting
220 numbers.
221 \f[B]obase\f[R] is initially \f[B]10\f[R].
222 The max allowable value for \f[B]obase\f[R] is \f[B]DC_BASE_MAX\f[R] and
223 can be queried with the \f[B]U\f[R] command.
224 The min allowable value for \f[B]obase\f[R] is \f[B]2\f[R].
225 Values are output in the specified base.
226 .PP
227 The \f[I]scale\f[R] of an expression is the number of digits in the
228 result of the expression right of the decimal point, and \f[B]scale\f[R]
229 is a register (see the \f[B]REGISTERS\f[R] section) that sets the
230 precision of any operations (with exceptions).
231 \f[B]scale\f[R] is initially \f[B]0\f[R].
232 \f[B]scale\f[R] cannot be negative.
233 The max allowable value for \f[B]scale\f[R] can be queried in dc(1)
234 programs with the \f[B]V\f[R] command.
235 .SS Comments
236 .PP
237 Comments go from \f[B]#\f[R] until, and not including, the next newline.
238 This is a \f[B]non-portable extension\f[R].
239 .SH NUMBERS
240 .PP
241 Numbers are strings made up of digits, uppercase letters up to
242 \f[B]F\f[R], and at most \f[B]1\f[R] period for a radix.
243 Numbers can have up to \f[B]DC_NUM_MAX\f[R] digits.
244 Uppercase letters are equal to \f[B]9\f[R] + their position in the
245 alphabet (i.e., \f[B]A\f[R] equals \f[B]10\f[R], or \f[B]9+1\f[R]).
246 If a digit or letter makes no sense with the current value of
247 \f[B]ibase\f[R], they are set to the value of the highest valid digit in
248 \f[B]ibase\f[R].
249 .PP
250 Single-character numbers (i.e., \f[B]A\f[R] alone) take the value that
251 they would have if they were valid digits, regardless of the value of
252 \f[B]ibase\f[R].
253 This means that \f[B]A\f[R] alone always equals decimal \f[B]10\f[R] and
254 \f[B]F\f[R] alone always equals decimal \f[B]15\f[R].
255 .SH COMMANDS
256 .PP
257 The valid commands are listed below.
258 .SS Printing
259 .PP
260 These commands are used for printing.
261 .PP
262 \f[B]p\f[R]
263 .PP
264 : Prints the value on top of the stack, whether number or string, and
265 prints a newline after.
266 .IP
267 .nf
268 \f[C]
269 This does not alter the stack.
270 \f[R]
271 .fi
272 .PP
273 \f[B]n\f[R]
274 .PP
275 : Prints the value on top of the stack, whether number or string, and
276 pops it off of the stack.
277 .PP
278 \f[B]P\f[R]
279 .PP
280 : Pops a value off the stack.
281 .IP
282 .nf
283 \f[C]
284 If the value is a number, it is truncated and the absolute value of the
285 result is printed as though **obase** is **UCHAR_MAX+1** and each digit is
286 interpreted as an ASCII character, making it a byte stream.
287
288 If the value is a string, it is printed without a trailing newline.
289
290 This is a **non-portable extension**.
291 \f[R]
292 .fi
293 .PP
294 \f[B]f\f[R]
295 .PP
296 : Prints the entire contents of the stack, in order from newest to
297 oldest, without altering anything.
298 .IP
299 .nf
300 \f[C]
301 Users should use this command when they get lost.
302 \f[R]
303 .fi
304 .SS Arithmetic
305 .PP
306 These are the commands used for arithmetic.
307 .PP
308 \f[B]+\f[R]
309 .PP
310 : The top two values are popped off the stack, added, and the result is
311 pushed onto the stack.
312 The \f[I]scale\f[R] of the result is equal to the max \f[I]scale\f[R] of
313 both operands.
314 .PP
315 \f[B]-\f[R]
316 .PP
317 : The top two values are popped off the stack, subtracted, and the
318 result is pushed onto the stack.
319 The \f[I]scale\f[R] of the result is equal to the max \f[I]scale\f[R] of
320 both operands.
321 .PP
322 \f[B]*\f[R]
323 .PP
324 : The top two values are popped off the stack, multiplied, and the
325 result is pushed onto the stack.
326 If \f[B]a\f[R] is the \f[I]scale\f[R] of the first expression and
327 \f[B]b\f[R] is the \f[I]scale\f[R] of the second expression, the
328 \f[I]scale\f[R] of the result is equal to
329 \f[B]min(a+b,max(scale,a,b))\f[R] where \f[B]min()\f[R] and
330 \f[B]max()\f[R] return the obvious values.
331 .PP
332 \f[B]/\f[R]
333 .PP
334 : The top two values are popped off the stack, divided, and the result
335 is pushed onto the stack.
336 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
337 .IP
338 .nf
339 \f[C]
340 The first value popped off of the stack must be non-zero.
341 \f[R]
342 .fi
343 .PP
344 \f[B]%\f[R]
345 .PP
346 : The top two values are popped off the stack, remaindered, and the
347 result is pushed onto the stack.
348 .IP
349 .nf
350 \f[C]
351 Remaindering is equivalent to 1) Computing **a/b** to current **scale**, and
352 2) Using the result of step 1 to calculate **a-(a/b)\[rs]*b** to *scale*
353 **max(scale+scale(b),scale(a))**.
354
355 The first value popped off of the stack must be non-zero.
356 \f[R]
357 .fi
358 .PP
359 \f[B]\[ti]\f[R]
360 .PP
361 : The top two values are popped off the stack, divided and remaindered,
362 and the results (divided first, remainder second) are pushed onto the
363 stack.
364 This is equivalent to \f[B]x y / x y %\f[R] except that \f[B]x\f[R] and
365 \f[B]y\f[R] are only evaluated once.
366 .IP
367 .nf
368 \f[C]
369 The first value popped off of the stack must be non-zero.
370
371 This is a **non-portable extension**.
372 \f[R]
373 .fi
374 .PP
375 \f[B]\[ha]\f[R]
376 .PP
377 : The top two values are popped off the stack, the second is raised to
378 the power of the first, and the result is pushed onto the stack.
379 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
380 .IP
381 .nf
382 \f[C]
383 The first value popped off of the stack must be an integer, and if that
384 value is negative, the second value popped off of the stack must be
385 non-zero.
386 \f[R]
387 .fi
388 .PP
389 \f[B]v\f[R]
390 .PP
391 : The top value is popped off the stack, its square root is computed,
392 and the result is pushed onto the stack.
393 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
394 .IP
395 .nf
396 \f[C]
397 The value popped off of the stack must be non-negative.
398 \f[R]
399 .fi
400 .PP
401 \f[B]_\f[R]
402 .PP
403 : If this command \f[I]immediately\f[R] precedes a number (i.e., no
404 spaces or other commands), then that number is input as a negative
405 number.
406 .IP
407 .nf
408 \f[C]
409 Otherwise, the top value on the stack is popped and copied, and the copy is
410 negated and pushed onto the stack. This behavior without a number is a
411 **non-portable extension**.
412 \f[R]
413 .fi
414 .PP
415 \f[B]b\f[R]
416 .PP
417 : The top value is popped off the stack, and if it is zero, it is pushed
418 back onto the stack.
419 Otherwise, its absolute value is pushed onto the stack.
420 .IP
421 .nf
422 \f[C]
423 This is a **non-portable extension**.
424 \f[R]
425 .fi
426 .PP
427 \f[B]|\f[R]
428 .PP
429 : The top three values are popped off the stack, a modular
430 exponentiation is computed, and the result is pushed onto the stack.
431 .IP
432 .nf
433 \f[C]
434 The first value popped is used as the reduction modulus and must be an
435 integer and non-zero. The second value popped is used as the exponent and
436 must be an integer and non-negative. The third value popped is the base and
437 must be an integer.
438
439 This is a **non-portable extension**.
440 \f[R]
441 .fi
442 .PP
443 \f[B]G\f[R]
444 .PP
445 : The top two values are popped off of the stack, they are compared, and
446 a \f[B]1\f[R] is pushed if they are equal, or \f[B]0\f[R] otherwise.
447 .IP
448 .nf
449 \f[C]
450 This is a **non-portable extension**.
451 \f[R]
452 .fi
453 .PP
454 \f[B]N\f[R]
455 .PP
456 : The top value is popped off of the stack, and if it a \f[B]0\f[R], a
457 \f[B]1\f[R] is pushed; otherwise, a \f[B]0\f[R] is pushed.
458 .IP
459 .nf
460 \f[C]
461 This is a **non-portable extension**.
462 \f[R]
463 .fi
464 .PP
465 \f[B](\f[R]
466 .PP
467 : The top two values are popped off of the stack, they are compared, and
468 a \f[B]1\f[R] is pushed if the first is less than the second, or
469 \f[B]0\f[R] otherwise.
470 .IP
471 .nf
472 \f[C]
473 This is a **non-portable extension**.
474 \f[R]
475 .fi
476 .PP
477 \f[B]{\f[R]
478 .PP
479 : The top two values are popped off of the stack, they are compared, and
480 a \f[B]1\f[R] is pushed if the first is less than or equal to the
481 second, or \f[B]0\f[R] otherwise.
482 .IP
483 .nf
484 \f[C]
485 This is a **non-portable extension**.
486 \f[R]
487 .fi
488 .PP
489 \f[B])\f[R]
490 .PP
491 : The top two values are popped off of the stack, they are compared, and
492 a \f[B]1\f[R] is pushed if the first is greater than the second, or
493 \f[B]0\f[R] otherwise.
494 .IP
495 .nf
496 \f[C]
497 This is a **non-portable extension**.
498 \f[R]
499 .fi
500 .PP
501 \f[B]}\f[R]
502 .PP
503 : The top two values are popped off of the stack, they are compared, and
504 a \f[B]1\f[R] is pushed if the first is greater than or equal to the
505 second, or \f[B]0\f[R] otherwise.
506 .IP
507 .nf
508 \f[C]
509 This is a **non-portable extension**.
510 \f[R]
511 .fi
512 .PP
513 \f[B]M\f[R]
514 .PP
515 : The top two values are popped off of the stack.
516 If they are both non-zero, a \f[B]1\f[R] is pushed onto the stack.
517 If either of them is zero, or both of them are, then a \f[B]0\f[R] is
518 pushed onto the stack.
519 .IP
520 .nf
521 \f[C]
522 This is like the **&&** operator in bc(1), and it is *not* a short-circuit
523 operator.
524
525 This is a **non-portable extension**.
526 \f[R]
527 .fi
528 .PP
529 \f[B]m\f[R]
530 .PP
531 : The top two values are popped off of the stack.
532 If at least one of them is non-zero, a \f[B]1\f[R] is pushed onto the
533 stack.
534 If both of them are zero, then a \f[B]0\f[R] is pushed onto the stack.
535 .IP
536 .nf
537 \f[C]
538 This is like the **||** operator in bc(1), and it is *not* a short-circuit
539 operator.
540
541 This is a **non-portable extension**.
542 \f[R]
543 .fi
544 .SS Stack Control
545 .PP
546 These commands control the stack.
547 .PP
548 \f[B]c\f[R]
549 .PP
550 : Removes all items from (\[dq]clears\[dq]) the stack.
551 .PP
552 \f[B]d\f[R]
553 .PP
554 : Copies the item on top of the stack (\[dq]duplicates\[dq]) and pushes
555 the copy onto the stack.
556 .PP
557 \f[B]r\f[R]
558 .PP
559 : Swaps (\[dq]reverses\[dq]) the two top items on the stack.
560 .PP
561 \f[B]R\f[R]
562 .PP
563 : Pops (\[dq]removes\[dq]) the top value from the stack.
564 .SS Register Control
565 .PP
566 These commands control registers (see the \f[B]REGISTERS\f[R] section).
567 .PP
568 \f[B]s\f[R]\f[I]r\f[R]
569 .PP
570 : Pops the value off the top of the stack and stores it into register
571 \f[I]r\f[R].
572 .PP
573 \f[B]l\f[R]\f[I]r\f[R]
574 .PP
575 : Copies the value in register \f[I]r\f[R] and pushes it onto the stack.
576 This does not alter the contents of \f[I]r\f[R].
577 .PP
578 \f[B]S\f[R]\f[I]r\f[R]
579 .PP
580 : Pops the value off the top of the (main) stack and pushes it onto the
581 stack of register \f[I]r\f[R].
582 The previous value of the register becomes inaccessible.
583 .PP
584 \f[B]L\f[R]\f[I]r\f[R]
585 .PP
586 : Pops the value off the top of the stack for register \f[I]r\f[R] and
587 push it onto the main stack.
588 The previous value in the stack for register \f[I]r\f[R], if any, is now
589 accessible via the \f[B]l\f[R]\f[I]r\f[R] command.
590 .SS Parameters
591 .PP
592 These commands control the values of \f[B]ibase\f[R], \f[B]obase\f[R],
593 and \f[B]scale\f[R].
594 Also see the \f[B]SYNTAX\f[R] section.
595 .PP
596 \f[B]i\f[R]
597 .PP
598 : Pops the value off of the top of the stack and uses it to set
599 \f[B]ibase\f[R], which must be between \f[B]2\f[R] and \f[B]16\f[R],
600 inclusive.
601 .IP
602 .nf
603 \f[C]
604 If the value on top of the stack has any *scale*, the *scale* is ignored.
605 \f[R]
606 .fi
607 .PP
608 \f[B]o\f[R]
609 .PP
610 : Pops the value off of the top of the stack and uses it to set
611 \f[B]obase\f[R], which must be between \f[B]2\f[R] and
612 \f[B]DC_BASE_MAX\f[R], inclusive (see the \f[B]LIMITS\f[R] section).
613 .IP
614 .nf
615 \f[C]
616 If the value on top of the stack has any *scale*, the *scale* is ignored.
617 \f[R]
618 .fi
619 .PP
620 \f[B]k\f[R]
621 .PP
622 : Pops the value off of the top of the stack and uses it to set
623 \f[B]scale\f[R], which must be non-negative.
624 .IP
625 .nf
626 \f[C]
627 If the value on top of the stack has any *scale*, the *scale* is ignored.
628 \f[R]
629 .fi
630 .PP
631 \f[B]I\f[R]
632 .PP
633 : Pushes the current value of \f[B]ibase\f[R] onto the main stack.
634 .PP
635 \f[B]O\f[R]
636 .PP
637 : Pushes the current value of \f[B]obase\f[R] onto the main stack.
638 .PP
639 \f[B]K\f[R]
640 .PP
641 : Pushes the current value of \f[B]scale\f[R] onto the main stack.
642 .PP
643 \f[B]T\f[R]
644 .PP
645 : Pushes the maximum allowable value of \f[B]ibase\f[R] onto the main
646 stack.
647 .IP
648 .nf
649 \f[C]
650 This is a **non-portable extension**.
651 \f[R]
652 .fi
653 .PP
654 \f[B]U\f[R]
655 .PP
656 : Pushes the maximum allowable value of \f[B]obase\f[R] onto the main
657 stack.
658 .IP
659 .nf
660 \f[C]
661 This is a **non-portable extension**.
662 \f[R]
663 .fi
664 .PP
665 \f[B]V\f[R]
666 .PP
667 : Pushes the maximum allowable value of \f[B]scale\f[R] onto the main
668 stack.
669 .IP
670 .nf
671 \f[C]
672 This is a **non-portable extension**.
673 \f[R]
674 .fi
675 .SS Strings
676 .PP
677 The following commands control strings.
678 .PP
679 dc(1) can work with both numbers and strings, and registers (see the
680 \f[B]REGISTERS\f[R] section) can hold both strings and numbers.
681 dc(1) always knows whether the contents of a register are a string or a
682 number.
683 .PP
684 While arithmetic operations have to have numbers, and will print an
685 error if given a string, other commands accept strings.
686 .PP
687 Strings can also be executed as macros.
688 For example, if the string \f[B][1pR]\f[R] is executed as a macro, then
689 the code \f[B]1pR\f[R] is executed, meaning that the \f[B]1\f[R] will be
690 printed with a newline after and then popped from the stack.
691 .PP
692 \f[B][\f[R]\f[I]characters\f[R]\f[B]]\f[R]
693 .PP
694 : Makes a string containing \f[I]characters\f[R] and pushes it onto the
695 stack.
696 .IP
697 .nf
698 \f[C]
699 If there are brackets (**\[rs][** and **\[rs]]**) in the string, then they must be
700 balanced. Unbalanced brackets can be escaped using a backslash (**\[rs]\[rs]**)
701 character.
702
703 If there is a backslash character in the string, the character after it
704 (even another backslash) is put into the string verbatim, but the (first)
705 backslash is not.
706 \f[R]
707 .fi
708 .PP
709 \f[B]a\f[R]
710 .PP
711 : The value on top of the stack is popped.
712 .IP
713 .nf
714 \f[C]
715 If it is a number, it is truncated and its absolute value is taken. The
716 result mod **UCHAR_MAX+1** is calculated. If that result is **0**, push an
717 empty string; otherwise, push a one-character string where the character is
718 the result of the mod interpreted as an ASCII character.
719
720 If it is a string, then a new string is made. If the original string is
721 empty, the new string is empty. If it is not, then the first character of
722 the original string is used to create the new string as a one-character
723 string. The new string is then pushed onto the stack.
724
725 This is a **non-portable extension**.
726 \f[R]
727 .fi
728 .PP
729 \f[B]x\f[R]
730 .PP
731 : Pops a value off of the top of the stack.
732 .IP
733 .nf
734 \f[C]
735 If it is a number, it is pushed back onto the stack.
736
737 If it is a string, it is executed as a macro.
738
739 This behavior is the norm whenever a macro is executed, whether by this
740 command or by the conditional execution commands below.
741 \f[R]
742 .fi
743 .PP
744 \f[B]>\f[R]\f[I]r\f[R]
745 .PP
746 : Pops two values off of the stack that must be numbers and compares
747 them.
748 If the first value is greater than the second, then the contents of
749 register \f[I]r\f[R] are executed.
750 .IP
751 .nf
752 \f[C]
753 For example, **0 1>a** will execute the contents of register **a**, and
754 **1 0>a** will not.
755
756 If either or both of the values are not numbers, dc(1) will raise an error
757 and reset (see the **RESET** section).
758 \f[R]
759 .fi
760 .PP
761 \f[B]>\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
762 .PP
763 : Like the above, but will execute register \f[I]s\f[R] if the
764 comparison fails.
765 .IP
766 .nf
767 \f[C]
768 If either or both of the values are not numbers, dc(1) will raise an error
769 and reset (see the **RESET** section).
770
771 This is a **non-portable extension**.
772 \f[R]
773 .fi
774 .PP
775 \f[B]!>\f[R]\f[I]r\f[R]
776 .PP
777 : Pops two values off of the stack that must be numbers and compares
778 them.
779 If the first value is not greater than the second (less than or equal
780 to), then the contents of register \f[I]r\f[R] are executed.
781 .IP
782 .nf
783 \f[C]
784 If either or both of the values are not numbers, dc(1) will raise an error
785 and reset (see the **RESET** section).
786 \f[R]
787 .fi
788 .PP
789 \f[B]!>\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
790 .PP
791 : Like the above, but will execute register \f[I]s\f[R] if the
792 comparison fails.
793 .IP
794 .nf
795 \f[C]
796 If either or both of the values are not numbers, dc(1) will raise an error
797 and reset (see the **RESET** section).
798
799 This is a **non-portable extension**.
800 \f[R]
801 .fi
802 .PP
803 \f[B]<\f[R]\f[I]r\f[R]
804 .PP
805 : Pops two values off of the stack that must be numbers and compares
806 them.
807 If the first value is less than the second, then the contents of
808 register \f[I]r\f[R] are executed.
809 .IP
810 .nf
811 \f[C]
812 If either or both of the values are not numbers, dc(1) will raise an error
813 and reset (see the **RESET** section).
814 \f[R]
815 .fi
816 .PP
817 \f[B]<\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
818 .PP
819 : Like the above, but will execute register \f[I]s\f[R] if the
820 comparison fails.
821 .IP
822 .nf
823 \f[C]
824 If either or both of the values are not numbers, dc(1) will raise an error
825 and reset (see the **RESET** section).
826
827 This is a **non-portable extension**.
828 \f[R]
829 .fi
830 .PP
831 \f[B]!<\f[R]\f[I]r\f[R]
832 .PP
833 : Pops two values off of the stack that must be numbers and compares
834 them.
835 If the first value is not less than the second (greater than or equal
836 to), then the contents of register \f[I]r\f[R] are executed.
837 .IP
838 .nf
839 \f[C]
840 If either or both of the values are not numbers, dc(1) will raise an error
841 and reset (see the **RESET** section).
842 \f[R]
843 .fi
844 .PP
845 \f[B]!<\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
846 .PP
847 : Like the above, but will execute register \f[I]s\f[R] if the
848 comparison fails.
849 .IP
850 .nf
851 \f[C]
852 If either or both of the values are not numbers, dc(1) will raise an error
853 and reset (see the **RESET** section).
854
855 This is a **non-portable extension**.
856 \f[R]
857 .fi
858 .PP
859 \f[B]=\f[R]\f[I]r\f[R]
860 .PP
861 : Pops two values off of the stack that must be numbers and compares
862 them.
863 If the first value is equal to the second, then the contents of register
864 \f[I]r\f[R] are executed.
865 .IP
866 .nf
867 \f[C]
868 If either or both of the values are not numbers, dc(1) will raise an error
869 and reset (see the **RESET** section).
870 \f[R]
871 .fi
872 .PP
873 \f[B]=\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
874 .PP
875 : Like the above, but will execute register \f[I]s\f[R] if the
876 comparison fails.
877 .IP
878 .nf
879 \f[C]
880 If either or both of the values are not numbers, dc(1) will raise an error
881 and reset (see the **RESET** section).
882
883 This is a **non-portable extension**.
884 \f[R]
885 .fi
886 .PP
887 \f[B]!=\f[R]\f[I]r\f[R]
888 .PP
889 : Pops two values off of the stack that must be numbers and compares
890 them.
891 If the first value is not equal to the second, then the contents of
892 register \f[I]r\f[R] are executed.
893 .IP
894 .nf
895 \f[C]
896 If either or both of the values are not numbers, dc(1) will raise an error
897 and reset (see the **RESET** section).
898 \f[R]
899 .fi
900 .PP
901 \f[B]!=\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
902 .PP
903 : Like the above, but will execute register \f[I]s\f[R] if the
904 comparison fails.
905 .IP
906 .nf
907 \f[C]
908 If either or both of the values are not numbers, dc(1) will raise an error
909 and reset (see the **RESET** section).
910
911 This is a **non-portable extension**.
912 \f[R]
913 .fi
914 .PP
915 \f[B]?\f[R]
916 .PP
917 : Reads a line from the \f[B]stdin\f[R] and executes it.
918 This is to allow macros to request input from users.
919 .PP
920 \f[B]q\f[R]
921 .PP
922 : During execution of a macro, this exits the execution of that macro
923 and the execution of the macro that executed it.
924 If there are no macros, or only one macro executing, dc(1) exits.
925 .PP
926 \f[B]Q\f[R]
927 .PP
928 : Pops a value from the stack which must be non-negative and is used the
929 number of macro executions to pop off of the execution stack.
930 If the number of levels to pop is greater than the number of executing
931 macros, dc(1) exits.
932 .SS Status
933 .PP
934 These commands query status of the stack or its top value.
935 .PP
936 \f[B]Z\f[R]
937 .PP
938 : Pops a value off of the stack.
939 .IP
940 .nf
941 \f[C]
942 If it is a number, calculates the number of significant decimal digits it
943 has and pushes the result.
944
945 If it is a string, pushes the number of characters the string has.
946 \f[R]
947 .fi
948 .PP
949 \f[B]X\f[R]
950 .PP
951 : Pops a value off of the stack.
952 .IP
953 .nf
954 \f[C]
955 If it is a number, pushes the *scale* of the value onto the stack.
956
957 If it is a string, pushes **0**.
958 \f[R]
959 .fi
960 .PP
961 \f[B]z\f[R]
962 .PP
963 : Pushes the current stack depth (before execution of this command).
964 .SS Arrays
965 .PP
966 These commands manipulate arrays.
967 .PP
968 \f[B]:\f[R]\f[I]r\f[R]
969 .PP
970 : Pops the top two values off of the stack.
971 The second value will be stored in the array \f[I]r\f[R] (see the
972 \f[B]REGISTERS\f[R] section), indexed by the first value.
973 .PP
974 \f[B];\f[R]\f[I]r\f[R]
975 .PP
976 : Pops the value on top of the stack and uses it as an index into the
977 array \f[I]r\f[R].
978 The selected value is then pushed onto the stack.
979 .SH REGISTERS
980 .PP
981 Registers are names that can store strings, numbers, and arrays.
982 (Number/string registers do not interfere with array registers.)
983 .PP
984 Each register is also its own stack, so the current register value is
985 the top of the stack for the register.
986 All registers, when first referenced, have one value (\f[B]0\f[R]) in
987 their stack.
988 .PP
989 In non-extended register mode, a register name is just the single
990 character that follows any command that needs a register name.
991 The only exception is a newline (\f[B]\[aq]\[rs]n\[aq]\f[R]); it is a
992 parse error for a newline to be used as a register name.
993 .SS Extended Register Mode
994 .PP
995 Unlike most other dc(1) implentations, this dc(1) provides nearly
996 unlimited amounts of registers, if extended register mode is enabled.
997 .PP
998 If extended register mode is enabled (\f[B]-x\f[R] or
999 \f[B]--extended-register\f[R] command-line arguments are given), then
1000 normal single character registers are used \f[I]unless\f[R] the
1001 character immediately following a command that needs a register name is
1002 a space (according to \f[B]isspace()\f[R]) and not a newline
1003 (\f[B]\[aq]\[rs]n\[aq]\f[R]).
1004 .PP
1005 In that case, the register name is found according to the regex
1006 \f[B][a-z][a-z0-9_]*\f[R] (like bc(1) identifiers), and it is a parse
1007 error if the next non-space characters do not match that regex.
1008 .SH RESET
1009 .PP
1010 When dc(1) encounters an error or a signal that it has a non-default
1011 handler for, it resets.
1012 This means that several things happen.
1013 .PP
1014 First, any macros that are executing are stopped and popped off the
1015 stack.
1016 The behavior is not unlike that of exceptions in programming languages.
1017 Then the execution point is set so that any code waiting to execute
1018 (after all macros returned) is skipped.
1019 .PP
1020 Thus, when dc(1) resets, it skips any remaining code waiting to be
1021 executed.
1022 Then, if it is interactive mode, and the error was not a fatal error
1023 (see the \f[B]EXIT STATUS\f[R] section), it asks for more input;
1024 otherwise, it exits with the appropriate return code.
1025 .SH PERFORMANCE
1026 .PP
1027 Most dc(1) implementations use \f[B]char\f[R] types to calculate the
1028 value of \f[B]1\f[R] decimal digit at a time, but that can be slow.
1029 This dc(1) does something different.
1030 .PP
1031 It uses large integers to calculate more than \f[B]1\f[R] decimal digit
1032 at a time.
1033 If built in a environment where \f[B]DC_LONG_BIT\f[R] (see the
1034 \f[B]LIMITS\f[R] section) is \f[B]64\f[R], then each integer has
1035 \f[B]9\f[R] decimal digits.
1036 If built in an environment where \f[B]DC_LONG_BIT\f[R] is \f[B]32\f[R]
1037 then each integer has \f[B]4\f[R] decimal digits.
1038 This value (the number of decimal digits per large integer) is called
1039 \f[B]DC_BASE_DIGS\f[R].
1040 .PP
1041 In addition, this dc(1) uses an even larger integer for overflow
1042 checking.
1043 This integer type depends on the value of \f[B]DC_LONG_BIT\f[R], but is
1044 always at least twice as large as the integer type used to store digits.
1045 .SH LIMITS
1046 .PP
1047 The following are the limits on dc(1):
1048 .PP
1049 \f[B]DC_LONG_BIT\f[R]
1050 .PP
1051 : The number of bits in the \f[B]long\f[R] type in the environment where
1052 dc(1) was built.
1053 This determines how many decimal digits can be stored in a single large
1054 integer (see the \f[B]PERFORMANCE\f[R] section).
1055 .PP
1056 \f[B]DC_BASE_DIGS\f[R]
1057 .PP
1058 : The number of decimal digits per large integer (see the
1059 \f[B]PERFORMANCE\f[R] section).
1060 Depends on \f[B]DC_LONG_BIT\f[R].
1061 .PP
1062 \f[B]DC_BASE_POW\f[R]
1063 .PP
1064 : The max decimal number that each large integer can store (see
1065 \f[B]DC_BASE_DIGS\f[R]) plus \f[B]1\f[R].
1066 Depends on \f[B]DC_BASE_DIGS\f[R].
1067 .PP
1068 \f[B]DC_OVERFLOW_MAX\f[R]
1069 .PP
1070 : The max number that the overflow type (see the \f[B]PERFORMANCE\f[R]
1071 section) can hold.
1072 Depends on \f[B]DC_LONG_BIT\f[R].
1073 .PP
1074 \f[B]DC_BASE_MAX\f[R]
1075 .PP
1076 : The maximum output base.
1077 Set at \f[B]DC_BASE_POW\f[R].
1078 .PP
1079 \f[B]DC_DIM_MAX\f[R]
1080 .PP
1081 : The maximum size of arrays.
1082 Set at \f[B]SIZE_MAX-1\f[R].
1083 .PP
1084 \f[B]DC_SCALE_MAX\f[R]
1085 .PP
1086 : The maximum \f[B]scale\f[R].
1087 Set at \f[B]DC_OVERFLOW_MAX-1\f[R].
1088 .PP
1089 \f[B]DC_STRING_MAX\f[R]
1090 .PP
1091 : The maximum length of strings.
1092 Set at \f[B]DC_OVERFLOW_MAX-1\f[R].
1093 .PP
1094 \f[B]DC_NAME_MAX\f[R]
1095 .PP
1096 : The maximum length of identifiers.
1097 Set at \f[B]DC_OVERFLOW_MAX-1\f[R].
1098 .PP
1099 \f[B]DC_NUM_MAX\f[R]
1100 .PP
1101 : The maximum length of a number (in decimal digits), which includes
1102 digits after the decimal point.
1103 Set at \f[B]DC_OVERFLOW_MAX-1\f[R].
1104 .PP
1105 Exponent
1106 .PP
1107 : The maximum allowable exponent (positive or negative).
1108 Set at \f[B]DC_OVERFLOW_MAX\f[R].
1109 .PP
1110 Number of vars
1111 .PP
1112 : The maximum number of vars/arrays.
1113 Set at \f[B]SIZE_MAX-1\f[R].
1114 .PP
1115 These limits are meant to be effectively non-existent; the limits are so
1116 large (at least on 64-bit machines) that there should not be any point
1117 at which they become a problem.
1118 In fact, memory should be exhausted before these limits should be hit.
1119 .SH ENVIRONMENT VARIABLES
1120 .PP
1121 dc(1) recognizes the following environment variables:
1122 .PP
1123 \f[B]DC_ENV_ARGS\f[R]
1124 .PP
1125 : This is another way to give command-line arguments to dc(1).
1126 They should be in the same format as all other command-line arguments.
1127 These are always processed first, so any files given in
1128 \f[B]DC_ENV_ARGS\f[R] will be processed before arguments and files given
1129 on the command-line.
1130 This gives the user the ability to set up \[dq]standard\[dq] options and
1131 files to be used at every invocation.
1132 The most useful thing for such files to contain would be useful
1133 functions that the user might want every time dc(1) runs.
1134 Another use would be to use the \f[B]-e\f[R] option to set
1135 \f[B]scale\f[R] to a value other than \f[B]0\f[R].
1136 .IP
1137 .nf
1138 \f[C]
1139 The code that parses **DC_ENV_ARGS** will correctly handle quoted arguments,
1140 but it does not understand escape sequences. For example, the string
1141 **\[dq]/home/gavin/some dc file.dc\[dq]** will be correctly parsed, but the string
1142 **\[dq]/home/gavin/some \[rs]\[dq]dc\[rs]\[dq] file.dc\[dq]** will include the backslashes.
1143
1144 The quote parsing will handle either kind of quotes, **\[aq]** or **\[dq]**. Thus,
1145 if you have a file with any number of single quotes in the name, you can use
1146 double quotes as the outside quotes, as in **\[dq]some \[aq]dc\[aq] file.dc\[dq]**, and vice
1147 versa if you have a file with double quotes. However, handling a file with
1148 both kinds of quotes in **DC_ENV_ARGS** is not supported due to the
1149 complexity of the parsing, though such files are still supported on the
1150 command-line where the parsing is done by the shell.
1151 \f[R]
1152 .fi
1153 .PP
1154 \f[B]DC_LINE_LENGTH\f[R]
1155 .PP
1156 : If this environment variable exists and contains an integer that is
1157 greater than \f[B]1\f[R] and is less than \f[B]UINT16_MAX\f[R]
1158 (\f[B]2\[ha]16-1\f[R]), dc(1) will output lines to that length,
1159 including the backslash newline combo.
1160 The default line length is \f[B]70\f[R].
1161 .PP
1162 \f[B]DC_EXPR_EXIT\f[R]
1163 .PP
1164 : If this variable exists (no matter the contents), dc(1) will exit
1165 immediately after executing expressions and files given by the
1166 \f[B]-e\f[R] and/or \f[B]-f\f[R] command-line options (and any
1167 equivalents).
1168 .SH EXIT STATUS
1169 .PP
1170 dc(1) returns the following exit statuses:
1171 .PP
1172 \f[B]0\f[R]
1173 .PP
1174 : No error.
1175 .PP
1176 \f[B]1\f[R]
1177 .PP
1178 : A math error occurred.
1179 This follows standard practice of using \f[B]1\f[R] for expected errors,
1180 since math errors will happen in the process of normal execution.
1181 .IP
1182 .nf
1183 \f[C]
1184 Math errors include divide by **0**, taking the square root of a negative
1185 number, attempting to convert a negative number to a hardware integer,
1186 overflow when converting a number to a hardware integer, and attempting to
1187 use a non-integer where an integer is required.
1188
1189 Converting to a hardware integer happens for the second operand of the power
1190 (**\[rs]\[ha]**) operator.
1191 \f[R]
1192 .fi
1193 .PP
1194 \f[B]2\f[R]
1195 .PP
1196 : A parse error occurred.
1197 .IP
1198 .nf
1199 \f[C]
1200 Parse errors include unexpected **EOF**, using an invalid character, failing
1201 to find the end of a string or comment, and using a token where it is
1202 invalid.
1203 \f[R]
1204 .fi
1205 .PP
1206 \f[B]3\f[R]
1207 .PP
1208 : A runtime error occurred.
1209 .IP
1210 .nf
1211 \f[C]
1212 Runtime errors include assigning an invalid number to **ibase**, **obase**,
1213 or **scale**; give a bad expression to a **read()** call, calling **read()**
1214 inside of a **read()** call, type errors, and attempting an operation when
1215 the stack has too few elements.
1216 \f[R]
1217 .fi
1218 .PP
1219 \f[B]4\f[R]
1220 .PP
1221 : A fatal error occurred.
1222 .IP
1223 .nf
1224 \f[C]
1225 Fatal errors include memory allocation errors, I/O errors, failing to open
1226 files, attempting to use files that do not have only ASCII characters (dc(1)
1227 only accepts ASCII characters), attempting to open a directory as a file,
1228 and giving invalid command-line options.
1229 \f[R]
1230 .fi
1231 .PP
1232 The exit status \f[B]4\f[R] is special; when a fatal error occurs, dc(1)
1233 always exits and returns \f[B]4\f[R], no matter what mode dc(1) is in.
1234 .PP
1235 The other statuses will only be returned when dc(1) is not in
1236 interactive mode (see the \f[B]INTERACTIVE MODE\f[R] section), since
1237 dc(1) resets its state (see the \f[B]RESET\f[R] section) and accepts
1238 more input when one of those errors occurs in interactive mode.
1239 This is also the case when interactive mode is forced by the
1240 \f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
1241 .PP
1242 These exit statuses allow dc(1) to be used in shell scripting with error
1243 checking, and its normal behavior can be forced by using the
1244 \f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
1245 .SH INTERACTIVE MODE
1246 .PP
1247 Like bc(1), dc(1) has an interactive mode and a non-interactive mode.
1248 Interactive mode is turned on automatically when both \f[B]stdin\f[R]
1249 and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
1250 and \f[B]--interactive\f[R] option can turn it on in other cases.
1251 .PP
1252 In interactive mode, dc(1) attempts to recover from errors (see the
1253 \f[B]RESET\f[R] section), and in normal execution, flushes
1254 \f[B]stdout\f[R] as soon as execution is done for the current input.
1255 .SH TTY MODE
1256 .PP
1257 If \f[B]stdin\f[R], \f[B]stdout\f[R], and \f[B]stderr\f[R] are all
1258 connected to a TTY, dc(1) turns on \[dq]TTY mode.\[dq]
1259 .PP
1260 TTY mode is required for history to be enabled (see the \f[B]COMMAND
1261 LINE HISTORY\f[R] section).
1262 It is also required to enable special handling for \f[B]SIGINT\f[R]
1263 signals.
1264 .PP
1265 TTY mode is different from interactive mode because interactive mode is
1266 required in the bc(1)
1267 specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
1268 and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
1269 to be connected to a terminal.
1270 .SH SIGNAL HANDLING
1271 .PP
1272 Sending a \f[B]SIGINT\f[R] will cause dc(1) to stop execution of the
1273 current input.
1274 If dc(1) is in TTY mode (see the \f[B]TTY MODE\f[R] section), it will
1275 reset (see the \f[B]RESET\f[R] section).
1276 Otherwise, it will clean up and exit.
1277 .PP
1278 Note that \[dq]current input\[dq] can mean one of two things.
1279 If dc(1) is processing input from \f[B]stdin\f[R] in TTY mode, it will
1280 ask for more input.
1281 If dc(1) is processing input from a file in TTY mode, it will stop
1282 processing the file and start processing the next file, if one exists,
1283 or ask for input from \f[B]stdin\f[R] if no other file exists.
1284 .PP
1285 This means that if a \f[B]SIGINT\f[R] is sent to dc(1) as it is
1286 executing a file, it can seem as though dc(1) did not respond to the
1287 signal since it will immediately start executing the next file.
1288 This is by design; most files that users execute when interacting with
1289 dc(1) have function definitions, which are quick to parse.
1290 If a file takes a long time to execute, there may be a bug in that file.
1291 The rest of the files could still be executed without problem, allowing
1292 the user to continue.
1293 .PP
1294 \f[B]SIGTERM\f[R] and \f[B]SIGQUIT\f[R] cause dc(1) to clean up and
1295 exit, and it uses the default handler for all other signals.
1296 The one exception is \f[B]SIGHUP\f[R]; in that case, when dc(1) is in
1297 TTY mode, a \f[B]SIGHUP\f[R] will cause dc(1) to clean up and exit.
1298 .SH COMMAND LINE HISTORY
1299 .PP
1300 dc(1) supports interactive command-line editing.
1301 If dc(1) is in TTY mode (see the \f[B]TTY MODE\f[R] section), history is
1302 enabled.
1303 Previous lines can be recalled and edited with the arrow keys.
1304 .PP
1305 \f[B]Note\f[R]: tabs are converted to 8 spaces.
1306 .SH LOCALES
1307 .PP
1308 This dc(1) ships with support for adding error messages for different
1309 locales and thus, supports \f[B]LC_MESSAGS\f[R].
1310 .SH SEE ALSO
1311 .PP
1312 bc(1)
1313 .SH STANDARDS
1314 .PP
1315 The dc(1) utility operators are compliant with the operators in the
1316 bc(1) IEEE Std 1003.1-2017
1317 (\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
1318 specification.
1319 .SH BUGS
1320 .PP
1321 None are known.
1322 Report bugs at https://git.yzena.com/gavin/bc.
1323 .SH AUTHOR
1324 .PP
1325 Gavin D.
1326 Howard <gavin@yzena.com> and contributors.