Quick Navigator

 Search Site Miscellaneous Server Agreement Year 2038 Credits

# Manual Reference Pages  -  SPAR (1)

### NAME

spar - a modular console calculator

### CONTENTS

Synopsis
Description
Options
Numbers
Variables
Constants
Functions
Trig Functions
Inverse Trig Functions
Exponents and Logarithms
Hyperbolic Functions
Inverse Hyperbolic Functions
Infinite Functions
Special Functions
Expressions
Commands
Features
Signals Support
Termcap Support
Bugs
Files
Author
Acknowledgments

### SYNOPSIS

```spar [options] [--] expression

```

### DESCRIPTION

Spar is a console calculator, primarily intended for problem solving in arbitrary precision. It supports also modules (aka code that can be loaded dynamically) and a number of other features, such as: user variables, functions, and constants.

#### OPTIONS

 -d, --decimals Set the decimal precision (number of digits printed after the point). -i, --integers Set the integer precision (number of digits printed before the point). -c, --config Use a user-defined modules configuration file. -q, --quiet Don’t display the welcome message. -h, --help Display usage information and exit. -v, --version Print version information and exit. -- Terminate option list: now all arguments is interpreted as an expression to evaluate.

### NUMBERS

The most basic element in spar is the number. Numbers are double precision numbers. All numbers are represented internally as a standard C double variable. There are no attributes of numbers, but the precision can affect the number output. This precision is both in the integer part and the decimal part.

For example: The number 0.123456789 is represented internally as a double precision variable, but if we change the precision, the output will change: 0.123456789 = 0.123457

### VARIABLES

Numbers can be stored in named variables. Variable names begin with a letter followed by any number of letters, digits and underscores. The variable names are case sensitive. Variables may have values assigned to them as well as used in expressions and it contains a special data member that stores the "previous" value".

To declare a variable you must supply both a name and a value. Any undeclared variable generate an error. For example, to declare the variable i of value 5 enter:

```

i = 5

```

### CONSTANTS

Constants are special variables that is read-only. This means that you can read a constant value but you can modify. There is a number of "preloaded" variables such as "e", "pi" ecc.

### FUNCTIONS

spar support a number of often used scientific functions (directly from The Spar Library). For example, to get the value of the natural logarithm in 0 enter:
```

log(0)

```

#### Trig Functions

These are the familiar ‘sin’, ‘cos’, and ‘tan’ functions. The arguments to all of these functions are in units of radians; recall that pi radians equals 180 degrees.

#### Inverse Trig Functions

These are the usual arc sine, arc cosine and arc tangent functions, which are the inverses of the sine, cosine and tangent functions respectively.

#### Exponents and Logarithms

These are the ’exp’ group, ’log’ group, ’pow’ group and ’sqrt’ group.

#### Hyperbolic Functions

sinh, cosh, tanh. The functions in this section are related to the exponential functions.

#### Inverse Hyperbolic Functions

asinh, acosh, atanh. The functions in this section are related to the Hyperbolicfunctions.

#### Infinite Functions

isnan, finite, isinf.

#### Special Functions

Factorial, sum, and other specific spar functions.

### EXPRESSIONS

The numbers are manipulated by expressions and statements. Since the math parser was implemented to be interactive, statements and expressions are executed as soon as possible.

A simple expression is just a constant. spar displays constants using the current precision (see OPTIONS). Full expressions are similar to many other high level languages. Since there is only one kind of number, there are no rules for mixing types.

In the following descriptions of legal expressions, "expr" refers to a complete expression and "var" refers to a simple variable.

 - expr The result is the negation of the expression. expr + expr The result of the expression is the sum of the two expressions. expr - expr The result of the expression is the difference of the two expressions. expr * expr The result of the expression is the product of the two expressions. expr / expr The result of the expression is the quotient of the two expressions. expr % expr The result of the expression is the "remainder" and it is computed in the following way. expr ^ expr The result of the expression is the value of the first raised to the second. ( expr ) This alters the standard precedence to force the evaluation of the expression. var = expr The variable is assigned the value of the expression. var This prints variable value’s: note that "var" could be also a constant.

### COMMANDS

 help Print a brief commands notice. If a command name is supplied print a detailed command report. warranty Print a longer warranty notice. No arguments. comment Add a comment to a variable. At least two arguments. consts Print the built-in constants table. No arguments. funcs Print the built-in functions table. No arguments. modules Print the all loaded modules. No arguments. old Swap the current variable value with the old one. One argument. quit Program termination. run Run a module. Note that you must supply a valid module name otherwise, the list of the loaded modules is printed. vars Print all user variables.

### FEATURES

Spar supports terminal features (termios) to allow the program to be more user-friendly and also more robust.

Spar can be compiled (via configure script) to use the GNU readline input editor library. This allows the user to do more editing of lines before sending them to spar.

It also allows for a history of previous lines typed: the history can be viewed by ’' key, whereas the readline auto-completion was implemented by the TAB key. For more information, read the user manuals for the GNU readline and history libraries. Instead the key ’!’ run the last command and, finally the key ’:’ can be used to display a specific history item. For example: ’:1’ shows the first history item.

#### SIGNALS SUPPORT

During a session, the SIGINT signal (usually generated by the control-C character from the terminal), SIGSTP signal (usually generated by the control-Z character from the terminal) and SIGTERM signal will cause execution to be interrupted. After all run-time structures have been cleaned up, a message will be printed to notify the user that spar is aborted. All variables and modules are removed during the clean up process.

#### TERMCAP SUPPORT

The control key EOF is inhibited. spar restore this setting on exit.

### BUGS

The best way to submit a bug report for Spar is to use the file BUG-REPORT, that will enable me to fix the problem. Please visit the Spar homepages at:

```     http://spar.sourceforge.net/index.html (main site)
http://web.tiscalinet.it/Davide18/index.html

```

### FILES

```/usr/local/bin/spar                     Spar
/usr/local/lib/libspar.so               Spar Library
/usr/local/lib/spar/*                   Spar modules
/usr/local/share/spar/modules_config    Spar modules config

```

### AUTHOR

Davide Angelocola davide178@inwind.it

### ACKNOWLEDGMENTS

The author would like to thank Sebastian Ritterbusch (Rascal@Ritterbusch.de) for his extensive help in testing the program and the documentation. Many great suggestions were given. Please visit his website http://rascal.sourceforge.net or the sourceforge project at http://sourceforge.net/projects/rascal.

```bc(1)    An arbitrary precision calculator language