Skip to main content
These cover core arithmetic, percent change, modulo, powers, roots, logarithms, and exponential functions. Every operation works on a number or a table, returning the same shape it was given. For operator precedence and the comparison and logical operators, see Operators and precedence.

Core arithmetic

Each operation accepts two numbers, a number and a table, or two tables — producing a new table when a table is involved. Two tables must be the same length, or an Invalid dimensions error is returned. Dividing by 0 returns a Division by 0 error; 1 / value returns the reciprocal of value.
Each of these operations accepts unit numbers as well as plain ones. Compatible units convert before adding, and multiplication and division combine dimensions:

Percent change [ch]

Returns value adjusted by a percentage change (entered as a decimal): a positive change adds, a negative change subtracts. This is the financial calculator equivalent of value + change% or value - change%, which a spreadsheet would write as value ± (value * change%). With periods, it compounds the change over that many periods (compound annual growth rate). value can be a number or a table.

Modulo [mod]

The remainder of value1 divided by value2. A value2 of 0 returns a Division by 0 error. Either argument can be a number or a table; if both are tables they must be the same length, or Invalid dimensions is returned. If value1 or value2 is too large to calculate then returns ‘Parameter out of range’ error. The remainder takes the sign of value1.
With units. mod works on unit numbers as readily as on plain ones. Both arguments must be the same kind of value: two plain numbers, or two units of the same dimension. Compatible units convert before the division, and the remainder is reported in value1’s unit. Anything else returns input.incompatible_units, including a bare number paired with a unit value.
That makes a time-of-day calculation direct. A date is a count of seconds, so the remainder of a date divided by one day is the time elapsed since midnight, with no stripping units and putting them back:
The second line follows from that rule. Cast the date to days before dividing and the remainder arrives in days, so noon reads as 0.5 d rather than 43200 s. That is the fraction-of-a-day figure a spreadsheet keeps time in. Because the sign follows value1, a date before 1970 is a negative value and gives a negative remainder.

Powers and roots

Power [^]

Raises value to the x power. value can either be a number or table where the same is returned. Several forms are common:
  • value ^ 2, value ^ 3 — squared, cubed.
  • value ^ -1 — the reciprocal of value (see also division).
  • value ^ (1/2) — the square root, the same as sqrt(value).
  • value ^ (1/x) — the xth root, the same as root(value; x).
With a unit, the exponent binds to the unit, not to the value. m^2 is the unit square metres, so 2m^2 is two square metres — not (2m) squared. Parenthesize the value to raise it:

Square root [sqrt]

The square root of value. value can either be a number or table where the same is returned. A root reduces the dimension along with the value: the square root of an area is a length.

Root [root]

The xth root of value. root(value; 2) is the same as sqrt(value). value can either be a number or table where the same is returned.

Logarithms and exponentials

These take a dimensionless value. An argument carrying a unit returns input.incompatible_type — convert it to a bare number first with unitvalue.

Natural logarithm [ln]

The natural logarithm (base e) of value. value can either be a number or table where the same is returned.

Exponential [exp]

The constant e (2.718281828459045) raised to value. value can either be a number or table where the same is returned. There is no e constant; write exp(1) when you need e itself.

Logarithm [log]

The logarithm of value in base 10, or in base. value can either be a number or table where the same is returned. base must be a whole number ≥ 2; real numbers are truncated, and values outside the range return a Parameter out of range error.

Antilogarithm [alog]

The inverse (base 10) logarithm of value. value can either be a number or table where the same is returned.