Post · 2 min read· pp. 1269–1270

Emacs calculator

Emacs has quite a sophisticated scientific calculator. Like many other things in Emacs, it is both powerful and idiosyncratic.

The calc module ships with Emacs as of version 22. The calc manual has full documentation, but it takes some work to understand. This post may make it easier to read the manual.

The manual says you can start calc with the command M-#. That did not work for me, but the command M-x calc did.

Calc has two modes: RPN (reverse Polish notation) and algebraic. RPN is the default mode and uses very terse commands, often one or two letters. Most people will find the algebraic mode syntax more familiar. Commands in algebraic mode begin with a quote and use longer, more descriptive names.

For example, suppose you want to find the cosine of 5. You can do this in RPN mode by typing 5 and pressing return, then typing shift-C. To do the same calculation in algebraic mode, type 'cos(5) and return.

I’ll step through to gamma function documentation as an example of how to interpret the manual. It says

The f g (calc-gamma) [gamma] command computes the Euler gamma function. …

This means that in RPN mode, you enter the argument of the gamma function, say 5, and then type fg. (Not f g as you might expect.) You could also enter 5 and then type M-x calc-gamma. In algebraic mode, the syntax would be 'gamma(5). So the pattern in the manual is

RPN keystrokes (lisp function) [algebraic syntax].

The calc module has an amazing range of functionality — symbolic calculation, matrix operations, graphics, etc. — though I don’t imagine I’d use much of it. In my mind, the benefit of calc is being able to do a quick calculation without leaving Emacs. Although one could do sophisticated calculations in calc, I doubt I would for two reasons. First, if I have to look up how to do something in calc, I lose the benefit of not interrupting my workflow. Second, I don’t want to start a computation in calc and then discover I need something that isn’t there and then have to switch to another tool such as SciPy, Mathematica, or R.