Sisällys

# Operators in LibreOffice Calc

You can use the following operators in LibreOffice Calc:

## Arithmetical Operators

These operators return numerical results.

Operator | Name | Example
--- | --- | ---
+ | Addition | 1+1
- | Subtraction | 2-1
- | Negation | -5
* | Multiplication | 2*2
/ | Division | 9/3
% | Percent | 15%
^ | Exponentiation | 3^2

Prefix "-" (negation) has a higher precedence than "^" (exponentiation). For example -3^2 equals 9, which is the square of a negative number.

B^X may or may not report a #NUM! error when B is negative and X is not an integer. The expression =B^X is calculated the same way as =POWER(B;X).

## Comparative operators

These operators return either true or false.

Operator | Name | Example
--- | --- | ---
= | Equal | A1=B1
> | Greater than | A1>B1
< | Less than | A1<B1
>= | Greater than or equal to | A1>=B1
<= | Less than or equal to | A1<=B1
<> | Inequality | A1<>B1

## Text operators

The operator combines separate texts into one text.

Operator | Name | Example
--- | --- | ---
& | text concatenation | "Sun" & "day" is "Sunday"

## Reference operators

These operators return a cell range of zero, one or more cells.

Range has the highest precedence, then intersection, and then finally union.

Operator | Name | Example
--- | --- | ---
: | Range | A1:C108, A:D or 3:13
! | Intersection | SUM(A1:B6!B5:C12) Calculates the sum of all cells in the intersection; in this example, the result yields the sum of cells B5 and B6.
~ | Concatenation or union | Takes two references and returns a reference list, which is a concatenation of the left reference followed by the right reference. Double entries are referenced twice. =COUNT(A1:B2~B2:C3) counts values of A1:B2 and B2:C3. Note that the cell B2 is counted twice. =INDEX(A1:B2~C1:D2;2;1;2) selects cell C2, that is, the first cell of the second row, first column, of the second range (C1:D2) of the range list.

A reference list is not allowed inside an array expression.

## Operator precedence

Associativity and precedence of operators, from highest to lowest precedence.

Associativity | Operator(s) | Comments
--- | --- | ---
left | : | Range.
left | ! | Reference intersection (A1:C4!B1:B5 is B1:B4).
left | ~ | Reference union.
right | +,- | Prefix unary operators. For example, -5 or -A1. Note that these have a different precedence than add and subtract.
left | % | Postfix unary operator % (divide by 100). Note that this is legal with expressions, for example, B1%.
left | ^ | Power (2^3 is 8).
left | *,/ | Multiply, divide.
left | +,- | Binary operations add, subtract. Note that unary (prefix) + and - have a different precedence.
left | & | Binary operation string concatenation. Note that "&" shall be escaped when included in an XML document.
left | =, <>, <, <=, >, >= | Comparison operators equal to, not equal to, less than, less than or equal to, greater than, greater than or equal to.

Prefix "-" has a higher precedence than "^", "^" is left-associative, and reference intersection has a higher precedence than reference union.

Prefix "+" and "-" are defined to be right-associative. However, note that typical applications which implement at most the operators defined in this specification (as specified) may implement them as left-associative, because the calculated results will be identical.

Precedence can be overridden by using parentheses, so "=2+3*4" computes to 14 but "=(2+3)*4" computes 20.

Aiheeseen liittyvää

OpenDocument v1.3 part 4, Formula Operators

Please support us!