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
	    "lib_debug"		calc library script debug level
	    "calc_debug"	internal calc debug level
	    "user_debug"	user defined debug level


    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.

    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 is 20.  This parameter does not change
    the stored value of a number.  Where rounding is necessary, the type
    of rounding to be used is controlled by "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 epsilon(v) as well as by config("epsilon", v), and the
    current value obtained by epsilon() as well as by config("epsilon").)
    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".

    With regards to "lib_debug", "calc_debug" and "user_debug":
    higher absolute values result in more detailed debugging and
    more verbose debug messages.  The default value is 0 in which
    a very amount of debugging will be performed with nil messages.
    The -1 value is reserved for no debugging or messages.  Any
    value <-1 will perform debugging silently (presumably collecting
    data to be displayed at a later time).  Values >0 result in a
    greater degree of debugging and more verbose messages.

    The "lib_debug" is reserved by convention for calc library scripts.
    This config parameter takes the place of the lib_debug global variable.
    By convention, "lib_debug" has the following meanings:

	<-1	no debug messages are printed though some internal
		    debug actions and information may be collected

	-1	no debug messages are printed, no debug actions will be taken

	0	only usage message regarding each important object are
		    printed at the time of the read (default)

	>0	messages regarding each important object are
		    printed at the time of the read in addition
		    to other debug messages

    The "calc_debug" is reserved by convention for internal calc routines.
    The output of "calc_debug" will change from release to release.
    Generally this value is used by calc wizards and by the regress.cal
    routine (make check).  By convention, "calc_debug" has the following
    meanings:

	<-1	reserved for future use

	-1	no debug messages are printed, no debug actions will be taken

	0	very little, if any debugging is performed (and then mostly
		    in alpha test code).  The only output is as a result of
		    internal fatal errors (typically either math_error() or
		    exit() will be called). (default)

	>0	a greater degree of debugging is performed and more
		    verbose messages are printed (regress.cal uses 1).

    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 will change this value other than
    during startup or during a config("all", xyz) call.

    The following is suggested as a convention for use of "user_debug".
    These are only suggestions: feel free to use it as you like:

	<-1	no debug messages are printed though some internal
		    debug actions and information may be collected

	-1	no debug messages are printed, no debug actions will be taken

	0	very little, if any debugging is performed.  The only output
		    are from fatal errors. (default)

	>0	a greater degree of debugging is performed and more
		    verbose messages are printed

    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
