Calc review

by on

Calc is arbitrary precision arithmetic system that uses a C-like language

License: LGPL (GNU Lesser General Public License)
File size: 1184K
Developer: Landon Curt Noll
0 stars award from

Calc is arbitrary precision arithmetic system that uses a C-like language. Calc is useful as a calculator, an algorithm prototype, and as a mathematical research tool.

More importantly, calc provides a machine-independent means of computation. Calc comes with a rich set of builtin mathematical and programmatic functions.

For example, the following line can be input:

3 * (4 + 1)

and the calculator will print:


Calc as the usual collection of arithmetic operators +, -, /, * as well as ^ exponentiation), % (modulus) and // (integer divide). For example:

3 * 19^43 - 1

will produce:


Notice that calc values can be very large. For example:


will print:

402874115778988778181873329071 ... many digits ... 3779264511

The special '.' symbol (called dot), represents the result of the last command expression, if any. This is of great use when a series of partial results are calculated, or when the output mode is changed and the last result needs to be redisplayed. For example, the above result can be modified by typing:

. % (2^127-1)

and the calculator will print:

For more complex calculations, variables can be used to save the intermediate results. For example, the result of adding 7 to the previous result can be saved by typing:

curds = 15
whey = 7 + 2*curds

Functions can be used in expressions. There are a great number of pre-defined functions. For example, the following will calculate the factorial of the value of 'old':

and the calculator prints:


The calculator also knows about complex numbers, so that typing:

(2+3i) * (4-3i)

will print:


The calculator can calculate transcendental functions, and accept and display numbers in real or exponential format. For example, typing:

config("display", 70)



Calc can output values in terms of fractions, octal or hexadecimal. For example:

config("mode", "fraction"),

will print:


All numbers are represented as fractions with arbitrarily large numerators and denominators which are always reduced to lowest terms. Real or exponential format numbers can be input and are converted to the equivalent fraction. Hex, binary, or octal numbers can be input by using numbers with leading '0x', '0b' or '0' characters.

Complex numbers can be input using a trailing 'i', as in '2+3i'. Strings and characters are input by using single or double quotes.

Commands are statements in a C-like language, where each input line is treated as the body of a procedure. Thus the command line can contain variable declarations, expressions, labels, conditional tests, and loops. Assignments to any variable name will automatically define that name as a global variable.

The other important thing to know is that all non-assignment expressions which are evaluated are automatically printed. Thus, you can evaluate an expression's value by simply typing it in.

Many useful built-in mathematical functions are available. Use the:

help builtin

command to list them.

You can also define your own functions by using the 'define' keyword, followed by a function declaration very similar to C.

define f2(n)
local ans;

ans = 1;
while (n > 1)
ans *= (n -= 2);
return ans;

Thus the input:


will produce;


Functions which only need to return a simple expression can be defined using an equals sign, as in the example:
define sc(a,b) = a^3 + b^3

Thus the input:

sc(31, 61)

will produce;


Variables in functions can be defined as either 'global', 'local', or 'static'. Global variables are common to all functions and the command line, whereas local variables are unique to each function level, and are destroyed when the function returns.

Static variables are scoped within single input files, or within functions, and are never destroyed. Variables are not typed at definition time, but dynamically change as they are used.

What's New in This Release:
This is a very minor update release to allow OpenBSD-like make parsers to compile the source.
This is also a minor release to fix an issue under Mac OS X where the make chk (and make check) regression awk script did not run correctly under Mac OS X 10.4.7.
A few minor variables that were not set to default values in lower level Makefiles was fixed.

Calc search tags