calc(1)

NAME
calc - arbitrary precision calculator

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

DESCRIPTION
CALC COMMAND LINE

-h  Print a help message. This option implies -q. This is equivalent to the calc command help help.

-q  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

OVERVIEW

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.

Calc comes with a rich set of builtin mathematical and programmatic functions.

Calc is distributed with library of scripts. Written in the same C-like language, library scripts may be read in and executed during a calc session. These library scripts are also provided because they are useful and to serve as examples of the calc language. One may further extend calc thru the use of user defined scripts.

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

DATA TYPES

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

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

The scope of a variable may be global, local to a file, or 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

INPUT/OUTPUT

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:

~/.calcrc
~chongo/lib/fft_multiply.cal

For more information use the following calc command:

help file

CALC LANGUAGE

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

FILES
${LIBDIR}/*.cal
    library scripts shipped with calc

${LIBDIR}/help/*
    help files

${LIBDIR}/bindings
    command line editor bindings

ENVIRONMENT
CALCPATH
    A :-separated list of directories used to search for scripts filenames that do not begin with /, ./ or ~.

    Default value: .:./lib:~/lib:${LIBDIR}

CALCRC
    On startup (unless -h or -q was given on the command line), calc searches for files along this :-separated environment variable.

    Default value: ${LIBDIR}/startup:~/.calcrc

CALCBINDINGS
    On startup (unless -h or -q was given on the command line), calc reads key bindings from the filename specified by this environment variable.

    Default value: ${LIBDIR}/bindings

CREDIT
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) 1994 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:

dbell@auug.org.au
chongo@toad.com

Enjoy!