C Expressions

Expressions can be entered using a C-like syntax. The 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
Addition.
N - M
Subtraction.
N * M
Multiplication.
N / M
Division.
N \ M
Integer division, i.e. the remainder is thrown away.
N % M
Modulus.
N ** M
Exponentiation.
!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. ||
  11. ; : ,
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 the comma notation above, cells can be referred to using R1C1 or A1 notation. The reference style is changed using the Window - Reference Style menu entry.

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, a1..c2. In this case, the range consists of all cells from row 1, column 1 to row 2, column 3 (6 cells altogether). Not all functions 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 interpreter in the following way:
define(name, value)
where name is the name of the variable and value is a numeric constant, another variable, a cell reference or an expression.

Variables assigned in the 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 can also themselves be expressions.

Reference list of available functions

More information on the Scheme interpreter

Examples

123.4
The constant 123.4
1+2-3
This evaluates to 0
2^3
Exclusive or of 2 and 3, i.e. 1.
2**3
2 raised to the power of 3, i.e. 8.
18/5
Evaluates to 3.6.
18\5
Evaluates to 3.
3,4
The contents of the cell in row 3, column 4
R3C4
The same in r1c1 notation
D3
The same in a1 notation
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
c2+d2
Same as above in A1 reference style
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)
Ditto
asin(sin(1.59))
In this example, 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 - July 2000 - ulric@siag.nu