# rcalc documentation

Copyright (C) 2000 Free Software Foundation, Inc.

This program and the documentation are free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

For more details see the file COPYING.

## Table of contents

### 1. Introduction

- 1.1. Feedback

### 2. Usage

- 2.1 Basics
- 2.2 Configuration
  - 2.2.1 Behavior
  - 2.2.2 Appearance

### 3. Reference

- 3.1 Commands
  - 3.1.1 Exit, Quit
  - 3.1.2 Help, Man, Helpwin, ?
  - 3.1.3 Ls, Who
  - 3.1.4 Rm, Clear
  - 3.1.5 Mode, Deg, Rad
- 3.2 Functions
  - 3.2.1 Int
  - 3.2.2 Abs
  - 3.2.3 Log, Ln
  - 3.2.4 Sqrt
  - 3.2.5 Sin, Cos, Tan, ASin, ACos, ATan
  - 3.2.6 Sinh, Cosh, Tanh, ASinh, ACosh, ATanh
  - 3.2.7 Fac
- 3.3 Constants
  - 3.3.1 Pi
  - 3.3.2 E

### 4. User-defined functions

- 4.1 Introduction
- 4.2 Usage

- 4.2.1 Define a new function
- 4.2.2 Use a function
- 4.2.3 List functions
- 4.2.4 Remove a function

- 4.3 Error messages

## 1. Introduction

rcalc is a fast, simple, symbolic calculator for GNOME, featuring:

- infix notation: expressions are entered as you would write them down, for example `1+3*sin(5)` is evaluated as you would expect.
- variables: this is where the `symbolic' comes in; if you enter an expression such as `a=1*2+3*4`, the result is stored in a variable called `a`. This may then be used in further expressions, such as `b=sqrt(a*5)`. Variables persist between rcalc sessions until such time as you decide to delete them.
- (optional) user-defined functions: see section 4.0.

rcalc is therefore not like other calculator programs, such as xcalc, kcalc or gcalc. It currently supports simple operators such as `/`, `*`, `+`, `-` and `^` (`raise to the power of'), as well as more complex functions like the trigonometric functions (`sin`, `cos`, `tan`, `asin`, `acos` and `atan`), the hyperbolic functions (`sinh`, `cosh`, `tanh`, `asinh`, `acosh` and `atanh`), `sqrt`, `log`, `ln`, `abs` and `int`. It also has two built-in constants, `pi` and `e`.

rcalc is supposed to form part of the GNOME desktop environment and as such tries to conform to the general `look and feel' of other GNOME applications. The rcalc command interpreter tries to conform to the bash shell, and to some extent to Matlab's command interpreter. Hopefully this should all come together and make rcalc easy to use: tell me what you think!

rcalc is not meant to be a complete mathematical package; simply a fast-loading, simple and convenient scientific calculator. If you want a complete heavy-duty maths solution, look at bc or Dr Genius (both free), or Matlab (commercial).

### 1.1 Feedback

Check out the rcalc website, http://rcalc.sourceforge.net/ for updates. There are forums for general discussion, help requests and suggestions: please feel free to use them.

If you find a bug, please go to the rcalc bugs page and submit it if it is not there already.

If none of the above seem appropriate, then email me on <phneutre@icculus.org>.

## 2. Usage

### 2.1 Basics

When you start rcalc, you will be presented with a simple window containing a prompt (``rcalc>` '); expressions are generally entered at this prompt as you would write them down on paper. The notable exception to this is that rcalc does not support implied multiplication: you cannot enter `3sin(2pi)` as the parser will not recognize that you mean `three multiplied by the sine of two multiplied by pi'. The correct way to enter the above expression is `3*sin(2*pi)`.

If you were to type in the above expression, you will see the following output:

    rcalc> 3*sin(2*pi)
            Ans = 0.3283278207189595

The result of the calculation has been assigned to a variable called '`Ans`'; indeed the results of all calculations are stored in `Ans` unless otherwise stated. This result can then be used in subsequent calculations, for example:

    rcalc> Ans+1
            Ans = 1.328327820718959

The result may be stored in a variable other than '`Ans`', for example:

    rcalc> MyVariable = Ans*5
            MyVariable = 6.641639103594797

The result of the calculation has now been stored in '`MyVariable`';' `Ans`' has been left untouched.

Variable names, and indeed function, command and constant names, are case-insensitive: `MyVariable`, `myvariable`, `MYVARIABLE` and `MyVaRiAbLe` all refer to the same value. Any whitespace in expressions is ignored, although whitespace in commands is not.

Variables are managed using the ``ls`' and ``rm`' commands in a similar manner to that in which files are managed in a shell, for example:

    rcalc> ls
            Ans      = 1.328327820718959
            MyVariable = 6.641639103594797
    rcalc> rm Ans
    rcalc> ls
            MyVariable = 6.641639103594797

Continuing the theme of being shell-like, there is a ``man`' command; try typing ``man man`' at the prompt. Another shell-like feature is the ability to enter multiple commands/expressions on the same line: semicolons (`;`) are used to separate items, for example:

    rcalc> a=0.223; Tb=0.044; 1/Tb*(1-Ta/Tb)
            Ta = 0.223
            Tb = 0.044
            Ans = -92.45867768595043

For those of you who have used Matlab, most of the shell-like commands have Matlab-like aliases, for example `help`, `helpwin`, `who` and `clear`. Please read the documentation, however, as some commands behave differently when their Matlab alias is used.

### 2.2 Configuration

To configure rcalc, select Preferences... from the File pull down menu. The window that appears has three sections, which can be navigated using the tabs at the top.

#### 2.2.1 Behavior

This window allows you to configure the behavior of the terminal in which rcalc runs. You can set where the scrollbar will appear, the number of lines of text that will kept in memory for scrolling, whether the terminal will scroll to the cursor when a key is pressed or when text is output, whether the cursor will flash and whether an audible beep will be heard at certain occasions.

#### 2.2.2 Appearance

This window allows you to set the font and colors used. Please note that the display may look strange if proportional fonts are used; rcalc is designed to use fixed-width (monospace) fonts such as Courier or Lucidatypewriter.

## 3. Reference

### 3.1 Commands

#### 3.1.1 Exit, Quit

`exit
quit`

Exit the program.

#### 3.1.2 Help, Man, Helpwin, ?

`help [topic]
man <topic>
helpwin [topic]
? [topic]`

Display help on `topic`, where `topic` is generally the name of a command or function. For a list of topics, try typing ``ls` commands' or ``ls` functions'. `Help`, `helpwin` or `?` without a topic simply displays the introduction of the help file.

#### 3.1.3 Ls, Who

`ls [variables|functions|constants|commands]
who`

List the items specified; if no arguments are supplied, `ls` will list the variables. `Who` is simply an alias of `ls variables`.

#### 3.1.4 Rm, Clear

`rm variable1 [variable2 ...]
clear [variable1 [variable2 ...]]`

Remove the specified variables from memory. `Clear` with no arguments will delete all variables.

#### 3.1.5 Mode, Deg, Rad

`mode [deg|rad]
deg
rad`

Display or set the calculation engine settings; this is equivalent to the calculations section of the preferences dialog. Currently, the only settings relate to the units of angles used by the trigonometric functions.

`Mode` with no arguments displays the current mode; with one argument it will set the unit of angles used. `Deg` is simply an alias of `mode deg`, and likewise `rad` is an alias of `mode rad`.

### 3.2 Functions

#### 3.2.1 Int

`int(x)`

Returns the nearest integer to `x`, using rounding arithmetic.

#### 3.2.2 Abs

`abs(x)`

Returns the absolute value of `x`.

#### 3.2.3 Log, Ln

`log(x)
ln(x)`

Return the base-10 logarithm (`log`) or the natural logarithm (`ln`) of `x`.

#### 3.2.4 Sqrt

`sqrt(x)`

Returns the square root of `x`.

#### 3.2.5 Sin, Cos, Tan, ASin, ACos, ATan

`sin(x)
cos(x)
tan(x)
asin(x)
acos(x)
atan(x)`

Return the sine, cosine, tangent, arc sine, arc cosine or arc tangent of `x`, taking account of the specified units of angle (see `mode`).

#### 3.2.6 Sinh, Cosh, Tanh, ASinh, ACosh, ATanh

`sinh(x)
cosh(x)
tanh(x)
asinh(x)
acosh(x)
atanh(x)`

Return the hyperbolic sine, hyperbolic cosine, hyperbolic tangent, inverse hyperbolic sine, inverse hyperbolic cosine or inverse hyperbolic tangent of `x`.

#### 3.2.7 Fac

`fac(x)`

Returns x!, i.e. n(n-1)(n-2)...(1)

### 3.3 Constants

#### 3.3.1 Pi

The ratio of a circle's circumference to its diameter: rcalc uses the math library definition, which on my machine is 3.14159265358979323846.

#### 3.3.2 E

The base of natural logarithms: rcalc uses the math library definition, which on my machine is 2.7182818284590452354.

## 4. User-defined functions

### 4.1 Introduction

Starting with rcalc 0.4.0, you can define your own functions.

These functions are parsed by default, but if you compiled rcalc using the --enable-compiled-functions configure flag (this particular method is currently unsupported, not enabled by default, and needs a working gcc installed), they are compiled and dynamically linked to the executable when you define them.

Your functions are automatically reloaded at startup (like variables).

### 4.2 Usage

#### 4.2.1 Define a new function

When defining a function, the variable is `x`. Currently, you can only define a function that uses only 1 variable (`x`), that is, you cannot define something like `f(x,y)=cos(x) + sin(y)`.

To create a new function, use the func command:
`func [function_name](x)=[function_expression]`
Examples:

    rcalc> func g(x)=2*x

    rcalc> func myfunction(x) = 2*x*x + 7*cos((sin(x))) - abs(x)

If you compiled with --enable-compiled-functions, you can do some advanced stuff like this, provided you write C code that can be put after a return.

    rcalc> func fact(x)=(!(int)x) ? 1 : (abs( (int) x ) * fact (abs( (int)x )-1))

#### 4.2.2 Use a function

`function_name( [mathematical_expression] )`

Example, if both `g` and `myfunction` exist:

    rcalc> 3*sin(2*pi)
            Ans = 0.3283278207189595

    rcalc> g( 5 * cos ( myfunction( 2-Ans ) ) )
            Ans = 9.892698159952772

#### 4.2.3 List functions

`ls functions` (or just `ls func`)

This will list both built-in functions (see section 3.2) and user-defined functions.

#### 4.2.4 Remove a function

`rm [function_name]`

### 4.3 Error messages

This error messages means your function expression is incorrect (this may differ if you compiled with --enable-compiled-functions) :

    rcalc> func t(x)=foo

    error : malformed expression.