C Expressions

Expressions can also be entered using a C-like syntax. Any expression that starts with a '=' will be parsed by a separate evaluator which understands the following operators:
N ; M
Add all numbers in the current column from row N to row M.
N : M
Add all numbers in the current row from column N to column M.
N , M
Get the value from the cell in row N, column M.
N || M
Logical OR of N and M.
N && M
Logical AND of N and M.
N | M
Bitwise OR of N and M.
N ^ M
Bitwise XOR of N and M.
N & M
Bitwise AND of N and M.
N == M
1 if N equals M, 0 otherwise.
N != M
1 if N is not equal to M, 0 otherwise.
N < M
1 if N is less than M, 0 otherwise.
N <= M
1 if N is less than or equal to M, 0 otherwise.
N > M
1 if N is greater than M, 0 otherwise.
N >= M
1 if N is greater than or equal to M, 0 otherwise.
N >> M
N shifted right M steps.
N << M
N shifted left M steps.
N + M
N - M
N * M
N / M
N % M
!N
Logical NOT of N.
~N
Bitwise NOT of N.
-N
+N
In the above, N and M are either sub-expressions or constants. Constants can be hexadecimal numbers starting with 0x, octal numbers starting with 0 or floating-point numbers with or without decimal point and exponent. Note that this means that floating-point numbers must not start with 0 because they would be interpreted as octal.

Operators are evaluated in the following order:

  1. Unary + - ! ~
  2. * / %
  3. + -
  4. == !=
  5. &
  6. ^
  7. |
  8. &&
  9. ||
  10. ; : ,
Parentheses can be used to group sub-expressions and to override the standard evaluation order.

The characters R and C can be used to denote the current row and column, respectively.

The expressions can contain white space and C-style comments.

Examples

=123.4
The constant 123.4
=1+2-3
This evaluates to 0
=3,4
The contents of the cell in row 3, column 4
=r, c-1
The contents of the cell immediately to the left of the current cell
=2;r-1
The sum of the cells in the current column from row 2 to the row immediately above the current cell
=(r-1,c)+(r,c-1)
The sum of the cells to the left and above the current cell. The parentheses are necessary because '+' would otherwise be evaluated before ','
=0.1
This produces an error, because the '0' makes Siag expect an octal number. Write this example as '=.1'

Ulric Eriksson - July 1996 - ulric@asogy.stockholm.se