To run calc, just enter calc at your shell prompt. You'll see
the > prompt. You can now enter commands. For example,
enter 2 3 +. You should see the result (5) followed by
another prompt. The entire session would look like this:
$ calc
calc v2.0.0, Copyright (C) 1999 Eduardo M Kalinowski (ekalin@iname.com)
This program comes with ABSOLUTELY NO WARRANTY. See COPYING file for details.
> 2 3 +
[ 1] 5
>
The calculator is ready to receive more commands. For example, let us
divide the result of the previous calculation by 3. Just enter 3
/. The result is shown.
When you are done, enter q or quit to quit.
calc uses Reverse Polish Notation (or RPN for short). Although strange at first, RPN is much easier to use than the normal notation, especially for long calculations.
In RPN, the operators (ie, +, -, sin, etc) come after the operands. So, the expressin ``(5 + 2) / 3'' would be written as ``5 2 + 3 /''. The order of evaluation is always from left to right, and parenthesis are never necessary.
The results of the calculations are put in a stack. Its operation is like a pile of plates. The piles are put at the top of the pile, and taken from the top of the pile. Thus, the first plat put on the pile is the last one to be taken.
In RPN calculators, the stack is upside down, that is, the numbers are
put at the bottom (and so taken from the botton.) To put a number in
calc's stack, just enter the number at the > prompt.
By default, only the first four levels of the stack are shown (this
can be changed, see the section
Command-Line Arguments.) If you want to see the more of stack, use the =
command (see
The = command.
By default, the stack can hold up to 25 items. If you think you need
more (which is unlikely) you can change this limit. See the
INSTALL file for instructions.
Starting at version 2.0.0, there is support for complex numbers. To enter a complex number, use the following syntax:
> (x, y)
Where x is the real part and y is the imaginary part. You may omit the space or the comma separing the real and imaginary parts, but not both.
Executing operations on complex numbers is the same as in real
numbers. Just put the operands in the stack and enter the command,
such as + or cosh.
Complex numbers can also be entered and/or displayed in polar form. To enter a number in polar form, do like this:
> (r, <theta)
Where r is the magnitude and theta the angle. You may omit the space and the comma if you wish.
When complex numbers are displayed in polar form, they are shown with a similar syntax. Too configure calc to display numbers in polar form, see section Coordinate Mode.
The current angle mode (degrees or radians) is taken in consideration when entering and displaying complex numbers. See section Angle Mode for information on changing the angle mode.
Provided your system supports it, calc has support for non-stop calculations. This means you'll never get an error while you're doing your calculations, except if you do not enter enough arguments or if you mistake the argument type. But you'll not get an error for dividing 1 by 0, or even 0 by 0.
To achieve this, two concepts are important: Inf and NaN. You'll get Inf as a result whenever you run a function which an argument that would result in a very large result, such as 1e300 * 1e300, or 2 divided by 0. You can read "Inf" as infinity, and that's what it means. Its complement is -Inf, which is negative infinity.
The other concept is NaN (short for Not-a-number). You get this result when the result of a function you called is undefined, such as 0/0, Inf-Inf, and so on.
If you want to get one of this values in the stack, you can just use
the commands inf, -inf and nan.
The most basic way to enter commands (and seldom used) is to enter one command at a time, each on its only line. However, it is easier to enter more than one command in each line. Separate each command with a space. Numbers should also be separated from commands and from other numbers with spaces.
If you just press <ENTER> without entering any command, the
stack will be shown.
Case is irrelevant when entering commands, so ``dup'' is the same
as ``DUP''.
This program uses the GNU Readline Library. This allows you to edit the commands you've entered as if you were using a text editor. For more information, see Using Readline.
calc accepts some command line options. The invocation form of calc is:
calc [-d n] [-b] [-s] [-m] [--] [commands]
or: calc --help | --version
The -d option must be followed by a numeric argument. It
specified how many lines of the stack will be shown by default. If
this option is not present, four is assumed. To make the whole stack
be displayed all times, use -1 as argument. Note that if you use
-d 0 no stack will be shown.
If there is a number in the command line specifying the number of elements to display, it overrides the number saved in the configuration file (see The configuration file).
The -s option tells calc not to load the stack from its
configuration file (see
The configuration file).
The -m option tells calc not to load the memory from its
configuration file (see
The configuration file).
The -b run calc in batch mode, that is, the calculator
immediately exits after processing the commands given in the command
line. If no commands are given in the command line, it just prints the
copyright message and exits.
The --help option displays a help message with the command line
options and then exits successfully. The --version option
displays version information and exits successfully.
You can enter commands on the command line to be executed as if they
were entered at the prompt. However, if you try to enter a negative
number or the - command, it will be mistakenly taken as an
option, and you'll get undesirable results. To avoid this problem, put
-- before the commands. This tell calc to process all
arguments after it as commands.
At any time, you can enter the help command at the prompt to
get help. Without arguments, it displays a list of commands. To get
help on a specific command, enter help followed by the command's
name, for example help sin.