3 While calc is C-like, users of C will find some unexpected
4 surprises in calc syntax and usage. Persons familiar with C should
11 The comma is also used for continuation of obj and mat creation
12 expressions and for separation of expressions to be used for
13 arguments or values in function calls or initialization lists. The
14 precedence order of these different uses is: continuation,
15 separator, comma operator. For example, assuming the variables a,
16 b, c, d, e, and object type xx have been defined, the arguments
19 f(a, b, c, obj xx d, e)
21 are a, b, c, and e, with e having the value of a newly created xx
24 f((a, b), c, (obj xx d), e)
26 the arguments of f are b, c, d, e, with only d being a newly
29 In combination with other operators, the continuation use of the
30 comma has the same precedence as [] and ., the separator use the
31 same as the comma operator. For example, assuming xx.mul() has
34 f(a = b, obj xx c, d = {1,2} * obj xx e = {3,4})
36 passes two arguments: a (with value b) and the product d * e of two
37 initialized xx objects.
43 In C, ^ is the xor operator. Like the '**', '^' is the
44 exponentiation operator. The expression:
48 yields "a to the b power", NOT "a xor b".
50 Note that 'b' must be an integer. Also if 'a' == 0, 'b'
53 To raise to a non-integer power, use the power() builtin function.
59 As was suggested in the '^ is not xor' section, the expression:
63 yields "a to the b power", NOT "a xor b".
65 Note that 'b' must be an integer. Also if 'a' == 0, 'b'
68 To raise to a non-integer power, use the power() builtin function.
71 op= operators associate left to right
72 =====================================
74 Operator-with-assignments:
76 += -= *= /= %= //= &= |= <<= >>= ^= **=
78 associate from left to right instead of right to left as in C.
87 where only 'a' is required to be an lvalue. For the effect of:
91 when both 'a' and 'b' are lvalues, use:
96 || yields values other than 0 or 1
97 ==================================
103 will produce 0 or 1 depending on the logical evaluation
104 of the expression. In calc, this expression will produce
105 either 'a' or 'b' and is equivalent to the expression:
109 In other words, if 'a' is true, then 'a' is returned, otherwise
113 && yields values other than 0 or 1
114 ==================================
120 will produce 0 or 1 depending on the logical evaluation
121 of the expression. In calc, this expression will produce
122 either 'a' or 'b' and is equivalent to the expression:
126 In other words, if 'a' is true, then 'b' is returned, otherwise
130 / is fractional divide, // is integral divide
131 =============================================
137 performs integer division when 'x' and 'y' are integer types.
138 In calc, this expression yields a rational number.
144 to perform division with integer truncation and is the equivalent to:
149 | and & have higher precedence than ==, +, -, *, / and %
150 ========================================================
160 and calc it is interpreted as:
165 calc always evaluates terms from left to right
166 ==============================================
168 Calc has a definite order for evaluation of terms (addends in a
169 sum, factors in a product, arguments for a function or a matrix,
170 etc.). This order is always from left to right. but skipping of
171 terms may occur for ||, && and ? : .
173 Consider, for example:
177 In calc above expression is evaluated in the following order:
187 This order of evaluation is significant if evaluation of a
188 term changes a variable on which a later term depends. For example:
190 x++ * x++ + x++ * x++
192 in calc returns the value:
194 x * (x + 1) + (x + 2) * (x + 3)
196 and increments x as if by x += 4. Similarly, for functions f, g,
203 f(x, x + 1) + g(x + 2)
205 and increments x three times.
208 &A[0] and A are different things in calc
209 ========================================
211 In calc, value of &A[0] is the address of the first element, whereas
212 A is the entire array.
215 *X may be used to to return the value of X
216 ==========================================
218 If the current value of a variable X is an octet, number or string,
219 *X may be used to to return the value of X; in effect X is an
220 address and *X is the value at X.
223 freeing a variable has the effect of assigning the null value to it
224 ===================================================================
226 The freeglobals(), freestatics(), freeredc() and free() free
227 builtins to not "undefine" the variables, but have the effect of
228 assigning the null value to them, and so frees the memory used for
229 elements of a list, matrix or object.
231 Along the same lines:
235 undefines all current user-defined functions. After executing
236 all the above freeing functions (and if necessary free(.) to free
237 the current "old value"), the only remaining numbers as displayed by
241 should be those associated with epsilon(), and if it has been
248 In addition to the C style /* comment lines */, lines that begin with
249 #! are treated as comments.