calc
2.12.7.2
About: Calc is a C-style arbitrary precision calculator.
Fossies Dox: calc-2.12.7.2.tar.bz2 ("inofficial" and yet experimental doxygen-generated source code documentation) |

calc Documentation

- To see the Doxygen generated documentation please click on one of the items in the steelblue colored "quick index" bar above or use the side panel at the left which displays a hierarchical tree-like index structure and is adjustable in width.
- If you want to search for something by keyword rather than browse for it you can use the client side search facility (using Javascript and DHTML) that provides live searching, i.e. the search results are presented and adapted as you type in the Search input field at the top right.
- Doxygen doesn't incorporate all member files but just a definable subset (basically the main project source code files that are written in a supported language). So to search and browse all member files you may visit the Fossies calc-2.12.7.2.tar.bz2 contents page and use the Fossies standard member browsing features (also with source code highlighting and additionally with optional code folding).

README.md

Calc is an interactive calculator which provides for easy large Otherwise, it enters interactive mode. In this mode, it accepts commands one at a time, processes them, and displays the answers. In the simplest case, commands are simply expressions which are evaluated. For example, the following line can be input:

and the calculator will print:

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

will produce:

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

will print:

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:

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:

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 'whey':

and the calculator prints:

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

will print:

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

prints:

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

will print:

```
19967568900859523802559065713/257829627945307727248226067259
0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1
0x17b5164ac24ee836bf/0xc7b7a8e3ef5fcf752+0x883eaf5adadd26be3/0xc7b7a8e3ef5fcf752i
```

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:

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.

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:

Thus the input:

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.

For more information about the calc language and features, try:

Calc has a help command that will produce information about every builtin function, command as well as a number of other aspects of calc usage. Try the command:

for and overview of the help system. The command:

provides information on built-in mathematical functions, whereas:

will provides information a specific function. The following help files:

provide a good overview of the calc language. If you are familiar with C, you should also try:

It contains information about differences between C and calc that may surprize C programmers.