]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bc/manuals/dc/NP.1
mlx4en(4): Fix wrong mbuf cluster size in mlx4_en_debugnet_init()
[FreeBSD/FreeBSD.git] / contrib / bc / manuals / dc / NP.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]0\f[R].
225 If \f[B]obase\f[R] is \f[B]0\f[R], values are output in scientific
226 notation, and if \f[B]obase\f[R] is \f[B]1\f[R], values are output in
227 engineering notation.
228 Otherwise, values are output in the specified base.
229 .PP
230 Outputting in scientific and engineering notations are \f[B]non-portable
231 extensions\f[R].
232 .PP
233 The \f[I]scale\f[R] of an expression is the number of digits in the
234 result of the expression right of the decimal point, and \f[B]scale\f[R]
235 is a register (see the \f[B]REGISTERS\f[R] section) that sets the
236 precision of any operations (with exceptions).
237 \f[B]scale\f[R] is initially \f[B]0\f[R].
238 \f[B]scale\f[R] cannot be negative.
239 The max allowable value for \f[B]scale\f[R] can be queried in dc(1)
240 programs with the \f[B]V\f[R] command.
241 .PP
242 \f[B]seed\f[R] is a register containing the current seed for the
243 pseudo-random number generator.
244 If the current value of \f[B]seed\f[R] is queried and stored, then if it
245 is assigned to \f[B]seed\f[R] later, the pseudo-random number generator
246 is guaranteed to produce the same sequence of pseudo-random numbers that
247 were generated after the value of \f[B]seed\f[R] was first queried.
248 .PP
249 Multiple values assigned to \f[B]seed\f[R] can produce the same sequence
250 of pseudo-random numbers.
251 Likewise, when a value is assigned to \f[B]seed\f[R], it is not
252 guaranteed that querying \f[B]seed\f[R] immediately after will return
253 the same value.
254 In addition, the value of \f[B]seed\f[R] will change after any call to
255 the \f[B]\[aq]\f[R] command or the \f[B]\[dq]\f[R] command that does not
256 get receive a value of \f[B]0\f[R] or \f[B]1\f[R].
257 The maximum integer returned by the \f[B]\[aq]\f[R] command can be
258 queried with the \f[B]W\f[R] command.
259 .PP
260 \f[B]Note\f[R]: The values returned by the pseudo-random number
261 generator with the \f[B]\[aq]\f[R] and \f[B]\[dq]\f[R] commands are
262 guaranteed to \f[B]NOT\f[R] be cryptographically secure.
263 This is a consequence of using a seeded pseudo-random number generator.
264 However, they \f[I]are\f[R] guaranteed to be reproducible with identical
265 \f[B]seed\f[R] values.
266 This means that the pseudo-random values from dc(1) should only be used
267 where a reproducible stream of pseudo-random numbers is
268 \f[I]ESSENTIAL\f[R].
269 In any other case, use a non-seeded pseudo-random number generator.
270 .PP
271 The pseudo-random number generator, \f[B]seed\f[R], and all associated
272 operations are \f[B]non-portable extensions\f[R].
273 .SS Comments
274 .PP
275 Comments go from \f[B]#\f[R] until, and not including, the next newline.
276 This is a \f[B]non-portable extension\f[R].
277 .SH NUMBERS
278 .PP
279 Numbers are strings made up of digits, uppercase letters up to
280 \f[B]F\f[R], and at most \f[B]1\f[R] period for a radix.
281 Numbers can have up to \f[B]DC_NUM_MAX\f[R] digits.
282 Uppercase letters are equal to \f[B]9\f[R] + their position in the
283 alphabet (i.e., \f[B]A\f[R] equals \f[B]10\f[R], or \f[B]9+1\f[R]).
284 If a digit or letter makes no sense with the current value of
285 \f[B]ibase\f[R], they are set to the value of the highest valid digit in
286 \f[B]ibase\f[R].
287 .PP
288 Single-character numbers (i.e., \f[B]A\f[R] alone) take the value that
289 they would have if they were valid digits, regardless of the value of
290 \f[B]ibase\f[R].
291 This means that \f[B]A\f[R] alone always equals decimal \f[B]10\f[R] and
292 \f[B]F\f[R] alone always equals decimal \f[B]15\f[R].
293 .PP
294 In addition, dc(1) accepts numbers in scientific notation.
295 These have the form \f[B]<number>e<integer>\f[R].
296 The exponent (the portion after the \f[B]e\f[R]) must be an integer.
297 An example is \f[B]1.89237e9\f[R], which is equal to
298 \f[B]1892370000\f[R].
299 Negative exponents are also allowed, so \f[B]4.2890e_3\f[R] is equal to
300 \f[B]0.0042890\f[R].
301 .PP
302 \f[B]WARNING\f[R]: Both the number and the exponent in scientific
303 notation are interpreted according to the current \f[B]ibase\f[R], but
304 the number is still multiplied by \f[B]10\[ha]exponent\f[R] regardless
305 of the current \f[B]ibase\f[R].
306 For example, if \f[B]ibase\f[R] is \f[B]16\f[R] and dc(1) is given the
307 number string \f[B]FFeA\f[R], the resulting decimal number will be
308 \f[B]2550000000000\f[R], and if dc(1) is given the number string
309 \f[B]10e_4\f[R], the resulting decimal number will be \f[B]0.0016\f[R].
310 .PP
311 Accepting input as scientific notation is a \f[B]non-portable
312 extension\f[R].
313 .SH COMMANDS
314 .PP
315 The valid commands are listed below.
316 .SS Printing
317 .PP
318 These commands are used for printing.
319 .PP
320 Note that both scientific notation and engineering notation are
321 available for printing numbers.
322 Scientific notation is activated by assigning \f[B]0\f[R] to
323 \f[B]obase\f[R] using \f[B]0o\f[R], and engineering notation is
324 activated by assigning \f[B]1\f[R] to \f[B]obase\f[R] using
325 \f[B]1o\f[R].
326 To deactivate them, just assign a different value to \f[B]obase\f[R].
327 .PP
328 Printing numbers in scientific notation and/or engineering notation is a
329 \f[B]non-portable extension\f[R].
330 .PP
331 \f[B]p\f[R]
332 .PP
333 : Prints the value on top of the stack, whether number or string, and
334 prints a newline after.
335 .IP
336 .nf
337 \f[C]
338 This does not alter the stack.
339 \f[R]
340 .fi
341 .PP
342 \f[B]n\f[R]
343 .PP
344 : Prints the value on top of the stack, whether number or string, and
345 pops it off of the stack.
346 .PP
347 \f[B]P\f[R]
348 .PP
349 : Pops a value off the stack.
350 .IP
351 .nf
352 \f[C]
353 If the value is a number, it is truncated and the absolute value of the
354 result is printed as though **obase** is **UCHAR_MAX+1** and each digit is
355 interpreted as an ASCII character, making it a byte stream.
356
357 If the value is a string, it is printed without a trailing newline.
358
359 This is a **non-portable extension**.
360 \f[R]
361 .fi
362 .PP
363 \f[B]f\f[R]
364 .PP
365 : Prints the entire contents of the stack, in order from newest to
366 oldest, without altering anything.
367 .IP
368 .nf
369 \f[C]
370 Users should use this command when they get lost.
371 \f[R]
372 .fi
373 .SS Arithmetic
374 .PP
375 These are the commands used for arithmetic.
376 .PP
377 \f[B]+\f[R]
378 .PP
379 : The top two values are popped off the stack, added, and the result is
380 pushed onto the stack.
381 The \f[I]scale\f[R] of the result is equal to the max \f[I]scale\f[R] of
382 both operands.
383 .PP
384 \f[B]-\f[R]
385 .PP
386 : The top two values are popped off the stack, subtracted, and the
387 result is pushed onto the stack.
388 The \f[I]scale\f[R] of the result is equal to the max \f[I]scale\f[R] of
389 both operands.
390 .PP
391 \f[B]*\f[R]
392 .PP
393 : The top two values are popped off the stack, multiplied, and the
394 result is pushed onto the stack.
395 If \f[B]a\f[R] is the \f[I]scale\f[R] of the first expression and
396 \f[B]b\f[R] is the \f[I]scale\f[R] of the second expression, the
397 \f[I]scale\f[R] of the result is equal to
398 \f[B]min(a+b,max(scale,a,b))\f[R] where \f[B]min()\f[R] and
399 \f[B]max()\f[R] return the obvious values.
400 .PP
401 \f[B]/\f[R]
402 .PP
403 : The top two values are popped off the stack, divided, and the result
404 is pushed onto the stack.
405 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
406 .IP
407 .nf
408 \f[C]
409 The first value popped off of the stack must be non-zero.
410 \f[R]
411 .fi
412 .PP
413 \f[B]%\f[R]
414 .PP
415 : The top two values are popped off the stack, remaindered, and the
416 result is pushed onto the stack.
417 .IP
418 .nf
419 \f[C]
420 Remaindering is equivalent to 1) Computing **a/b** to current **scale**, and
421 2) Using the result of step 1 to calculate **a-(a/b)\[rs]*b** to *scale*
422 **max(scale+scale(b),scale(a))**.
423
424 The first value popped off of the stack must be non-zero.
425 \f[R]
426 .fi
427 .PP
428 \f[B]\[ti]\f[R]
429 .PP
430 : The top two values are popped off the stack, divided and remaindered,
431 and the results (divided first, remainder second) are pushed onto the
432 stack.
433 This is equivalent to \f[B]x y / x y %\f[R] except that \f[B]x\f[R] and
434 \f[B]y\f[R] are only evaluated once.
435 .IP
436 .nf
437 \f[C]
438 The first value popped off of the stack must be non-zero.
439
440 This is a **non-portable extension**.
441 \f[R]
442 .fi
443 .PP
444 \f[B]\[ha]\f[R]
445 .PP
446 : The top two values are popped off the stack, the second is raised to
447 the power of the first, and the result is pushed onto the stack.
448 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
449 .IP
450 .nf
451 \f[C]
452 The first value popped off of the stack must be an integer, and if that
453 value is negative, the second value popped off of the stack must be
454 non-zero.
455 \f[R]
456 .fi
457 .PP
458 \f[B]v\f[R]
459 .PP
460 : The top value is popped off the stack, its square root is computed,
461 and the result is pushed onto the stack.
462 The \f[I]scale\f[R] of the result is equal to \f[B]scale\f[R].
463 .IP
464 .nf
465 \f[C]
466 The value popped off of the stack must be non-negative.
467 \f[R]
468 .fi
469 .PP
470 \f[B]_\f[R]
471 .PP
472 : If this command \f[I]immediately\f[R] precedes a number (i.e., no
473 spaces or other commands), then that number is input as a negative
474 number.
475 .IP
476 .nf
477 \f[C]
478 Otherwise, the top value on the stack is popped and copied, and the copy is
479 negated and pushed onto the stack. This behavior without a number is a
480 **non-portable extension**.
481 \f[R]
482 .fi
483 .PP
484 \f[B]b\f[R]
485 .PP
486 : The top value is popped off the stack, and if it is zero, it is pushed
487 back onto the stack.
488 Otherwise, its absolute value is pushed onto the stack.
489 .IP
490 .nf
491 \f[C]
492 This is a **non-portable extension**.
493 \f[R]
494 .fi
495 .PP
496 \f[B]|\f[R]
497 .PP
498 : The top three values are popped off the stack, a modular
499 exponentiation is computed, and the result is pushed onto the stack.
500 .IP
501 .nf
502 \f[C]
503 The first value popped is used as the reduction modulus and must be an
504 integer and non-zero. The second value popped is used as the exponent and
505 must be an integer and non-negative. The third value popped is the base and
506 must be an integer.
507
508 This is a **non-portable extension**.
509 \f[R]
510 .fi
511 .PP
512 \f[B]$\f[R]
513 .PP
514 : The top value is popped off the stack and copied, and the copy is
515 truncated and pushed onto the stack.
516 .IP
517 .nf
518 \f[C]
519 This is a **non-portable extension**.
520 \f[R]
521 .fi
522 .PP
523 \f[B]\[at]\f[R]
524 .PP
525 : The top two values are popped off the stack, and the precision of the
526 second is set to the value of the first, whether by truncation or
527 extension.
528 .IP
529 .nf
530 \f[C]
531 The first value popped off of the stack must be an integer and non-negative.
532
533 This is a **non-portable extension**.
534 \f[R]
535 .fi
536 .PP
537 \f[B]H\f[R]
538 .PP
539 : The top two values are popped off the stack, and the second is shifted
540 left (radix shifted right) to the value of the first.
541 .IP
542 .nf
543 \f[C]
544 The first value popped off of the stack must be an integer and non-negative.
545
546 This is a **non-portable extension**.
547 \f[R]
548 .fi
549 .PP
550 \f[B]h\f[R]
551 .PP
552 : The top two values are popped off the stack, and the second is shifted
553 right (radix shifted left) to the value of the first.
554 .IP
555 .nf
556 \f[C]
557 The first value popped off of the stack must be an integer and non-negative.
558
559 This is a **non-portable extension**.
560 \f[R]
561 .fi
562 .PP
563 \f[B]G\f[R]
564 .PP
565 : The top two values are popped off of the stack, they are compared, and
566 a \f[B]1\f[R] is pushed if they are equal, or \f[B]0\f[R] otherwise.
567 .IP
568 .nf
569 \f[C]
570 This is a **non-portable extension**.
571 \f[R]
572 .fi
573 .PP
574 \f[B]N\f[R]
575 .PP
576 : The top value is popped off of the stack, and if it a \f[B]0\f[R], a
577 \f[B]1\f[R] is pushed; otherwise, a \f[B]0\f[R] is pushed.
578 .IP
579 .nf
580 \f[C]
581 This is a **non-portable extension**.
582 \f[R]
583 .fi
584 .PP
585 \f[B](\f[R]
586 .PP
587 : The top two values are popped off of the stack, they are compared, and
588 a \f[B]1\f[R] is pushed if the first is less than the second, or
589 \f[B]0\f[R] otherwise.
590 .IP
591 .nf
592 \f[C]
593 This is a **non-portable extension**.
594 \f[R]
595 .fi
596 .PP
597 \f[B]{\f[R]
598 .PP
599 : The top two values are popped off of the stack, they are compared, and
600 a \f[B]1\f[R] is pushed if the first is less than or equal to the
601 second, or \f[B]0\f[R] otherwise.
602 .IP
603 .nf
604 \f[C]
605 This is a **non-portable extension**.
606 \f[R]
607 .fi
608 .PP
609 \f[B])\f[R]
610 .PP
611 : The top two values are popped off of the stack, they are compared, and
612 a \f[B]1\f[R] is pushed if the first is greater than the second, or
613 \f[B]0\f[R] otherwise.
614 .IP
615 .nf
616 \f[C]
617 This is a **non-portable extension**.
618 \f[R]
619 .fi
620 .PP
621 \f[B]}\f[R]
622 .PP
623 : The top two values are popped off of the stack, they are compared, and
624 a \f[B]1\f[R] is pushed if the first is greater than or equal to the
625 second, or \f[B]0\f[R] otherwise.
626 .IP
627 .nf
628 \f[C]
629 This is a **non-portable extension**.
630 \f[R]
631 .fi
632 .PP
633 \f[B]M\f[R]
634 .PP
635 : The top two values are popped off of the stack.
636 If they are both non-zero, a \f[B]1\f[R] is pushed onto the stack.
637 If either of them is zero, or both of them are, then a \f[B]0\f[R] is
638 pushed onto the stack.
639 .IP
640 .nf
641 \f[C]
642 This is like the **&&** operator in bc(1), and it is *not* a short-circuit
643 operator.
644
645 This is a **non-portable extension**.
646 \f[R]
647 .fi
648 .PP
649 \f[B]m\f[R]
650 .PP
651 : The top two values are popped off of the stack.
652 If at least one of them is non-zero, a \f[B]1\f[R] is pushed onto the
653 stack.
654 If both of them are zero, then a \f[B]0\f[R] is pushed onto the stack.
655 .IP
656 .nf
657 \f[C]
658 This is like the **||** operator in bc(1), and it is *not* a short-circuit
659 operator.
660
661 This is a **non-portable extension**.
662 \f[R]
663 .fi
664 .SS Pseudo-Random Number Generator
665 .PP
666 dc(1) has a built-in pseudo-random number generator.
667 These commands query the pseudo-random number generator.
668 (See Parameters for more information about the \f[B]seed\f[R] value that
669 controls the pseudo-random number generator.)
670 .PP
671 The pseudo-random number generator is guaranteed to \f[B]NOT\f[R] be
672 cryptographically secure.
673 .PP
674 \f[B]\[aq]\f[R]
675 .PP
676 : Generates an integer between 0 and \f[B]DC_RAND_MAX\f[R], inclusive
677 (see the \f[B]LIMITS\f[R] section).
678 .IP
679 .nf
680 \f[C]
681 The generated integer is made as unbiased as possible, subject to the
682 limitations of the pseudo-random number generator.
683
684 This is a **non-portable extension**.
685 \f[R]
686 .fi
687 .PP
688 \f[B]\[dq]\f[R]
689 .PP
690 : Pops a value off of the stack, which is used as an \f[B]exclusive\f[R]
691 upper bound on the integer that will be generated.
692 If the bound is negative or is a non-integer, an error is raised, and
693 dc(1) resets (see the \f[B]RESET\f[R] section) while \f[B]seed\f[R]
694 remains unchanged.
695 If the bound is larger than \f[B]DC_RAND_MAX\f[R], the higher bound is
696 honored by generating several pseudo-random integers, multiplying them
697 by appropriate powers of \f[B]DC_RAND_MAX+1\f[R], and adding them
698 together.
699 Thus, the size of integer that can be generated with this command is
700 unbounded.
701 Using this command will change the value of \f[B]seed\f[R], unless the
702 operand is \f[B]0\f[R] or \f[B]1\f[R].
703 In that case, \f[B]0\f[R] is pushed onto the stack, and \f[B]seed\f[R]
704 is \f[I]not\f[R] changed.
705 .IP
706 .nf
707 \f[C]
708 The generated integer is made as unbiased as possible, subject to the
709 limitations of the pseudo-random number generator.
710
711 This is a **non-portable extension**.
712 \f[R]
713 .fi
714 .SS Stack Control
715 .PP
716 These commands control the stack.
717 .PP
718 \f[B]c\f[R]
719 .PP
720 : Removes all items from (\[dq]clears\[dq]) the stack.
721 .PP
722 \f[B]d\f[R]
723 .PP
724 : Copies the item on top of the stack (\[dq]duplicates\[dq]) and pushes
725 the copy onto the stack.
726 .PP
727 \f[B]r\f[R]
728 .PP
729 : Swaps (\[dq]reverses\[dq]) the two top items on the stack.
730 .PP
731 \f[B]R\f[R]
732 .PP
733 : Pops (\[dq]removes\[dq]) the top value from the stack.
734 .SS Register Control
735 .PP
736 These commands control registers (see the \f[B]REGISTERS\f[R] section).
737 .PP
738 \f[B]s\f[R]\f[I]r\f[R]
739 .PP
740 : Pops the value off the top of the stack and stores it into register
741 \f[I]r\f[R].
742 .PP
743 \f[B]l\f[R]\f[I]r\f[R]
744 .PP
745 : Copies the value in register \f[I]r\f[R] and pushes it onto the stack.
746 This does not alter the contents of \f[I]r\f[R].
747 .PP
748 \f[B]S\f[R]\f[I]r\f[R]
749 .PP
750 : Pops the value off the top of the (main) stack and pushes it onto the
751 stack of register \f[I]r\f[R].
752 The previous value of the register becomes inaccessible.
753 .PP
754 \f[B]L\f[R]\f[I]r\f[R]
755 .PP
756 : Pops the value off the top of the stack for register \f[I]r\f[R] and
757 push it onto the main stack.
758 The previous value in the stack for register \f[I]r\f[R], if any, is now
759 accessible via the \f[B]l\f[R]\f[I]r\f[R] command.
760 .SS Parameters
761 .PP
762 These commands control the values of \f[B]ibase\f[R], \f[B]obase\f[R],
763 \f[B]scale\f[R], and \f[B]seed\f[R].
764 Also see the \f[B]SYNTAX\f[R] section.
765 .PP
766 \f[B]i\f[R]
767 .PP
768 : Pops the value off of the top of the stack and uses it to set
769 \f[B]ibase\f[R], which must be between \f[B]2\f[R] and \f[B]16\f[R],
770 inclusive.
771 .IP
772 .nf
773 \f[C]
774 If the value on top of the stack has any *scale*, the *scale* is ignored.
775 \f[R]
776 .fi
777 .PP
778 \f[B]o\f[R]
779 .PP
780 : Pops the value off of the top of the stack and uses it to set
781 \f[B]obase\f[R], which must be between \f[B]0\f[R] and
782 \f[B]DC_BASE_MAX\f[R], inclusive (see the \f[B]LIMITS\f[R] section and
783 the \f[B]NUMBERS\f[R] section).
784 .IP
785 .nf
786 \f[C]
787 If the value on top of the stack has any *scale*, the *scale* is ignored.
788 \f[R]
789 .fi
790 .PP
791 \f[B]k\f[R]
792 .PP
793 : Pops the value off of the top of the stack and uses it to set
794 \f[B]scale\f[R], which must be non-negative.
795 .IP
796 .nf
797 \f[C]
798 If the value on top of the stack has any *scale*, the *scale* is ignored.
799 \f[R]
800 .fi
801 .PP
802 \f[B]j\f[R]
803 .PP
804 : Pops the value off of the top of the stack and uses it to set
805 \f[B]seed\f[R].
806 The meaning of \f[B]seed\f[R] is dependent on the current pseudo-random
807 number generator but is guaranteed to not change except for new major
808 versions.
809 .IP
810 .nf
811 \f[C]
812 The *scale* and sign of the value may be significant.
813
814 If a previously used **seed** value is used again, the pseudo-random number
815 generator is guaranteed to produce the same sequence of pseudo-random
816 numbers as it did when the **seed** value was previously used.
817
818 The exact value assigned to **seed** is not guaranteed to be returned if the
819 **J** command is used. However, if **seed** *does* return a different value,
820 both values, when assigned to **seed**, are guaranteed to produce the same
821 sequence of pseudo-random numbers. This means that certain values assigned
822 to **seed** will not produce unique sequences of pseudo-random numbers.
823
824 There is no limit to the length (number of significant decimal digits) or
825 *scale* of the value that can be assigned to **seed**.
826
827 This is a **non-portable extension**.
828 \f[R]
829 .fi
830 .PP
831 \f[B]I\f[R]
832 .PP
833 : Pushes the current value of \f[B]ibase\f[R] onto the main stack.
834 .PP
835 \f[B]O\f[R]
836 .PP
837 : Pushes the current value of \f[B]obase\f[R] onto the main stack.
838 .PP
839 \f[B]K\f[R]
840 .PP
841 : Pushes the current value of \f[B]scale\f[R] onto the main stack.
842 .PP
843 \f[B]J\f[R]
844 .PP
845 : Pushes the current value of \f[B]seed\f[R] onto the main stack.
846 .IP
847 .nf
848 \f[C]
849 This is a **non-portable extension**.
850 \f[R]
851 .fi
852 .PP
853 \f[B]T\f[R]
854 .PP
855 : Pushes the maximum allowable value of \f[B]ibase\f[R] onto the main
856 stack.
857 .IP
858 .nf
859 \f[C]
860 This is a **non-portable extension**.
861 \f[R]
862 .fi
863 .PP
864 \f[B]U\f[R]
865 .PP
866 : Pushes the maximum allowable value of \f[B]obase\f[R] onto the main
867 stack.
868 .IP
869 .nf
870 \f[C]
871 This is a **non-portable extension**.
872 \f[R]
873 .fi
874 .PP
875 \f[B]V\f[R]
876 .PP
877 : Pushes the maximum allowable value of \f[B]scale\f[R] onto the main
878 stack.
879 .IP
880 .nf
881 \f[C]
882 This is a **non-portable extension**.
883 \f[R]
884 .fi
885 .PP
886 \f[B]W\f[R]
887 .PP
888 : Pushes the maximum (inclusive) integer that can be generated with the
889 \f[B]\[aq]\f[R] pseudo-random number generator command.
890 .IP
891 .nf
892 \f[C]
893 This is a **non-portable extension**.
894 \f[R]
895 .fi
896 .SS Strings
897 .PP
898 The following commands control strings.
899 .PP
900 dc(1) can work with both numbers and strings, and registers (see the
901 \f[B]REGISTERS\f[R] section) can hold both strings and numbers.
902 dc(1) always knows whether the contents of a register are a string or a
903 number.
904 .PP
905 While arithmetic operations have to have numbers, and will print an
906 error if given a string, other commands accept strings.
907 .PP
908 Strings can also be executed as macros.
909 For example, if the string \f[B][1pR]\f[R] is executed as a macro, then
910 the code \f[B]1pR\f[R] is executed, meaning that the \f[B]1\f[R] will be
911 printed with a newline after and then popped from the stack.
912 .PP
913 \f[B][\f[R]\f[I]characters\f[R]\f[B]]\f[R]
914 .PP
915 : Makes a string containing \f[I]characters\f[R] and pushes it onto the
916 stack.
917 .IP
918 .nf
919 \f[C]
920 If there are brackets (**\[rs][** and **\[rs]]**) in the string, then they must be
921 balanced. Unbalanced brackets can be escaped using a backslash (**\[rs]\[rs]**)
922 character.
923
924 If there is a backslash character in the string, the character after it
925 (even another backslash) is put into the string verbatim, but the (first)
926 backslash is not.
927 \f[R]
928 .fi
929 .PP
930 \f[B]a\f[R]
931 .PP
932 : The value on top of the stack is popped.
933 .IP
934 .nf
935 \f[C]
936 If it is a number, it is truncated and its absolute value is taken. The
937 result mod **UCHAR_MAX+1** is calculated. If that result is **0**, push an
938 empty string; otherwise, push a one-character string where the character is
939 the result of the mod interpreted as an ASCII character.
940
941 If it is a string, then a new string is made. If the original string is
942 empty, the new string is empty. If it is not, then the first character of
943 the original string is used to create the new string as a one-character
944 string. The new string is then pushed onto the stack.
945
946 This is a **non-portable extension**.
947 \f[R]
948 .fi
949 .PP
950 \f[B]x\f[R]
951 .PP
952 : Pops a value off of the top of the stack.
953 .IP
954 .nf
955 \f[C]
956 If it is a number, it is pushed back onto the stack.
957
958 If it is a string, it is executed as a macro.
959
960 This behavior is the norm whenever a macro is executed, whether by this
961 command or by the conditional execution commands below.
962 \f[R]
963 .fi
964 .PP
965 \f[B]>\f[R]\f[I]r\f[R]
966 .PP
967 : Pops two values off of the stack that must be numbers and compares
968 them.
969 If the first value is greater than the second, then the contents of
970 register \f[I]r\f[R] are executed.
971 .IP
972 .nf
973 \f[C]
974 For example, **0 1>a** will execute the contents of register **a**, and
975 **1 0>a** will not.
976
977 If either or both of the values are not numbers, dc(1) will raise an error
978 and reset (see the **RESET** section).
979 \f[R]
980 .fi
981 .PP
982 \f[B]>\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
983 .PP
984 : Like the above, but will execute register \f[I]s\f[R] if the
985 comparison fails.
986 .IP
987 .nf
988 \f[C]
989 If either or both of the values are not numbers, dc(1) will raise an error
990 and reset (see the **RESET** section).
991
992 This is a **non-portable extension**.
993 \f[R]
994 .fi
995 .PP
996 \f[B]!>\f[R]\f[I]r\f[R]
997 .PP
998 : Pops two values off of the stack that must be numbers and compares
999 them.
1000 If the first value is not greater than the second (less than or equal
1001 to), then the contents of register \f[I]r\f[R] are executed.
1002 .IP
1003 .nf
1004 \f[C]
1005 If either or both of the values are not numbers, dc(1) will raise an error
1006 and reset (see the **RESET** section).
1007 \f[R]
1008 .fi
1009 .PP
1010 \f[B]!>\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
1011 .PP
1012 : Like the above, but will execute register \f[I]s\f[R] if the
1013 comparison fails.
1014 .IP
1015 .nf
1016 \f[C]
1017 If either or both of the values are not numbers, dc(1) will raise an error
1018 and reset (see the **RESET** section).
1019
1020 This is a **non-portable extension**.
1021 \f[R]
1022 .fi
1023 .PP
1024 \f[B]<\f[R]\f[I]r\f[R]
1025 .PP
1026 : Pops two values off of the stack that must be numbers and compares
1027 them.
1028 If the first value is less than the second, then the contents of
1029 register \f[I]r\f[R] are executed.
1030 .IP
1031 .nf
1032 \f[C]
1033 If either or both of the values are not numbers, dc(1) will raise an error
1034 and reset (see the **RESET** section).
1035 \f[R]
1036 .fi
1037 .PP
1038 \f[B]<\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
1039 .PP
1040 : Like the above, but will execute register \f[I]s\f[R] if the
1041 comparison fails.
1042 .IP
1043 .nf
1044 \f[C]
1045 If either or both of the values are not numbers, dc(1) will raise an error
1046 and reset (see the **RESET** section).
1047
1048 This is a **non-portable extension**.
1049 \f[R]
1050 .fi
1051 .PP
1052 \f[B]!<\f[R]\f[I]r\f[R]
1053 .PP
1054 : Pops two values off of the stack that must be numbers and compares
1055 them.
1056 If the first value is not less than the second (greater than or equal
1057 to), then the contents of register \f[I]r\f[R] are executed.
1058 .IP
1059 .nf
1060 \f[C]
1061 If either or both of the values are not numbers, dc(1) will raise an error
1062 and reset (see the **RESET** section).
1063 \f[R]
1064 .fi
1065 .PP
1066 \f[B]!<\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
1067 .PP
1068 : Like the above, but will execute register \f[I]s\f[R] if the
1069 comparison fails.
1070 .IP
1071 .nf
1072 \f[C]
1073 If either or both of the values are not numbers, dc(1) will raise an error
1074 and reset (see the **RESET** section).
1075
1076 This is a **non-portable extension**.
1077 \f[R]
1078 .fi
1079 .PP
1080 \f[B]=\f[R]\f[I]r\f[R]
1081 .PP
1082 : Pops two values off of the stack that must be numbers and compares
1083 them.
1084 If the first value is equal to the second, then the contents of register
1085 \f[I]r\f[R] are executed.
1086 .IP
1087 .nf
1088 \f[C]
1089 If either or both of the values are not numbers, dc(1) will raise an error
1090 and reset (see the **RESET** section).
1091 \f[R]
1092 .fi
1093 .PP
1094 \f[B]=\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
1095 .PP
1096 : Like the above, but will execute register \f[I]s\f[R] if the
1097 comparison fails.
1098 .IP
1099 .nf
1100 \f[C]
1101 If either or both of the values are not numbers, dc(1) will raise an error
1102 and reset (see the **RESET** section).
1103
1104 This is a **non-portable extension**.
1105 \f[R]
1106 .fi
1107 .PP
1108 \f[B]!=\f[R]\f[I]r\f[R]
1109 .PP
1110 : Pops two values off of the stack that must be numbers and compares
1111 them.
1112 If the first value is not equal to the second, then the contents of
1113 register \f[I]r\f[R] are executed.
1114 .IP
1115 .nf
1116 \f[C]
1117 If either or both of the values are not numbers, dc(1) will raise an error
1118 and reset (see the **RESET** section).
1119 \f[R]
1120 .fi
1121 .PP
1122 \f[B]!=\f[R]\f[I]r\f[R]\f[B]e\f[R]\f[I]s\f[R]
1123 .PP
1124 : Like the above, but will execute register \f[I]s\f[R] if the
1125 comparison fails.
1126 .IP
1127 .nf
1128 \f[C]
1129 If either or both of the values are not numbers, dc(1) will raise an error
1130 and reset (see the **RESET** section).
1131
1132 This is a **non-portable extension**.
1133 \f[R]
1134 .fi
1135 .PP
1136 \f[B]?\f[R]
1137 .PP
1138 : Reads a line from the \f[B]stdin\f[R] and executes it.
1139 This is to allow macros to request input from users.
1140 .PP
1141 \f[B]q\f[R]
1142 .PP
1143 : During execution of a macro, this exits the execution of that macro
1144 and the execution of the macro that executed it.
1145 If there are no macros, or only one macro executing, dc(1) exits.
1146 .PP
1147 \f[B]Q\f[R]
1148 .PP
1149 : Pops a value from the stack which must be non-negative and is used the
1150 number of macro executions to pop off of the execution stack.
1151 If the number of levels to pop is greater than the number of executing
1152 macros, dc(1) exits.
1153 .SS Status
1154 .PP
1155 These commands query status of the stack or its top value.
1156 .PP
1157 \f[B]Z\f[R]
1158 .PP
1159 : Pops a value off of the stack.
1160 .IP
1161 .nf
1162 \f[C]
1163 If it is a number, calculates the number of significant decimal digits it
1164 has and pushes the result.
1165
1166 If it is a string, pushes the number of characters the string has.
1167 \f[R]
1168 .fi
1169 .PP
1170 \f[B]X\f[R]
1171 .PP
1172 : Pops a value off of the stack.
1173 .IP
1174 .nf
1175 \f[C]
1176 If it is a number, pushes the *scale* of the value onto the stack.
1177
1178 If it is a string, pushes **0**.
1179 \f[R]
1180 .fi
1181 .PP
1182 \f[B]z\f[R]
1183 .PP
1184 : Pushes the current stack depth (before execution of this command).
1185 .SS Arrays
1186 .PP
1187 These commands manipulate arrays.
1188 .PP
1189 \f[B]:\f[R]\f[I]r\f[R]
1190 .PP
1191 : Pops the top two values off of the stack.
1192 The second value will be stored in the array \f[I]r\f[R] (see the
1193 \f[B]REGISTERS\f[R] section), indexed by the first value.
1194 .PP
1195 \f[B];\f[R]\f[I]r\f[R]
1196 .PP
1197 : Pops the value on top of the stack and uses it as an index into the
1198 array \f[I]r\f[R].
1199 The selected value is then pushed onto the stack.
1200 .SH REGISTERS
1201 .PP
1202 Registers are names that can store strings, numbers, and arrays.
1203 (Number/string registers do not interfere with array registers.)
1204 .PP
1205 Each register is also its own stack, so the current register value is
1206 the top of the stack for the register.
1207 All registers, when first referenced, have one value (\f[B]0\f[R]) in
1208 their stack.
1209 .PP
1210 In non-extended register mode, a register name is just the single
1211 character that follows any command that needs a register name.
1212 The only exception is a newline (\f[B]\[aq]\[rs]n\[aq]\f[R]); it is a
1213 parse error for a newline to be used as a register name.
1214 .SS Extended Register Mode
1215 .PP
1216 Unlike most other dc(1) implentations, this dc(1) provides nearly
1217 unlimited amounts of registers, if extended register mode is enabled.
1218 .PP
1219 If extended register mode is enabled (\f[B]-x\f[R] or
1220 \f[B]--extended-register\f[R] command-line arguments are given), then
1221 normal single character registers are used \f[I]unless\f[R] the
1222 character immediately following a command that needs a register name is
1223 a space (according to \f[B]isspace()\f[R]) and not a newline
1224 (\f[B]\[aq]\[rs]n\[aq]\f[R]).
1225 .PP
1226 In that case, the register name is found according to the regex
1227 \f[B][a-z][a-z0-9_]*\f[R] (like bc(1) identifiers), and it is a parse
1228 error if the next non-space characters do not match that regex.
1229 .SH RESET
1230 .PP
1231 When dc(1) encounters an error or a signal that it has a non-default
1232 handler for, it resets.
1233 This means that several things happen.
1234 .PP
1235 First, any macros that are executing are stopped and popped off the
1236 stack.
1237 The behavior is not unlike that of exceptions in programming languages.
1238 Then the execution point is set so that any code waiting to execute
1239 (after all macros returned) is skipped.
1240 .PP
1241 Thus, when dc(1) resets, it skips any remaining code waiting to be
1242 executed.
1243 Then, if it is interactive mode, and the error was not a fatal error
1244 (see the \f[B]EXIT STATUS\f[R] section), it asks for more input;
1245 otherwise, it exits with the appropriate return code.
1246 .SH PERFORMANCE
1247 .PP
1248 Most dc(1) implementations use \f[B]char\f[R] types to calculate the
1249 value of \f[B]1\f[R] decimal digit at a time, but that can be slow.
1250 This dc(1) does something different.
1251 .PP
1252 It uses large integers to calculate more than \f[B]1\f[R] decimal digit
1253 at a time.
1254 If built in a environment where \f[B]DC_LONG_BIT\f[R] (see the
1255 \f[B]LIMITS\f[R] section) is \f[B]64\f[R], then each integer has
1256 \f[B]9\f[R] decimal digits.
1257 If built in an environment where \f[B]DC_LONG_BIT\f[R] is \f[B]32\f[R]
1258 then each integer has \f[B]4\f[R] decimal digits.
1259 This value (the number of decimal digits per large integer) is called
1260 \f[B]DC_BASE_DIGS\f[R].
1261 .PP
1262 In addition, this dc(1) uses an even larger integer for overflow
1263 checking.
1264 This integer type depends on the value of \f[B]DC_LONG_BIT\f[R], but is
1265 always at least twice as large as the integer type used to store digits.
1266 .SH LIMITS
1267 .PP
1268 The following are the limits on dc(1):
1269 .PP
1270 \f[B]DC_LONG_BIT\f[R]
1271 .PP
1272 : The number of bits in the \f[B]long\f[R] type in the environment where
1273 dc(1) was built.
1274 This determines how many decimal digits can be stored in a single large
1275 integer (see the \f[B]PERFORMANCE\f[R] section).
1276 .PP
1277 \f[B]DC_BASE_DIGS\f[R]
1278 .PP
1279 : The number of decimal digits per large integer (see the
1280 \f[B]PERFORMANCE\f[R] section).
1281 Depends on \f[B]DC_LONG_BIT\f[R].
1282 .PP
1283 \f[B]DC_BASE_POW\f[R]
1284 .PP
1285 : The max decimal number that each large integer can store (see
1286 \f[B]DC_BASE_DIGS\f[R]) plus \f[B]1\f[R].
1287 Depends on \f[B]DC_BASE_DIGS\f[R].
1288 .PP
1289 \f[B]DC_OVERFLOW_MAX\f[R]
1290 .PP
1291 : The max number that the overflow type (see the \f[B]PERFORMANCE\f[R]
1292 section) can hold.
1293 Depends on \f[B]DC_LONG_BIT\f[R].
1294 .PP
1295 \f[B]DC_BASE_MAX\f[R]
1296 .PP
1297 : The maximum output base.
1298 Set at \f[B]DC_BASE_POW\f[R].
1299 .PP
1300 \f[B]DC_DIM_MAX\f[R]
1301 .PP
1302 : The maximum size of arrays.
1303 Set at \f[B]SIZE_MAX-1\f[R].
1304 .PP
1305 \f[B]DC_SCALE_MAX\f[R]
1306 .PP
1307 : The maximum \f[B]scale\f[R].
1308 Set at \f[B]DC_OVERFLOW_MAX-1\f[R].
1309 .PP
1310 \f[B]DC_STRING_MAX\f[R]
1311 .PP
1312 : The maximum length of strings.
1313 Set at \f[B]DC_OVERFLOW_MAX-1\f[R].
1314 .PP
1315 \f[B]DC_NAME_MAX\f[R]
1316 .PP
1317 : The maximum length of identifiers.
1318 Set at \f[B]DC_OVERFLOW_MAX-1\f[R].
1319 .PP
1320 \f[B]DC_NUM_MAX\f[R]
1321 .PP
1322 : The maximum length of a number (in decimal digits), which includes
1323 digits after the decimal point.
1324 Set at \f[B]DC_OVERFLOW_MAX-1\f[R].
1325 .PP
1326 \f[B]DC_RAND_MAX\f[R]
1327 .PP
1328 : The maximum integer (inclusive) returned by the \f[B]\[aq]\f[R]
1329 command, if dc(1).
1330 Set at \f[B]2\[ha]DC_LONG_BIT-1\f[R].
1331 .PP
1332 Exponent
1333 .PP
1334 : The maximum allowable exponent (positive or negative).
1335 Set at \f[B]DC_OVERFLOW_MAX\f[R].
1336 .PP
1337 Number of vars
1338 .PP
1339 : The maximum number of vars/arrays.
1340 Set at \f[B]SIZE_MAX-1\f[R].
1341 .PP
1342 These limits are meant to be effectively non-existent; the limits are so
1343 large (at least on 64-bit machines) that there should not be any point
1344 at which they become a problem.
1345 In fact, memory should be exhausted before these limits should be hit.
1346 .SH ENVIRONMENT VARIABLES
1347 .PP
1348 dc(1) recognizes the following environment variables:
1349 .PP
1350 \f[B]DC_ENV_ARGS\f[R]
1351 .PP
1352 : This is another way to give command-line arguments to dc(1).
1353 They should be in the same format as all other command-line arguments.
1354 These are always processed first, so any files given in
1355 \f[B]DC_ENV_ARGS\f[R] will be processed before arguments and files given
1356 on the command-line.
1357 This gives the user the ability to set up \[dq]standard\[dq] options and
1358 files to be used at every invocation.
1359 The most useful thing for such files to contain would be useful
1360 functions that the user might want every time dc(1) runs.
1361 Another use would be to use the \f[B]-e\f[R] option to set
1362 \f[B]scale\f[R] to a value other than \f[B]0\f[R].
1363 .IP
1364 .nf
1365 \f[C]
1366 The code that parses **DC_ENV_ARGS** will correctly handle quoted arguments,
1367 but it does not understand escape sequences. For example, the string
1368 **\[dq]/home/gavin/some dc file.dc\[dq]** will be correctly parsed, but the string
1369 **\[dq]/home/gavin/some \[rs]\[dq]dc\[rs]\[dq] file.dc\[dq]** will include the backslashes.
1370
1371 The quote parsing will handle either kind of quotes, **\[aq]** or **\[dq]**. Thus,
1372 if you have a file with any number of single quotes in the name, you can use
1373 double quotes as the outside quotes, as in **\[dq]some \[aq]dc\[aq] file.dc\[dq]**, and vice
1374 versa if you have a file with double quotes. However, handling a file with
1375 both kinds of quotes in **DC_ENV_ARGS** is not supported due to the
1376 complexity of the parsing, though such files are still supported on the
1377 command-line where the parsing is done by the shell.
1378 \f[R]
1379 .fi
1380 .PP
1381 \f[B]DC_LINE_LENGTH\f[R]
1382 .PP
1383 : If this environment variable exists and contains an integer that is
1384 greater than \f[B]1\f[R] and is less than \f[B]UINT16_MAX\f[R]
1385 (\f[B]2\[ha]16-1\f[R]), dc(1) will output lines to that length,
1386 including the backslash newline combo.
1387 The default line length is \f[B]70\f[R].
1388 .PP
1389 \f[B]DC_EXPR_EXIT\f[R]
1390 .PP
1391 : If this variable exists (no matter the contents), dc(1) will exit
1392 immediately after executing expressions and files given by the
1393 \f[B]-e\f[R] and/or \f[B]-f\f[R] command-line options (and any
1394 equivalents).
1395 .SH EXIT STATUS
1396 .PP
1397 dc(1) returns the following exit statuses:
1398 .PP
1399 \f[B]0\f[R]
1400 .PP
1401 : No error.
1402 .PP
1403 \f[B]1\f[R]
1404 .PP
1405 : A math error occurred.
1406 This follows standard practice of using \f[B]1\f[R] for expected errors,
1407 since math errors will happen in the process of normal execution.
1408 .IP
1409 .nf
1410 \f[C]
1411 Math errors include divide by **0**, taking the square root of a negative
1412 number, using a negative number as a bound for the pseudo-random number
1413 generator, attempting to convert a negative number to a hardware integer,
1414 overflow when converting a number to a hardware integer, and attempting to
1415 use a non-integer where an integer is required.
1416
1417 Converting to a hardware integer happens for the second operand of the power
1418 (**\[rs]\[ha]**), places (**\[rs]\[at]**), left shift (**H**), and right shift (**h**)
1419 operators.
1420 \f[R]
1421 .fi
1422 .PP
1423 \f[B]2\f[R]
1424 .PP
1425 : A parse error occurred.
1426 .IP
1427 .nf
1428 \f[C]
1429 Parse errors include unexpected **EOF**, using an invalid character, failing
1430 to find the end of a string or comment, and using a token where it is
1431 invalid.
1432 \f[R]
1433 .fi
1434 .PP
1435 \f[B]3\f[R]
1436 .PP
1437 : A runtime error occurred.
1438 .IP
1439 .nf
1440 \f[C]
1441 Runtime errors include assigning an invalid number to **ibase**, **obase**,
1442 or **scale**; give a bad expression to a **read()** call, calling **read()**
1443 inside of a **read()** call, type errors, and attempting an operation when
1444 the stack has too few elements.
1445 \f[R]
1446 .fi
1447 .PP
1448 \f[B]4\f[R]
1449 .PP
1450 : A fatal error occurred.
1451 .IP
1452 .nf
1453 \f[C]
1454 Fatal errors include memory allocation errors, I/O errors, failing to open
1455 files, attempting to use files that do not have only ASCII characters (dc(1)
1456 only accepts ASCII characters), attempting to open a directory as a file,
1457 and giving invalid command-line options.
1458 \f[R]
1459 .fi
1460 .PP
1461 The exit status \f[B]4\f[R] is special; when a fatal error occurs, dc(1)
1462 always exits and returns \f[B]4\f[R], no matter what mode dc(1) is in.
1463 .PP
1464 The other statuses will only be returned when dc(1) is not in
1465 interactive mode (see the \f[B]INTERACTIVE MODE\f[R] section), since
1466 dc(1) resets its state (see the \f[B]RESET\f[R] section) and accepts
1467 more input when one of those errors occurs in interactive mode.
1468 This is also the case when interactive mode is forced by the
1469 \f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
1470 .PP
1471 These exit statuses allow dc(1) to be used in shell scripting with error
1472 checking, and its normal behavior can be forced by using the
1473 \f[B]-i\f[R] flag or \f[B]--interactive\f[R] option.
1474 .SH INTERACTIVE MODE
1475 .PP
1476 Like bc(1), dc(1) has an interactive mode and a non-interactive mode.
1477 Interactive mode is turned on automatically when both \f[B]stdin\f[R]
1478 and \f[B]stdout\f[R] are hooked to a terminal, but the \f[B]-i\f[R] flag
1479 and \f[B]--interactive\f[R] option can turn it on in other cases.
1480 .PP
1481 In interactive mode, dc(1) attempts to recover from errors (see the
1482 \f[B]RESET\f[R] section), and in normal execution, flushes
1483 \f[B]stdout\f[R] as soon as execution is done for the current input.
1484 .SH TTY MODE
1485 .PP
1486 If \f[B]stdin\f[R], \f[B]stdout\f[R], and \f[B]stderr\f[R] are all
1487 connected to a TTY, dc(1) turns on \[dq]TTY mode.\[dq]
1488 .PP
1489 TTY mode is required for history to be enabled (see the \f[B]COMMAND
1490 LINE HISTORY\f[R] section).
1491 It is also required to enable special handling for \f[B]SIGINT\f[R]
1492 signals.
1493 .PP
1494 TTY mode is different from interactive mode because interactive mode is
1495 required in the bc(1)
1496 specification (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html),
1497 and interactive mode requires only \f[B]stdin\f[R] and \f[B]stdout\f[R]
1498 to be connected to a terminal.
1499 .SH SIGNAL HANDLING
1500 .PP
1501 Sending a \f[B]SIGINT\f[R] will cause dc(1) to stop execution of the
1502 current input.
1503 If dc(1) is in TTY mode (see the \f[B]TTY MODE\f[R] section), it will
1504 reset (see the \f[B]RESET\f[R] section).
1505 Otherwise, it will clean up and exit.
1506 .PP
1507 Note that \[dq]current input\[dq] can mean one of two things.
1508 If dc(1) is processing input from \f[B]stdin\f[R] in TTY mode, it will
1509 ask for more input.
1510 If dc(1) is processing input from a file in TTY mode, it will stop
1511 processing the file and start processing the next file, if one exists,
1512 or ask for input from \f[B]stdin\f[R] if no other file exists.
1513 .PP
1514 This means that if a \f[B]SIGINT\f[R] is sent to dc(1) as it is
1515 executing a file, it can seem as though dc(1) did not respond to the
1516 signal since it will immediately start executing the next file.
1517 This is by design; most files that users execute when interacting with
1518 dc(1) have function definitions, which are quick to parse.
1519 If a file takes a long time to execute, there may be a bug in that file.
1520 The rest of the files could still be executed without problem, allowing
1521 the user to continue.
1522 .PP
1523 \f[B]SIGTERM\f[R] and \f[B]SIGQUIT\f[R] cause dc(1) to clean up and
1524 exit, and it uses the default handler for all other signals.
1525 The one exception is \f[B]SIGHUP\f[R]; in that case, when dc(1) is in
1526 TTY mode, a \f[B]SIGHUP\f[R] will cause dc(1) to clean up and exit.
1527 .SH COMMAND LINE HISTORY
1528 .PP
1529 dc(1) supports interactive command-line editing.
1530 If dc(1) is in TTY mode (see the \f[B]TTY MODE\f[R] section), history is
1531 enabled.
1532 Previous lines can be recalled and edited with the arrow keys.
1533 .PP
1534 \f[B]Note\f[R]: tabs are converted to 8 spaces.
1535 .SH SEE ALSO
1536 .PP
1537 bc(1)
1538 .SH STANDARDS
1539 .PP
1540 The dc(1) utility operators are compliant with the operators in the
1541 bc(1) IEEE Std 1003.1-2017
1542 (\[lq]POSIX.1-2017\[rq]) (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
1543 specification.
1544 .SH BUGS
1545 .PP
1546 None are known.
1547 Report bugs at https://git.yzena.com/gavin/bc.
1548 .SH AUTHOR
1549 .PP
1550 Gavin D.
1551 Howard <gavin@yzena.com> and contributors.