Configuration parameters Configuration parameters affect how the calculator performs certain operations. Among features that are controlled by these parameters are the accuracy of some calculations, the displayed format of results, the choice from possible alternative algorithms, and whether or not debugging information is displayed. The parameters are read or set using the "config" built-in function; they remain in effect until their values are changed by a config or equivalent instruction. The following parameters can be specified: "all" all configuration values listed below "trace" turns tracing features on or off "display" sets number of digits in prints. "epsilon" sets error value for transcendentals. "maxprint" sets maximum number of elements printed. "mode" sets printout mode. "mul2" sets size for alternative multiply. "sq2" sets size for alternative squaring. "pow2" sets size for alternate powering. "redc2" sets size for alternate REDC. "tilde" enable/disable printing of the roundoff '~' "tab" enable/disable printing of leading tabs "quomod" sets rounding mode for quomod "quo" sets rounding mode for //, default for quo "mod" sets "rounding" mode for %, default for mod "sqrt" sets rounding mode for sqrt "appr" sets rounding mode for appr "cfappr" sets rounding mode for cfappr "cfsim" sets rounding mode for cfsim "round" sets rounding mode for round and bround "outround" sets rounding mode for printing of numbers "leadzero" enables/disables printing of 0 as in 0.5 "fullzero" enables/disables padding zeros as in .5000 "maxscan" maximum number of scan errors before abort "prompt" default interactive prompt "more" default interactive multi-line input prompt "blkmaxprint" number of block octets to print, 0 means all "blkverbose" TRUE=>print all lines, FALSE=>skip duplicates "blkbase" block output base "blkfmt" block output format "calc_debug" controls internal calc debug information "lib_debug" controls library script debug information "user_debug" for user defined debug information "verbose_quit" TRUE=>print message on empty quit or abort The "all" config value allows one to save/restore the configuration set of values. The return of: config("all") is a CONFIG type which may be used as the 2rd arg in a later call. One may save, modify and restore the configuration state as follows: oldstate = config("all") ... config("tab", 0) config("mod", 10) ... config("all", oldstate) This save/restore method is useful within functions. It allows functions to control their configuration without impacting the calling function. There are two configuration state aliases that may be set. To set the backward compatible standard configuration: config("all", "oldstd") The "oldstd" will restore the configuration to the default at startup. A new configuration that some people prefer may be set by: config("all", "newstd") The "newstd" is not backward compatible with the historic configuration. Even so, some people prefer this configuration and place the config("all", "newstd") command in their CALCRC startup files; newstd may also be established by invoking calc with the flag -n. When nonzero, the "trace" parameter activates one or more features that may be useful for debugging. These features correspond to powers of 2 which contribute additively to config("trace"): 1: opcodes are displayed as functions are evaluated 2: disables the inclusion of debug lines in opcodes for functions whose definitions are introduced with a left-brace. 4: the number of links for real and complex numbers are displayed when the numbers are printed; for real numbers "#" or for complex numbers "##", followed by the number of links, are printed immediately after the number. 8: the opcodes for a new functions are displayed when the function is successfully defined. See also lib_debug, calc_debug and user_debug below for more debug levels. The "display" parameter specifies the maximum number of digits after the decimal point to be printed in real or exponential mode in normal unformatted printing (print, strprint, fprint) or in formatted printing (printf, strprintf, fprintf) when precision is not specified. The initial value for oldstd is 20, for newstd 10. The parameter may be changed to the value d by either config("display", d) or by display (d). This parameter does not change the stored value of a number. Where rounding is necessary to display up to d decimal places, the type of rounding to be used is controlled by config("outround"). The "epsilon" parameter specifies the default accuracy for the calculation of functions for which exact values are not possible or not desired. For most functions, the remainder = exact value - calculated value has absolute value less than epsilon, but, except when the sign of the remainder is controlled by an appropriate parameter, the absolute value of the remainder usually does not exceed epsilon/2. Functions which require an epsilon value accept an optional argument which overrides this default epsilon value for that single call. The value v can be assigned to the "epsilon" parameter by either config("epsilon", v) or epsilon(v); each of these functions return the current epsilon value; config("epsilon") or epsilon() returns but does not change the epsilon value. For the transcendental functions and the functions sqrt() and appr(), the calculated value is always a multiple of epsilon. The "mode" parameter is a string specifying the mode for printing of numbers by the unformatted print functions, and the default ("%d" specifier) for formatted print functions. The initial mode is "real". The available modes are: "frac" decimal fractions "int" decimal integer "real" decimal floating point "exp" decimal exponential "hex" hex fractions "oct" octal fractions "bin" binary fractions The "maxprint" parameter specifies the maximum number of elements to be displayed when a matrix or list is printed. The initial value is 16. Mul2 and sq2 specify the sizes of numbers at which calc switches from its first to its second algorithm for multiplying and squaring. The first algorithm is the usual method of cross multiplying, which runs in a time of O(N^2). The second method is a recursive and complicated method which runs in a time of O(N^1.585). The argument for these parameters is the number of binary words at which the second algorithm begins to be used. The minimum value is 2, and the maximum value is very large. If 2 is used, then the recursive algorithm is used all the way down to single digits, which becomes slow since the recursion overhead is high. If a number such as 1000000 is used, then the recursive algorithm is never used, causing calculations for large numbers to slow down. For a typical example on a 386, the two algorithms are about equal in speed for a value of 20, which is about 100 decimal digits. A value of zero resets the parameter back to its default value. Usually there is no need to change these parameters. Pow2 specifies the sizes of numbers at which calc switches from its first to its second algorithm for calculating powers modulo another number. The first algorithm for calculating modular powers is by repeated squaring and multiplying and dividing by the modulus. The second method uses the REDC algorithm given by Peter Montgomery which avoids divisions. The argument for pow2 is the size of the modulus at which the second algorithm begins to be used. Redc2 specifies the sizes of numbers at which calc switches from its first to its second algorithm when using the REDC algorithm. The first algorithm performs a multiply and a modular reduction together in one loop which runs in O(N^2). The second algorithm does the REDC calculation using three multiplies, and runs in O(N^1.585). The argument for redc2 is the size of the modulus at which the second algorithm begins to be used. Config("tilde") controls whether or not a leading tilde ('~') is printed to indicate that a number has not been printed exactly because the number of decimal digits required would exceed the specified maximum number. The initial "tilde" value is 1. Config ("tab") controls the printing of a tab before results automatically displayed when working interactively. It does not affect the printing by the functions print, printf, etc. The initial "tab" value is 1. The "quomod", "quo", "mod", "sqrt", "appr", "cfappr", "cfsim", and "round" control the way in which any necessary rounding occurs. Rounding occurs when for some reason, a calculated or displayed value (the "approximation") has to differ from the "true value", e.g. for quomod and quo, the quotient is to be an integer, for sqrt and appr, the approximation is to be a multiple of an explicit or implicit "epsilon", for round and bround (both controlled by config("round")) the number of decimal places or fractional bits in the approximation is limited. Zero value for any of these parameters indicates that the true value is greater than the approximation, i.e. the rounding is "down", or in the case of mod, that the residue has the same sign as the divisor. If bit 4 of the parameter is set, the rounding of to the nearest acceptable candidate when this is uniquely determined; in the remaining ambiguous cases, the type of rounding is determined by the lower bits of the parameter value. If bit 3 is set, the rounding for quo, appr and sqrt, is to the nearest even integer or the nearest even multiple of epsilon, and for round to the nearest even "last decimal place". The effects of the 3 lowest bits of the parameter value are as follows: Bit 0: Unconditional reversal (down to up, even to odd, etc.) Bit 1: Reversal if the exact value is negative Bit 2: Reversal if the divisor or epsilon is negative (Bit 2 is irrelevant for the functions round and bround since the equivalent epsilon (a power of 1/10 or 1/2) is always positive.) For quomod, the quotient is rounded to an integer value as if evaluating quo with config("quo") == config("quomod"). Similarly, quomod and mod give the same residues if config("mod") == config("quomod"). For the sqrt function, if bit 5 of config("sqrt") is set, the exact square-root is returned when this is possible; otherwise the result is rounded to a multiple of epsilon as determined by the five lower order bits. Bit 6 of config("sqrt") controls whether the principal or non-principal square-root is returned. For the functions cfappr and cfsim, whether the "rounding" is down or up, etc. is controlled by the appropriate bits of config("cfappr") and config("cfsim") as for quomod, quo, etc. The "outround" parameter determines the type of rounding to be used by the various kinds of printing to the output: bits 0, 1, 3 and 4 are used in the same way as for the functions round and bround. The "leadzero" parameter controls whether or not a 0 is printed before the decimal point in non-zero fractions with absolute value less than 1, e.g. whether 1/2 is printed as 0.5 or .5. The initial value is 0, corresponding to the printing .5. The "fullzero" parameter controls whether or not in decimal floating- point printing, the digits are padded with zeros to reach the number of digits specified by config("display") or by a precision specification in formatted printing. The initial value for this parameter is 0, so that, for example, if config("display") >= 2, 5/4 will print in "real" mode as 1.25. The maxscan value controls how many scan errors are allowed before the compiling phase of a computation is aborted. The initial value of "maxscan" is 20. Setting maxscan to 0 disables this feature. The default prompt when in interactive mode is "> ". One may change this prompt to a more cut-and-paste friendly prompt by: config("prompt", "; ") On windowing systems that support cut/paste of a line, one may cut/copy an input line and paste it directly into input. The leading ';' will be ignored. When inside multi-line input, the more prompt is used. One may change it by: config("more", ";; ") The "blkmaxprint" config value limits the number of octets to print for a block. A "blkmaxprint" of 0 means to print all octets of a block, regardless of size. The default is to print only the first 256 octets. The "blkverbose" determines if all lines, including duplicates should be printed. If TRUE, then all lines are printed. If false, duplicate lines are skipped and only a "*" is printed in a style similar to od. This config value has not meaning if "blkfmt" is "str". The default value for "blkverbose" is FALSE: duplicate lines are not printed. The "blkbase" determines the base in which octets of a block are printed. Possible values are: "hexadecimal" Octets printed in 2 digit hex "hex" "octal" Octets printed in 3 digit octal "oct" "character" Octets printed as chars with non-printing "char" chars as \123 or \n, \t, \r "binary" Octets printed as 0 or 1 chars "bin" "raw" Octets printed as is, i.e. raw binary "none" The default "blkbase" is "hex". The "blkfmt" determines for format of how block are printed: "line" print in lines of up to 79 chars + newline "lines" "str" print as one long string "string" "strings" "od" print in od-like format, with leading offset, "odstyle" followed by octets in the given base "od_style" "hd" print in hex dump format, with leading offset, "hdstyle" followed by octets in the given base, followed "hd_style" by chars or '.' if no-printable or blank The default "blkfmt" is "hd". The "calc_debug" is intended for controlling internal calc routines that test its operation, or collect or display information that might be useful for debug purposes. Much of the output from these will make sense only to calc wizards. Zero value (the default for both oldstd and newstd) of config("lib_calc") corresponds to switching off all these routines. For nonzero value, particular bits currently have the following meanings: n Meaning of bit n of config("calc_debug") 0 outputs shell commands prior to execution 1 outputs currently active functions when a quit instruction is executed 2 some details of shs, shs1 and md5 hash states are included in the output when these are printed 3 when a function constructs a block value, tests are made that the result has the properties required for use of that block, e.g. that the pointer to the start of the block is not NULL, and that its "length" is not negative. A failure will result in a runtime error. 4 Report on changes to the state of stdin as well as changes to internal variables that control the setting and restoring of stdin. 5 Report on changes to the run state of calc. Bits >= 6 are reserved for future use and should not be used at this time. By default, "calc_debug" is 0. The initial value may be overridden by the -D command line option. The "lib_debug" parameter is intended for controlling the possible display of special information relating to functions, objects, and other structures created by instructions in calc scripts. Zero value of config("lib_debug") means that no such information is displayed. For other values, the non-zero bits which currently have meanings are as follows: n Meaning of bit n of config("lib_debug") 0 When a function is defined, redefined or undefined at interactive level, a message saying what has been done is displayed. 1 When a function is defined, redefined or undefined during the reading of a file, a message saying what has been done is displayed. The value for config("lib_debug") in both oldstd and newstd is 3, but if calc is invoked with the -d flag, its initial value is zero. Thus, if calc is started without the -d flag, until config("lib_debug") is changed, a message will be output when a function is defined either interactively or during the reading of a file. By default, "lib_debug" is 3. The -d flag changes this default to 0. The initial value may be overridden by the -D command line option. The "user_debug" is provided for use by users. Calc ignores this value other than to set it to 0 by default (for both "oldstd" and "newstd"). No calc code or shipped library should change this value. Users should feel free to use it in any way. In particular they may use particular bits for special purposes as with "calc_debug", or they may use it to indicate a debug level with larger values indicating more stringent and more informative tests with presumably slower operation or more memory usage, and a particular value (like -1 or 0) corresponding to "no tests". By default, "user_debug" is 0. The initial value may be overridden by the -D command line option. The "verbose_quit" controls the print of the message: Quit or abort executed when a non-interactive quit or abort without an argument is encounted. A quit of abort without an argument does not display a message when invoked at the interactive level. The following are synonyms for true: "on" "yes" "y" "true" "t" "1" any non-zero number The following are synonyms for false: "off" "no" "n" "false" "f" "0" the number zero (0) Examples of setting some parameters are: config("mode", "exp"); exponential output config("display", 50); 50 digits of output epsilon(epsilon() / 8); 3 bits more accuracy config("tilde", 0) disable roundoff tilde printing config("tab", "off") disable leading tab printing