1 Configuration parameters
3 Configuration parameters affect how the calculator performs certain
4 operations. Among features that are controlled by these parameters
5 are the accuracy of some calculations, the displayed format of results,
6 the choice from possible alternative algorithms, and whether or not
7 debugging information is displayed. The parameters are
8 read or set using the "config" built-in function; they remain in effect
9 until their values are changed by a config or equivalent instruction.
10 The following parameters can be specified:
12 "all" all configuration values listed below
14 "trace" turns tracing features on or off
15 "display" sets number of digits in prints.
16 "epsilon" sets error value for transcendentals.
17 "maxprint" sets maximum number of elements printed.
18 "mode" sets printout mode.
19 "mode2" sets 2nd base printout mode.
20 "mul2" sets size for alternative multiply.
21 "sq2" sets size for alternative squaring.
22 "pow2" sets size for alternate powering.
23 "redc2" sets size for alternate REDC.
24 "tilde" enable/disable printing of the roundoff '~'
25 "tab" enable/disable printing of leading tabs
26 "quomod" sets rounding mode for quomod
27 "quo" sets rounding mode for //, default for quo
28 "mod" sets "rounding" mode for %, default for mod
29 "sqrt" sets rounding mode for sqrt
30 "appr" sets rounding mode for appr
31 "cfappr" sets rounding mode for cfappr
32 "cfsim" sets rounding mode for cfsim
33 "round" sets rounding mode for round and bround
34 "outround" sets rounding mode for printing of numbers
35 "leadzero" enables/disables printing of 0 as in 0.5
36 "fullzero" enables/disables padding zeros as in .5000
37 "maxscan" maximum number of scan errors before abort
38 "prompt" default interactive prompt
39 "more" default interactive multi-line input prompt
40 "blkmaxprint" number of block octets to print, 0 means all
41 "blkverbose" TRUE=>print all lines, FALSE=>skip duplicates
42 "blkbase" block output base
43 "blkfmt" block output format
44 "calc_debug" controls internal calc debug information
45 "resource_debug" controls resource file debug information
46 "user_debug" for user defined debug information
47 "verbose_quit" TRUE=>print message on empty quit or abort
48 "ctrl_d" The interactive meaning of ^D (Control D)
49 "program" Read-only calc program or shell script path
50 "basename" Read-only basename of the program value
51 "windows" Read-only indicator of MS windows
52 "cygwin" TRUE=>calc compiled with cygwin, Read-only
53 "compile_custom" TRUE=>calc was compiled with custom functions
54 "allow_custom" TRUE=>custom functions are enabled
55 "version" Read-only calc version
57 The "all" config value allows one to save/restore the configuration
58 set of values. The return of:
62 is a CONFIG type which may be used as the 2rd arg in a later call.
63 One may save, modify and restore the configuration state as follows:
65 oldstate = config("all")
70 config("all", oldstate)
72 This save/restore method is useful within functions.
73 It allows functions to control their configuration without impacting
76 There are two configuration state aliases that may be set. To
77 set the backward compatible standard configuration:
79 config("all", "oldstd")
81 The "oldstd" will restore the configuration to the default at startup.
83 A new configuration that some people prefer may be set by:
85 config("all", "newstd")
87 The "newstd" is not backward compatible with the historic
88 configuration. Even so, some people prefer this configuration
89 and place the config("all", "newstd") command in their CALCRC
90 startup files; newstd may also be established by invoking calc
93 The following are synonyms for true:
104 The following are synonyms for false:
115 Examples of setting some parameters are:
117 config("mode", "exp"); exponential output
118 config("display", 50); 50 digits of output
119 epsilon(epsilon() / 8); 3 bits more accuracy
120 config("tilde", 0) disable roundoff tilde printing
121 config("tab", "off") disable leading tab printing
124 Detailed config descriptions
128 config("trace", bitflag)
130 When nonzero, the "trace" parameter activates one or more features
131 that may be useful for debugging. These features correspond to
132 powers of 2 which contribute additively to config("trace"):
134 1: opcodes are displayed as functions are evaluated
136 2: disables the inclusion of debug lines in opcodes for functions
137 whose definitions are introduced with a left-brace.
139 4: the number of links for real and complex numbers are displayed
140 when the numbers are printed; for real numbers "#" or for
141 complex numbers " printed immediately after the number.
143 8: the opcodes for a new functions are displayed when the function
144 is successfully defined.
146 See also resource_debug, calc_debug and user_debug below for more
151 config("display", int)
153 The "display" parameter specifies the maximum number of digits after
154 the decimal point to be printed in real or exponential mode in
155 normal unformatted printing (print, strprint, fprint) or in
156 formatted printing (printf, strprintf, fprintf) when precision is not
157 specified. The initial value for oldstd is 20, for newstd 10.
158 The parameter may be changed to the value d by either
159 config("display", d) or by display (d). This parameter does not change
160 the stored value of a number. Where rounding is necessary to
161 display up to d decimal places, the type of rounding to be used is
162 controlled by config("outround").
166 config("epsilon", real)
169 The "epsilon" parameter specifies the default accuracy for the
170 calculation of functions for which exact values are not possible or
171 not desired. For most functions, the
173 remainder = exact value - calculated value
175 has absolute value less than epsilon, but, except when the sign of
176 the remainder is controlled by an appropriate parameter, the
177 absolute value of the remainder usually does not exceed epsilon/2.
178 Functions which require an epsilon value accept an
179 optional argument which overrides this default epsilon value for
180 that single call. The value v can be assigned to the "epsilon"
181 parameter by either config("epsilon", v) or epsilon(v); each of
182 these functions return the current epsilon value; config("epsilon")
183 or epsilon() returns but does not change the epsilon value.
184 For the transcendental functions and the functions sqrt() and
185 appr(), the calculated value is always a multiple of epsilon.
189 config("mode", "mode_string")
190 config("mode2", "mode_string")
192 The "mode" parameter is a string specifying the mode for printing of
193 numbers by the unformatted print functions, and the default
194 ("%d" specifier) for formatted print functions. The initial mode
195 is "real". The available modes are:
197 config("mode") meaning equivalent
200 "binary" base 2 fractions base(2)
203 "octal" base 8 fractions base(8)
206 "real" base 10 floating point base(10)
210 "integer" base 10 integer base(-10)
213 "hexadecimal" base 16 fractions base(16)
216 "fraction" base 10 fractions base(1/3)
219 "scientific" base 10 scientific notation base(1e20)
223 Where multiple strings are given, the first string listed is what
224 config("mode") will return.
226 The "mode2" controls the double base output. When set to a value
227 other than "off", calc outputs files in both the "base" mode as
228 well as the "base2" mode. The "mode2" value may be any of the
229 "mode" values with the addition of:
231 "off" disable 2nd base output mode base2(0)
233 The base() builtin function sets and returns the "mode" value.
234 The base2() builtin function sets and returns the "mode2" value.
236 The default "mode" is "real". The default "mode2" is "off".
240 config("maxprint", int)
242 The "maxprint" parameter specifies the maximum number of elements to
243 be displayed when a matrix or list is printed. The initial value is 16.
250 Mul2 and sq2 specify the sizes of numbers at which calc switches
251 from its first to its second algorithm for multiplying and squaring.
252 The first algorithm is the usual method of cross multiplying, which
253 runs in a time of O(N^2). The second method is a recursive and
254 complicated method which runs in a time of O(N^1.585). The argument
255 for these parameters is the number of binary words at which the
256 second algorithm begins to be used. The minimum value is 2, and
257 the maximum value is very large. If 2 is used, then the recursive
258 algorithm is used all the way down to single digits, which becomes
259 slow since the recursion overhead is high. If a number such as
260 1000000 is used, then the recursive algorithm is never used, causing
261 calculations for large numbers to slow down. For a typical example
262 on a 386, the two algorithms are about equal in speed for a value
263 of 20, which is about 100 decimal digits. A value of zero resets
264 the parameter back to its default value. Usually there is no need
265 to change these parameters.
271 Pow2 specifies the sizes of numbers at which calc switches from
272 its first to its second algorithm for calculating powers modulo
273 another number. The first algorithm for calculating modular powers
274 is by repeated squaring and multiplying and dividing by the modulus.
275 The second method uses the REDC algorithm given by Peter Montgomery
276 which avoids divisions. The argument for pow2 is the size of the
277 modulus at which the second algorithm begins to be used.
283 Redc2 specifies the sizes of numbers at which calc switches from
284 its first to its second algorithm when using the REDC algorithm.
285 The first algorithm performs a multiply and a modular reduction
286 together in one loop which runs in O(N^2). The second algorithm
287 does the REDC calculation using three multiplies, and runs in
288 O(N^1.585). The argument for redc2 is the size of the modulus at
289 which the second algorithm begins to be used.
293 config("tilde", boolean)
295 Config("tilde") controls whether or not a leading tilde ('~') is
296 printed to indicate that a number has not been printed exactly
297 because the number of decimal digits required would exceed the
298 specified maximum number. The initial "tilde" value is 1.
302 config("tab", boolean)
304 Config ("tab") controls the printing of a tab before results
305 automatically displayed when working interactively. It does not
306 affect the printing by the functions print, printf, etc. The initial
311 config("quomod", bitflag)
312 config("quo", bitflag)
313 config("mod", bitflag)
314 config("sqrt", bitflag)
315 config("appr", bitflag)
316 config("cfappr", bitflag)
317 config("cfsim", bitflag)
318 config("outround", bitflag)
319 config("round", bitflag)
321 The "quomod", "quo", "mod", "sqrt", "appr", "cfappr", "cfsim", and
322 "round" control the way in which any necessary rounding occurs.
323 Rounding occurs when for some reason, a calculated or displayed
324 value (the "approximation") has to differ from the "true value",
325 e.g. for quomod and quo, the quotient is to be an integer, for sqrt
326 and appr, the approximation is to be a multiple of an explicit or
327 implicit "epsilon", for round and bround (both controlled by
328 config("round")) the number of decimal places or fractional bits
329 in the approximation is limited. Zero value for any of these
330 parameters indicates that the true value is greater than the approximation,
331 i.e. the rounding is "down", or in the case of mod, that the
332 residue has the same sign as the divisor. If bit 4 of the
333 parameter is set, the rounding of to the nearest acceptable candidate
334 when this is uniquely determined; in the remaining ambiguous cases,
335 the type of rounding is determined by the lower bits of the parameter
336 value. If bit 3 is set, the rounding for quo, appr and sqrt,
337 is to the nearest even integer or the nearest even multiple of epsilon,
338 and for round to the nearest even "last decimal place". The effects
339 of the 3 lowest bits of the parameter value are as follows:
341 Bit 0: Unconditional reversal (down to up, even to odd, etc.)
342 Bit 1: Reversal if the exact value is negative
343 Bit 2: Reversal if the divisor or epsilon is negative
345 (Bit 2 is irrelevant for the functions round and bround since the
346 equivalent epsilon (a power of 1/10 or 1/2) is always positive.)
348 For quomod, the quotient is rounded to an integer value as if
349 evaluating quo with config("quo") == config("quomod"). Similarly,
350 quomod and mod give the same residues if config("mod") == config("quomod").
352 For the sqrt function, if bit 5 of config("sqrt") is set, the exact
353 square-root is returned when this is possible; otherwise the
354 result is rounded to a multiple of epsilon as determined by the
355 five lower order bits. Bit 6 of config("sqrt") controls whether the
356 principal or non-principal square-root is returned.
358 For the functions cfappr and cfsim, whether the "rounding" is down
359 or up, etc. is controlled by the appropriate bits of config("cfappr")
360 and config("cfsim") as for quomod, quo, etc.
362 The "outround" parameter determines the type of rounding to be used
363 by the various kinds of printing to the output: bits 0, 1, 3 and 4
364 are used in the same way as for the functions round and bround.
368 config("leadzero", bool)
370 The "leadzero" parameter controls whether or not a 0 is printed
371 before the decimal point in non-zero fractions with absolute value
372 less than 1, e.g. whether 1/2 is printed as 0.5 or .5. The
373 initial value is 0, corresponding to the printing .5.
377 config("fullzero", bool)
379 The "fullzero" parameter controls whether or not in decimal floating-
380 point printing, the digits are padded with zeros to reach the
381 number of digits specified by config("display") or by a precision
382 specification in formatted printing. The initial value for this
383 parameter is 0, so that, for example, if config("display") >= 2,
384 5/4 will print in "real" mode as 1.25.
388 config("maxscan", int)
390 The maxscan value controls how many scan errors are allowed
391 before the compiling phase of a computation is aborted. The initial
392 value of "maxscan" is 20. Setting maxscan to 0 disables this feature.
396 config("prompt", str)
398 The default prompt when in interactive mode is "> ". One may change
399 this prompt to a more cut-and-paste friendly prompt by:
401 config("prompt", "; ")
403 On windowing systems that support cut/paste of a line, one may
404 cut/copy an input line and paste it directly into input. The
405 leading ';' will be ignored.
411 When inside multi-line input, the more prompt is used. One may
414 config("more", ";; ")
418 config("blkmaxprint", int)
420 The "blkmaxprint" config value limits the number of octets to print
421 for a block. A "blkmaxprint" of 0 means to print all octets of a
422 block, regardless of size.
424 The default is to print only the first 256 octets.
428 config("blkverbose", bool)
430 The "blkverbose" determines if all lines, including duplicates
431 should be printed. If TRUE, then all lines are printed. If false,
432 duplicate lines are skipped and only a "*" is printed in a style
433 similar to od. This config value has not meaning if "blkfmt" is "str".
435 The default value for "blkverbose" is FALSE: duplicate lines are
440 config("blkbase", "blkbase_string")
442 The "blkbase" determines the base in which octets of a block
443 are printed. Possible values are:
445 "hexadecimal" Octets printed in 2 digit hex
449 "octal" Octets printed in 3 digit octal
452 "character" Octets printed as chars with non-printing
453 "char" chars as \123 or \n, \t, \r
455 "binary" Octets printed as 0 or 1 chars
458 "raw" Octets printed as is, i.e. raw binary
461 Where multiple strings are given, the first string listed is what
462 config("blkbase") will return.
464 The default "blkbase" is "hexadecimal".
468 config("blkfmt", "blkfmt_string")
470 The "blkfmt" determines for format of how block are printed:
472 "lines" print in lines of up to 79 chars + newline
475 "strings" print as one long string
479 "od_style" print in od-like format, with leading offset,
480 "odstyle" followed by octets in the given base
483 "hd_style" print in hex dump format, with leading offset,
484 "hdstyle" followed by octets in the given base, followed
485 "hd" by chars or '.' if no-printable or blank
488 Where multiple strings are given, the first string listed is what
489 config("blkfmt") will return.
491 The default "blkfmt" is "hd_style".
495 config("calc_debug", bitflag)
497 The "calc_debug" is intended for controlling internal calc routines
498 that test its operation, or collect or display information that
499 might be useful for debug purposes. Much of the output from these
500 will make sense only to calc wizards. Zero value (the default for
501 both oldstd and newstd) of config("resource_debug") corresponds to
502 switching off all these routines. For nonzero value, particular
503 bits currently have the following meanings:
505 n Meaning of bit n of config("calc_debug")
507 0 outputs shell commands prior to execution
509 1 outputs currently active functions when a quit instruction
512 2 some details of shs, shs1 and md5 hash states are included
513 in the output when these are printed
515 3 when a function constructs a block value, tests are
516 made that the result has the properties required for use of
517 that block, e.g. that the pointer to the start of the
518 block is not NULL, and that its "length" is not negative.
519 A failure will result in a runtime error.
521 4 Report on changes to the state of stdin as well as changes
522 to internal variables that control the setting and restoring
525 5 Report on changes to the run state of calc.
527 6 Report on rand() subtractive 100 shuffle generator issues.
529 Bits >= 7 are reserved for future use and should not be used at this time.
531 By default, "calc_debug" is 0. The initial value may be overridden
532 by the -D command line option.
536 config("resource_debug", bitflag)
537 config("lib_debug", bitflag)
539 The "resource_debug" parameter is intended for controlling the possible
540 display of special information relating to functions, objects, and
541 other structures created by instructions in calc scripts.
542 Zero value of config("resource_debug") means that no such information
543 is displayed. For other values, the non-zero bits which currently
544 have meanings are as follows:
546 n Meaning of bit n of config("resource_debug")
548 0 When a function is defined, redefined or undefined at
549 interactive level, a message saying what has been done
552 1 When a function is defined, redefined or undefined during
553 the reading of a file, a message saying what has been done
556 2 Show func will display more information about a functions
557 arguments and argument summary information.
559 3 During execution, allow calc standard resource files
560 to output additional debugging information.
562 The value for config("resource_debug") in both oldstd and newstd is 3,
563 but if calc is invoked with the -d flag, its initial value is zero.
564 Thus, if calc is started without the -d flag, until config("resource_debug")
565 is changed, a message will be output when a function is defined
566 either interactively or during the reading of a file.
568 The name config("lib_debug") is equivalent to config("resource_debug")
569 and is included for backward compatibility.
571 By default, "resource_debug" is 3. The -d flag changes this default to 0.
572 The initial value may be overridden by the -D command line option.
576 config("user_debug", int)
578 The "user_debug" is provided for use by users. Calc ignores this value
579 other than to set it to 0 by default (for both "oldstd" and "newstd").
580 No calc code or standard resource should change this value. Users
581 should feel free to use it in any way. In particular they may
582 use particular bits for special purposes as with "calc_debug", or
583 they may use it to indicate a debug level with larger values
584 indicating more stringent and more informative tests with presumably
585 slower operation or more memory usage, and a particular value (like
586 -1 or 0) corresponding to "no tests".
588 By default, "user_debug" is 0. The initial value may be overridden
589 by the -D command line option.
593 config("verbose_quit", bool)
595 The "verbose_quit" controls the print of the message:
597 quit or abort executed
599 when a non-interactive quit or abort without an argument is encountered.
600 A quit of abort without an argument does not display a message when
601 invoked at the interactive level.
603 By deafult, "verbose_quit" is false.
607 config("ctrl_d", "ctrl_d_string")
609 For calc that is using the calc binding (not GNU-readline) facility:
611 The "ctrl_d" controls the interactive meaning of ^D (Control D):
613 "virgin_eof" If ^D is the only character that has been typed
614 "virgineof" on a line, then calc will exit. Otherwise ^D
615 "virgin" will act according to the calc binding, which
616 "default" by default is a Emacs-style delete-char.
618 "never_eof" The ^D never exits calc and only acts according
619 "nevereof" calc binding, which by default is a Emacs-style
622 "empty_eof" The ^D always exits calc if typed on an empty line.
623 "emptyeof" This condition occurs when ^D either the first
624 "empty" character typed, or when all other characters on
625 the line have been removed (say by deleting them).
627 Where multiple strings are given, the first string listed is what
628 config("ctrl_d") will return.
630 Note that config("ctrl_d") actually controls each and every character
631 that is bound to ``delete_char''. By default, ``delete_char'' is
632 Control D. Any character(s) bound to ``delete_char'' will cause calc
633 to exit (or not exit) as directed by config("ctrl_d").
635 See the ``binding'' help for information on the default calc bindings.
637 The default "ctrl_d", without GNU-readline is "virgin_eof".
639 For calc that was compiled with the GNU-readline facility:
641 The "ctrl_d" controls the interactive meaning of ^D (Control D):
643 "virgin_eof" Same as "empty_eof"
648 "never_eof" The ^D never exits calc and only acts according
649 "nevereof" calc binding, which by default is a Emacs-style
652 "empty_eof" The ^D always exits calc if typed on an empty line.
653 "emptyeof" This condition occurs when ^D either the first
654 "empty" character typed, or when all other characters on
656 Where multiple strings are given, the first string listed is what
657 config("ctrl_d") will return.
659 The default "ctrl_d", with GNU-readline is effectively "empty_eof".
661 Literally it is "virgin_eof", but since "virgin_eof" is the
662 same as "empty_eof", the default is effectively "empty_eof".
664 Emacs users may find the default behavior objectionable, particularly
665 when using the GNU-readline facility. Such users may want to add the line:
667 config("ctrl_d", "never_eof"),;
669 to their ~/.calcrc startup file to prevent ^D from causing calc to exit.
673 config("program") <== NOTE: This is a read-only config value
675 The full path to the calc program, or the calc shell script can be
680 This config parameter is read-only and cannot be set.
684 config("basename") <== NOTE: This is a read-only config value
686 The calc program, or the calc shell script basename can be obtained by:
690 The config("basename") is the config("program") without any leading
691 path. If config("program") has a / in it, config("basename") is
692 everything after the last /, otherwise config("basename") is the
693 same as config("program").
695 This config parameter is read-only and cannot be set.
699 config("windows") <== NOTE: This is a read-only config value
701 Returns TRUE if you are running on a MS windows system, false if you
702 are running on an operating system that does not hate you.
704 This config parameter is read-only and cannot be set.
708 config("cygwin") <== NOTE: This is a read-only config value
710 Returns TRUE if you calc was compiled with cygwin, false otherwise.
712 This config parameter is read-only and cannot be set.
716 config("compile_custom") <== NOTE: This is a read-only config value
718 Returns TRUE if you calc was compiled with -DCUSTOM. By default,
719 the calc Makefile uses ALLOW_CUSTOM= -DCUSTOM so by default
720 config("compile_custom") is TRUE. If, however, calc is compiled
721 without -DCUSTOM, then config("compile_custom") will be FALSE.
723 The config("compile_custom") value is only affected by compile
724 flags. The calc -D runtime command line option does not change
725 the config("compile_custom") value.
727 See also config("allow_custom").
729 This config parameter is read-only and cannot be set.
733 config("allow_custom") <== NOTE: This is a read-only config value
735 Returns TRUE if you custom functions are enabled. To allow the use
736 of custom functions, calc must be compiled with -DCUSTOM (which it
737 is by default) AND calc run be run with the -D runtime command line
738 option (which it is not by default).
740 If config("allow_custom") is TRUE, then custom functions are allowed.
741 If config("allow_custom") is FALSE, then custom functions are not
744 See also config("compile_custom").
746 This config parameter is read-only and cannot be set.
750 config("version") <== NOTE: This is a read-only config value
752 The version string of the calc program can be obtained by:
756 This config parameter is read-only and cannot be set.