HTML automatically generated with rman
Table of Contents


calc - arbitrary precision calculator


calc [ -h ] [ -q ] [ calc_cmd ... ]



Print a help message. This option implies -q. This is equivalent to the calc command help help.
Disable the use of the $CALCRC startup library scripts.

Without calc_cmds, calc operates interactively. If one or more calc_cmds are given on the command line, calc will execute them and exit.

Normally on startup, calc attempts to execute a collection of library scripts. The environment variable $CALCRC (if non-existent then a compiled in value) contains a : separated list of startup library scripts. No error conditions are produced if these startup library scripts are not found.

Filenames are subject to ‘‘~’’ expansion (see below). The environment variable $CALCPATH (if non-existent then a compiled in value) contains a : separated list of search directories. If a file does not begin with /, ~ or ./, then it is searched for under each directory listed in the $CALCPATH. It is an error if no such readable file is found.

For more information use the following calc commands:

help usage
help help
help environment


Calc is arbitrary precision arithmetic system that uses a C-like language. Calc is useful as a calculator, an algorithm prototyped and as a mathematical research tool. More importantly, calc provides one with a machine independent means of computation.

A rich set of builtin functions is provided. A number of library scripts are also provided because they are useful and to serve as examples of the calc language.

One may further extend calc permits further thru to use of calc library scripts. Written in the same C-like language, library scripts may be read in and executed during a calc session.

Internally calc represents numeric values as fractions reduced to their lowest terms. The numerators and denominators of these factions may grow to arbitrarily large values. Numeric values read in are automatically converted into rationals. The user need not be aware of this internal representation.

For more information use the following calc commands:

help intro
help builtin
help stdlib
help define
show builtins
show functions


Fundamental builtin data types include integers, real numbers, rational numbers, complex numbers and strings.

By use of an object, one may define an arbitrarily complex data types. One may define how such objects behave a wide range of operations such as addition, subtraction, multiplication, division, negation, squaring, modulus, rounding, exponentiation, equality, comparison, printing and so on.

For more information use the following calc commands:

help types
help obj
show objfuncs


Variables in calc are typeless. In other words, the fundamental type of a variable is determined by its content. Before variable is assigned a value is of type ‘‘null’’.

The scope of a variable may be global, or only a local to a procedure. Values may be grouped together in a matrix, or into a a list that permits stack and queue style operations.

For more information use the following calc commands:

help variable
help mat
help list
show globals


A leading ‘‘0x’’ implies a hexadecimal value, a leading ‘‘0b’’ implies a binary value, and a ‘‘0’’ followed by a digit implies an octal value. Complex numbers are indicated by a trailing ‘‘i’’ such as in ‘‘3+4i’’. Strings may be delimited by either a pair of single or double quotes. By default, calc prints values as if they were floating point numbers. One may change the default to print values in a number of modes including fractions, integers and exponentials.

A number of stdio-like file I/O operations are provided. One may open, read, write, seek and close files. Filenames are subject to ‘‘~’’ expansion to home directories in a way similar to that of the Korn or C-Shell.

For example:


For more information use the following calc command:

help file


The calc language is a C-like language. The language includes commands such as variable declarations, expressions, tests, labels, loops, file operations, function calls. These commands are very similar to their counterparts in C.

The language also include a number of commands particular to calc itself. These include commands such as function definition, help, reading in library scripts, dump files to a file, error notification, configuration control and status.

For more information use the following calc command:

help command
help statement
help expression
help operator
help config


library scripts shipped with calc

help files

Typically ${LIBDIR} is /usr/local/lib/calc


Written by David I. Bell.

Thanks for suggestions and encouragement from Peter Miller, Neil Justusson, and Landon Noll.

Portions of this program are derived from an earlier set of public domain arbitrarily precision routines which was posted to the net around 1984. By now, there is almost no recognizable code left from that original source.

Most of this source and binary is:

Copyright (c) 1992 David I. Bell

Some files are a copyrighted David I. Bell and Landon Noll.

Permission is granted to use, distribute, or modify this source, provided that this copyright notice remains intact.

Send calc comments, suggestions, bug fixes, enhancements and interesting calc scripts that you would like you see included in future distributions to:  and


Table of Contents