Go to the previous, next section.

Introduction

This chapter is the beginning of the Calc reference manual. It covers basic concepts such as the stack, algebraic and numeric entry, undo, numeric prefix arguments, etc.

Basic Commands

To start the Calculator in its standard interface, type M-x calc. By default this creates a pair of small windows, `*Calculator*' and `*Calc Trail*'. The former displays the contents of the Calculator stack and is manipulated exclusively through Calc commands. It is possible (though not usually necessary) to create several Calc Mode buffers each of which has an independent stack, undo list, and mode settings. There is exactly one Calc Trail buffer; it records a list of the results of all calculations that have been done. The Calc Trail buffer uses a variant of Calc Mode, so Calculator commands still work when the trail buffer's window is selected. It is possible to turn the trail window off, but the `*Calc Trail*' buffer itself still exists and is updated silently. See section Trail Commands.

In most installations, the M-# c key sequence is a more convenient way to start the Calculator. Also, M-# M-# and M-# # are synonyms for M-# c unless you last used Calc in its "keypad" mode.

Most Calc commands use one or two keystrokes. Lower- and upper-case letters are distinct. Commands may also be entered in full M-x form; for some commands this is the only form. As a convenience, the x key (calc-execute-extended-command) is like M-x except that it enters the initial string `calc-' for you. For example, the following key sequences are equivalent: S, M-x calc-sin RET, x sin RET.

The Calculator exists in many parts. When you type M-# c, the Emacs "auto-load" mechanism will bring in only the first part, which contains the basic arithmetic functions. The other parts will be auto-loaded the first time you use the more advanced commands like trig functions or matrix operations. This is done to improve the response time of the Calculator in the common case when all you need to do is a little arithmetic. If for some reason the Calculator fails to load an extension module automatically, you can force it to load all the extensions by using the M-# L (calc-load-everything) command. See section Mode Settings.

If you type M-x calc or M-# c with any numeric prefix argument, the Calculator is loaded if necessary, but it is not actually started. If the argument is positive, the `calc-ext' extensions are also loaded if necessary. User-written Lisp code that wishes to make use of Calc's arithmetic routines can use `(calc 0)' or `(calc 1)' to auto-load the Calculator.

If you type M-# b, then next time you use M-# c you will get a Calculator that uses the full height of the Emacs screen. When full-screen mode is on, M-# c runs the full-calc command instead of calc. From the Unix shell you can type `emacs -f full-calc' to start a new Emacs specifically for use as a calculator. When Calc is started from the Emacs command line like this, Calc's normal "quit" commands actually quit Emacs itself.

The M-# o command is like M-# c except that the Calc window is not actually selected. If you are already in the Calc window, M-# o switches you out of it. (The regular Emacs C-x o command would also work for this, but it has a tendency to drop you into the Calc Trail window instead, which M-# o takes care not to do.)

For one quick calculation, you can type M-# q (quick-calc) which prompts you for a formula (like `2+3/4'). The result is displayed at the bottom of the Emacs screen without ever creating any special Calculator windows. See section "Quick Calculator" Mode.

Finally, if you are using the X window system you may want to try M-# k (calc-keypad) which runs Calc with a "calculator keypad" picture as well as a stack display. Click on the keys with the mouse to operate the calculator. See section "Keypad" Mode.

The q key (calc-quit) exits Calc Mode and closes the Calculator's window(s). It does not delete the Calculator buffers. If you type M-x calc again, the Calculator will reappear with the contents of the stack intact. Typing M-# c or M-# M-# again from inside the Calculator buffer is equivalent to executing calc-quit; you can think of M-# M-# as toggling the Calculator on and off.

The M-# x command also turns the Calculator off, no matter which user interface (standard, Keypad, or Embedded) is currently active. It also cancels calc-edit mode if used from there.

The d SPC key sequence (calc-refresh) redraws the contents of the Calculator buffer from memory. Use this if the contents of the buffer have been damaged somehow.

The o key (calc-realign) moves the cursor back to its "home" position at the bottom of the Calculator buffer.

The < and > keys are bound to calc-scroll-left and calc-scroll-right. These are just like the normal horizontal scrolling commands except that they scroll one half-screen at a time by default. (Calc formats its output to fit within the bounds of the window whenever it can.)

The { and } keys are bound to calc-scroll-down and calc-scroll-up. They scroll up or down by one-half the height of the Calc window.

The M-# 0 command (calc-reset; that's M-# followed by a zero) resets the Calculator to its default state. This clears the stack, resets all the modes, clears the caches (see section Caches), and so on. (It does not erase the values of any variables.) With a numeric prefix argument, M-# 0 preserves the contents of the stack but resets everything else.

The M-x calc-version command displays the current version number of Calc and the name of the person who installed it on your system. (This information is also present in the `*Calc Trail*' buffer, and in the output of the h h command.)

Help Commands

The ? key (calc-help) displays a series of brief help messages. Some keys (such as b and d) are prefix keys, like Emacs' ESC and C-x prefixes. You can type ? after a prefix to see a list of commands beginning with that prefix. (If the message includes `[MORE]', press ? again to see additional commands for that prefix.)

The h h (calc-full-help) command displays all the ? responses at once. When printed, this makes a nice, compact (three pages) summary of Calc keystrokes.

In general, the h key prefix introduces various commands that provide help within Calc. Many of the h key functions are Calc-specific analogues to the C-h functions for Emacs help.

The h i (calc-info) command runs the Emacs Info system to read this manual on-line. This is basically the same as typing C-h i (the regular way to run the Info system), then, if Info is not already in the Calc manual, selecting the beginning of the manual. The M-# i command is another way to read the Calc manual; it is different from h i in that it works any time, not just inside Calc. The plain i key is also equivalent to h i, though this key is obsolete and may be replaced with a different command in a future version of Calc.

The h t (calc-tutorial) command runs the Info system on the Tutorial section of the Calc manual. It is like h i, except that it selects the starting node of the tutorial rather than the beginning of the whole manual. (It actually selects the node "Interactive Tutorial" which tells a few things about using the Info system before going on to the actual tutorial.) The M-# t key is equivalent to h t (but it works at all times).

The h s (calc-info-summary) command runs the Info system on the Summary node of the Calc manual. See section Calc Summary. The M-# s key is equivalent to h s.

The h k (calc-describe-key) command looks up a key sequence in the Calc manual. For example, h k H a S looks up the documentation on the H a S (calc-solve-for) command. This works by looking up the textual description of the key(s) in the Key Index of the manual, then jumping to the node indicated by the index.

Most Calc commands do not have traditional Emacs documentation strings, since the h k command is both more convenient and more instructive. This means the regular Emacs C-h k (describe-key) command will not be useful for Calc keystrokes.

The h c (calc-describe-key-briefly) command reads a key sequence and displays a brief one-line description of it at the bottom of the screen. It looks for the key sequence in the Summary node of the Calc manual; if it doesn't find the sequence there, it acts just like its regular Emacs counterpart C-h c (describe-key-briefly). For example, h c H a S gives the description:

H a S runs calc-solve-for:  a `H a S' v  => fsolve(a,v)  (?=notes)

which means the command H a S or H M-x calc-solve-for takes a value a from the stack, prompts for a value v, then applies the algebraic function fsolve to these values. The `?=notes' message means you can now type ? to see additional notes from the summary that apply to this command.

The h f (calc-describe-function) command looks up an algebraic function or a command name in the Calc manual. The prompt initially contains `calcFunc-'; follow this with an algebraic function name to look up that function in the Function Index. Or, backspace and enter a command name beginning with `calc-' to look it up in the Command Index. This command will also look up operator symbols that can appear in algebraic formulas, like `%' and `=>'.

The h v (calc-describe-variable) command looks up a variable in the Calc manual. The prompt initially contains the `var-' prefix; just add a variable name like pi or PlotRejects.

The h b (calc-describe-bindings) command is just like C-h b, except that only local (Calc-related) key bindings are listed.

The h n or h C-n (calc-view-news) command displays the "news" or change history of Calc. This is kept in the file `README', which Calc looks for in the same directory as the Calc source files.

The h C-c, h C-d, and h C-w keys display copying, distribution, and warranty information about Calc. These work by pulling up the appropriate parts of the "Copying" or "Reporting Bugs" sections of the manual.

Stack Basics

Calc uses RPN notation. If you are not familar with RPN, see section RPN Calculations and the Stack.

To add the numbers 1 and 2 in Calc you would type the keys: 1 RET 2 +. (RET corresponds to the ENTER key on most calculators.) The first three keystrokes "push" the numbers 1 and 2 onto the stack. The + key always "pops" the top two numbers from the stack, adds them, and pushes the result (3) back onto the stack. This number is ready for further calculations: 5 - pushes 5 onto the stack, then pops the 3 and 5, subtracts them, and pushes the result (-2).

Note that the "top" of the stack actually appears at the bottom of the buffer. A line containing a single `.' character signifies the end of the buffer; Calculator commands operate on the number(s) directly above this line. The d t (calc-truncate-stack) command allows you to move the `.' marker up and down in the stack; see section Truncating the Stack.

Stack elements are numbered consecutively, with number 1 being the top of the stack. These line numbers are ordinarily displayed on the lefthand side of the window. The d l (calc-line-numbering) command controls whether these numbers appear. (Line numbers may be turned off since they slow the Calculator down a bit and also clutter the display.)

The unshifted letter o (calc-realign) command repositions the cursor to its top-of-stack "home" position. It also undoes any horizontal scrolling in the window. If you give it a numeric prefix argument, it instead moves the cursor to the specified stack element.

The RET (or equivalent SPC) key is only required to separate two consecutive numbers. (After all, if you typed 1 2 by themselves the Calculator would enter the number 12.) If you press RET or SPC not right after typing a number, the key duplicates the number on the top of the stack. RET * is thus a handy way to square a number.

The DEL key pops and throws away the top number on the stack. The TAB key swaps the top two objects on the stack. See section Stack and Trail Commands, for descriptions of these and other stack-related commands.

Numeric Entry

Pressing a digit or other numeric key begins numeric entry using the minibuffer. The number is pushed on the stack when you press the RET or SPC keys. If you press any other non-numeric key, the number is pushed onto the stack and the appropriate operation is performed. If you press a numeric key which is not valid, the key is ignored.

There are three different concepts corresponding to the word "minus," typified by a-b (subtraction), -x (change-sign), and -5 (negative number). Calc uses three different keys for these operations, respectively: -, n, and _ (the underscore). The - key subtracts the two numbers on the top of the stack. The n key changes the sign of the number on the top of the stack or the number currently being entered. The _ key begins entry of a negative number or changes the sign of the number currently being entered. The following sequences all enter the number -5 onto the stack: 0 RET 5 -, 5 n RET, 5 RET n, _ 5 RET, 5 _ RET.

Some other keys are active during numeric entry, such as # for non-decimal numbers, : for fractions, and @ for HMS forms. These notations are described later in this manual with the corresponding data types. See section Data Types.

During numeric entrer -5 onto the stack: 0 RET 5 -, 5 n RET, 5 RET n, _ 5 RET, 5 _ RET.

Some other keys are active during numeric entry, such as # for non-decimal numbers, : for fractions, and @ for HMS forms. These notations are described later in this manual with the corresponding data types. See section Data Types.

During numeric entr