calc: Prefix Arguments
4.7 Numeric Prefix Arguments
============================
Many Calculator commands use numeric prefix arguments. Some, such as ‘d
s’ (‘calc-sci-notation’), set a parameter to the value of the prefix
argument or use a default if you don’t use a prefix. Others (like ‘d f’
(‘calc-fix-notation’)) require an argument and prompt for a number if
you don’t give one as a prefix.
As a rule, stack-manipulation commands accept a numeric prefix
argument which is interpreted as an index into the stack. A positive
argument operates on the top N stack entries; a negative argument
operates on the Nth stack entry in isolation; and a zero argument
operates on the entire stack.
Most commands that perform computations (such as the arithmetic and
scientific functions) accept a numeric prefix argument that allows the
operation to be applied across many stack elements. For unary
operations (that is, functions of one argument like absolute value or
complex conjugate), a positive prefix argument applies that function to
the top N stack entries simultaneously, and a negative argument applies
it to the Nth stack entry only. For binary operations (functions of two
arguments like addition, GCD, and vector concatenation), a positive
prefix argument “reduces” the function across the top N stack elements
(for example, ‘C-u 5 +’ sums the top 5 stack entries; Reducing and
Mapping), and a negative argument maps the next-to-top N stack
elements with the top stack element as a second argument (for example,
‘7 c-u -5 +’ adds 7 to the top 5 stack elements). This feature is not
available for operations which use the numeric prefix argument for some
other purpose.
Numeric prefixes are specified the same way as always in Emacs: Press
a sequence of <META>-digits, or press <ESC> followed by digits, or press
‘C-u’ followed by digits. Some commands treat plain ‘C-u’ (without any
actual digits) specially.
You can type ‘~’ (‘calc-num-prefix’) to pop an integer from the top
of the stack and enter it as the numeric prefix for the next command.
For example, ‘C-u 16 p’ sets the precision to 16 digits; an alternate
(silly) way to do this would be ‘2 <RET> 4 ^ ~ p’, i.e., compute 2 to
the fourth power and set the precision to that value.
Conversely, if you have typed a numeric prefix argument the ‘~’ key
pushes it onto the stack in the form of an integer.