Skip to content
v3.3.0

Types of operators

The operators specify what type of actions are performed on arguments (operands) in the formula. HyperFormula supports the operators that are common in spreadsheet software. They are calculated in a specific order which can be altered by the use of parentheses.

HyperFormula supports the following operators:

  • Unary operators
  • Binary arithmetic operators
  • Comparison operators
  • Concatenation operator
  • Reference operators

The unary operators have only one argument (operand). For example, when the unary negation operation is provided with a number, it returns the negative value of that number.

OperatorMeaningExampleDescription
-Unary minus-aReturns the negative of its argument.
+Unary plus+aReturns the positive of its argument.
%Percenta%Calculate the percent of an argument.

The binary arithmetic operators enable the computation of basic mathematical operations. They don’t have to be wrapped with any functions. This table shows the basic behavior of the binary arithmetic operators:

OperatorMeaningExampleDescription
+Additiona + bAdd the two arguments.
-Subtractiona - bSubtract the second argument from the first argument.
*Multiplicationa * bMultiply the two arguments.
/Divisiona / bDivide the first argument by the second argument.
^Exponentiationa ^ bRaise the first argument by the power of the second argument.

You are probably wondering why the modulo operator is missing. It is supported by the function MOD so instead of writing a % b, as you would in a regular mathematical equation, you use a formula like this: =MOD(a, b).

The binary relational operators, when used in a formula, return boolean or logical values. Here are some very general rules:

OperatorMeaningExampleDescription
=Equal toa = bTrue if a is equal to b.
<Less thana < bTrue if a is less than b.
>Greater thana > bTrue if a is greater than b.
<=Less than or equala <= bTrue if a is less than or equal to b.
>=Greater than or equala >= bTrue if a is greater than or equal to b.
<>Not equal toa <> bTrue if a is not equal to b.

HyperFormula does type coercion and it can have an impact on comparing, adding, or any other operation between values of a different type. The tables represent some operations between different types and their results.

Boolean to int coercion, basic arithmetic operations

Section titled “Boolean to int coercion, basic arithmetic operations”
OperationResult
true + null1
true - null1
true * null0
true / null#DIV/0!
true^null1
+true (unary plus true)true
-true (unary minus true)-1
true%0.01
OperationResult
null + true1
null - true-1
null * true0
null / true0
null ^ true0
+null (unary plus null)null
-null (unary minus null)0
null%0
OperationResult
true + true2
true - true0
true * true1
true / true1
true ^ true1
OperationResult
false + true1
false - true-1
false * true0
false / true0
false ^ true0
OperationResult
true + false1
true - false1
true * false0
true / false#DIV/0!
true ^ false1
OperationResult
false + false0
false - false0
false * false0
false / false#DIV/0!
false ^ false1
+false (unary plus false)false
-false (unary minus false)0
false%0
OperationResult
null + false0
null - false0
null * false0
null / false#DIV/0!
null ^ false1
OperationResult
"" > nullfalse
"" < nullfalse
"" >= nulltrue
"" <= nulltrue
OperationResult
”string” > falsefalse
”string” < falsetrue
”string” >= falsefalse
”string” <= falsetrue
OperationResult
null > falsefalse
null < falsefalse
null >= falsetrue
null <= falsetrue
OperationResult
null > 1false
null < 1true
null >= 1false
null <= 1true
OperationResult
-1 > nullfalse
-1 < nulltrue
-1 >= nullfalse
-1 <= nulltrue
OperationResult
0 > nullfalse
0 < nullfalse
0 >= nulltrue
0 <= nulltrue
OperationResult
0 > falsefalse
0 < falsetrue
0 >= falsefalse
0 <= falsetrue
0 = falsefalse
OperationResult
1 > truefalse
1 < truetrue
1 >= truefalse
1 <= truetrue
1 = truefalse

By default, HyperFormula is case and accent insensitive. This means it will ignore upper and lower-case letters and accents during the comparison. For example, if you compare AsTrOnAuT with aStroNaut they will be understood as identical, the same goes for Préservation and Preservation. It applies to comparison operators only. It can be configured with accentSensitive and caseSensitive options in the configuration.

Apart from accents and case sensitivity, you can also configure caseFirst. This option defines whether upper case or lower case should come first. Additionally the ignorePunctuation option specifies whether punctuation should be ignored in string comparison. By default caseFirst is set to 'lower' and ignorePunctuation is set to false. For more details see the official API reference of HyperFormula.

Here is an example configuration that overwrites default settings:

// this part of the configuration shows options
// related to strings only
const options = {
caseSensitive: true,
accentSensitive: true,
caseFirst: 'upper',
ignorePunctuation: true
};

The concatenation operator is used to combine multiple text strings into a single value.

OperatorMeaningExampleDescription
&Concatenation”a” & “b”Concatenates two arguments
(left and right) into one

The reference operators are used to perform calculations of combined ranges.

OperatorMeaningExampleDescription
: (colon)Range operatorA1:B1Makes one reference to multiple cells between the two specified references.
, (comma)Union operatorA1:B1,A2:B2Returns the intersection of multiple ranges.
(space)Intersection operatorA1:B1 A2:B2Finds the intersection of the two ranges.