C Expressions

Expressions can also be entered using a C-like syntax. The C interpreter 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.

Numbers starting with a single 0 immediately followed by a decimal point are interpreted as floating point numbers.

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.

Cell References

In addition to using the comma notation above, cells can be referred to using the r1c1 notation from Visicalc.

References are automatically updated when lines and columns are inserted or removed.

Ranges

Certain functions can handle not only numbers and references, but whole ranges of cells. Such ranges are written as, for example, r1c1..r2c3. In this case, the range consists of all cells from row 1, column 1 to row 2, column 3 (6 cells altogether). Not all fuctions can handle ranges.

Ranges update when lines and columns are inserted or deleted, just like the references described above.

Numeric variables

Variables can be assigned from the C interpreter in the following way:
define(name, value)
where name is the name of the variable and value is a numeric constant, another variable or a cell reference. The value cannot itself be an expression.

Variables assigned in the C interpreter can also be used from SIOD, and any variable known by the SIOD interpreter is also available here.

Functions

All functions known by the SIOD interpreter can also be called from the C interpreter by writing the call as:
function(argument, argument...)
The arguments can be constants, cell references or numeric variables known by the SIOD interpreter. The arguments cannot themselves be expressions.

More information on the Scheme interpreter

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 ','
r2c3+r2c4
The sum of the value in row 2, column 3 and the value in row 2, column 4
acos(r3c1)
Arc cosine of the value in row 3, column 1
tan(r2c2)
Tangent of r2c2.
sin(r2c2)/cos(r2c2)
Also tangent of r2c2. Function calls can be part of expressions
pow(temp, 0.25)
The variable temp raised to the power of 1/4
pow(temp, 1/4)
This is an error because 1/4 is an expression and as such must not appear in an argument list
asin(sin(1.59))
Again, this is an error because sin(1.59) is an expression
define(pi, 3.14)
Define a useful variable
r_sum(r2c2..r5c6, r1c1, 12)
The sum of all numbers between row 2, column 2 and row 5, column 6; the number in row 1, column 1; and the number 12.

Ulric Eriksson - October 1997 - ulric@siag.nu