| 1 |
.\" RCSid "$Id: icalc.1,v 1.2 2007/09/04 17:36:40 greg Exp $" |
| 2 |
.TH ICALC 1 2/3/95 RADIANCE |
| 3 |
.SH NAME |
| 4 |
icalc - interactive calculator |
| 5 |
.SH SYNOPSIS |
| 6 |
.B icalc |
| 7 |
[ |
| 8 |
.B file |
| 9 |
] |
| 10 |
.SH DESCRIPTION |
| 11 |
.I Icalc |
| 12 |
is a algebraic calculator designed primarily for |
| 13 |
interactive use. |
| 14 |
Each formula definition |
| 15 |
.I file |
| 16 |
is read and compiled from the RADIANCE library where it is found. |
| 17 |
The standard input is then read, expressions are evaluated |
| 18 |
and results are sent to the standard output. |
| 19 |
If a newline is escaped using a backslash, input is continued |
| 20 |
on the next line. |
| 21 |
.PP |
| 22 |
An expression contains real numbers, variable names, function calls, |
| 23 |
and the following operators: |
| 24 |
.PP |
| 25 |
+ - * / ^ |
| 26 |
.PP |
| 27 |
Operators are evaluated left to right, except '^', |
| 28 |
which is right associative. |
| 29 |
Exponentiation has the highest precedence; multiplication and |
| 30 |
division are evaluated before addition and subtraction. |
| 31 |
Expressions can be grouped with parentheses. |
| 32 |
Each result is assigned a number, which can be used in future expressions. |
| 33 |
For example, the expression ($3*10) is the result of the |
| 34 |
third calculation multiplied by ten. |
| 35 |
A dollar sign by itself may be used for the previous result. |
| 36 |
All values are double precision real. |
| 37 |
.PP |
| 38 |
In addition, variables and functions can be defined by the |
| 39 |
user. |
| 40 |
A variable definition has the form: |
| 41 |
.PP |
| 42 |
|
| 43 |
var = expression ; |
| 44 |
|
| 45 |
.PP |
| 46 |
Any instance of the variable in an expression will be replaced |
| 47 |
with its definition. |
| 48 |
A function definition has the form: |
| 49 |
.PP |
| 50 |
|
| 51 |
func(a1, a2, ..) = expression ; |
| 52 |
|
| 53 |
.PP |
| 54 |
The expression can contain instances of the function arguments |
| 55 |
as well as other variables and functions. |
| 56 |
Function names can be passed as arguments. |
| 57 |
Recursive functions can be defined using calls to the defined |
| 58 |
function or other functions calling the defined function. |
| 59 |
.PP |
| 60 |
To define a constant expression, simply replace the equals sign ('=') |
| 61 |
with a colon (':') in a definition. |
| 62 |
Constant expressions are evaluated only once, the first time they are used. |
| 63 |
This avoids repeated evaluation of expressions whose values never change. |
| 64 |
Ideally, a constant expression contains only numbers and references |
| 65 |
to previously defined constant expressions and functions. |
| 66 |
Constant function definitions are are |
| 67 |
replaced by their value in any expression that uses them with constant |
| 68 |
arguments. |
| 69 |
All predefined functions and variables have the constant attribute. |
| 70 |
Thus, "sin(PI/4)" in an expression would be immediately replaced by ".707108" |
| 71 |
unless sin() or PI were redefined by the user. |
| 72 |
(Note that redefining constant expressions is not a recommended practice!)\ |
| 73 |
.PP |
| 74 |
A variable or function's definition can be displayed with the '?' |
| 75 |
command: |
| 76 |
.PP |
| 77 |
? name |
| 78 |
.PP |
| 79 |
If no name is given, all definitions are printed. |
| 80 |
The '>' command writes definitions to a file: |
| 81 |
.PP |
| 82 |
> file |
| 83 |
.PP |
| 84 |
Similarly, the '<' command loads definitions. |
| 85 |
.PP |
| 86 |
The following library of predefined functions and variables is provided: |
| 87 |
.TP 10n |
| 88 |
.BR PI |
| 89 |
the ratio of a circle's circumference to its diameter. |
| 90 |
.TP |
| 91 |
.BR "if(cond, then, else)" |
| 92 |
if cond is greater than zero, |
| 93 |
then is evaluated, otherwise else is evaluated. |
| 94 |
This function is necessary for recursive definitions. |
| 95 |
.TP |
| 96 |
.BR "select(N, a1, a2, ..)" |
| 97 |
return aN (N is rounded to the nearest integer). |
| 98 |
This function provides array capabilities. |
| 99 |
If |
| 100 |
.I N |
| 101 |
is zero, the number of available arguments is returned. |
| 102 |
.TP |
| 103 |
.BR "rand(x)" |
| 104 |
compute a random number between 0 and 1 based on x. |
| 105 |
.TP |
| 106 |
.BR "floor(x)" |
| 107 |
return largest integer not greater than x. |
| 108 |
.TP |
| 109 |
.BR "ceil(x)" |
| 110 |
return smallest integer not less than x. |
| 111 |
.TP |
| 112 |
.BR "sqrt(x)" |
| 113 |
return square root of x. |
| 114 |
.TP |
| 115 |
.BR "exp(x)" |
| 116 |
compute e to the power of x (e approx = 2.718281828). |
| 117 |
.TP |
| 118 |
.BR "log(x)" |
| 119 |
compute the logarithm of x to the base e. |
| 120 |
.TP |
| 121 |
.BR "log10(x)" |
| 122 |
compute the logarithm of x to the base 10. |
| 123 |
.TP |
| 124 |
.BR "sin(x), cos(x), tan(x)" |
| 125 |
trigonometric functions. |
| 126 |
.TP |
| 127 |
.BR "asin(x), acos(x), atan(x)" |
| 128 |
inverse trigonometric functions. |
| 129 |
.TP |
| 130 |
.BR "atan2(y, x)" |
| 131 |
inverse tangent of y/x (range \-pi to pi). |
| 132 |
.SH ENVIRONMENT |
| 133 |
RAYPATH the directories to check for auxiliary files. |
| 134 |
.SH AUTHOR |
| 135 |
Greg Ward |
| 136 |
.SH "SEE ALSO" |
| 137 |
ev(1), rcalc(1), tabfunc(1) |