mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.10.2t30
This commit is contained in:
267
help/config
Normal file
267
help/config
Normal file
@@ -0,0 +1,267 @@
|
||||
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
|
||||
"maxerr" maximum number of scan errors before abort
|
||||
"prompt" default interactive prompt
|
||||
"more" default interactive multi-line input prompt
|
||||
|
||||
|
||||
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.
|
||||
|
||||
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 inital
|
||||
"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 maxerr value controls how many scan errors are allowed
|
||||
before the compiling phase of a computation is aborted. The initial
|
||||
value of "maxerr" is 20. Setting maxerr to 0 disables this feature.
|
||||
|
||||
The default prompt when in teractive 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 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
|
Reference in New Issue
Block a user