ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/doc/man/man1/calc.1
Revision: 1.1
Committed: Tue Mar 11 19:20:21 2003 UTC (22 years, 2 months ago) by greg
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Added documentation to repository

File Contents

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