Reference

Operators & precedence

Every operator Hissab understands, and the order it applies them in. For the details of each group, see Arithmetic, Percentages, Probability, Bitwise operations, Symbolic algebra, Complex numbers, and Sets and combinatorics.

Precedence

Ranked from tightest-binding (applied first) to loosest-binding (applied last). Operators sharing a rank are applied left to right.

RankOperatorsGroup
1~ (NOT), perm, combBitwise / combinatorics
2! (factorial)Arithmetic
3% (postfix), prefix functions sin, cos, log, …Percent / functions
4^ (power)Arithmetic
5*, /, modArithmetic
6+, -Arithmetic
7off, of what isPercent phrases
8& (AND)Bitwise
9| (OR)Bitwise
10xor, <<, >>Bitwise
11to (conversion)Conversion
12= (assignment)Assignment
2 + 3 * 4
(2 + 3) * 4
256 ^ (1/8)

When in doubt, parenthesize. Bitwise operators bind looser than arithmetic, so 1 + 2 & 3 applies the + before the & — parenthesize to make the intent explicit.

Arithmetic

OperatorMeaningExample
+ -add, subtract100 - 25
* /multiply, divide10 * 5
^ (or **)power2 ^ 10
modmodulo (remainder)10 mod 7
!factorial (postfix)5!
10 mod 7
5!
2 ^ 10

Percent

OperatorMeaningExample
%postfix percent (5% → 0.05)5%
% ofpercent of a value25% of 200
+ % / - %markup / discount applied to other operand200 + 20%
offdiscount wording5% off 10
% of what isreverse percent33% of what is 3000
25% of 200
200 + 20%
33% of what is 3000

Combinatorics

perm and comb are infix operators, not functions.

OperatorMeaningExample
permpermutations (order matters)10 perm 3
combcombinations (order ignored)10 comb 3
10 perm 3
10 comb 3

Bitwise

OperatorMeaningExample
~NOT (prefix)~0b011010
&AND0xff & 0x0f
|OR0b1010 | 0x1
xorXOR5 xor 3
<< >>left / right shift1 << 8
0xff & 0x0f to decimal
5 xor 3
1 << 8

^ is power, not XOR — use xor. The words and / or are not bitwise operators; use & and |.

Probability operators

When at least one operand is a P(...) probability, the bitwise operators switch to probability math for independent events.

OperatorMeaningExample
~Complement~P(0.2)
&Intersection / ANDP(0.5) & P(0.3)
|Union / ORP(0.5) | P(0.3)
xorExactly oneP(0.5) xor P(0.3)

Without P(...), these remain integer bitwise operators.

Symbolic and complex arithmetic

The normal arithmetic operators also apply to symbolic and complex values.

2x^2 - 4x^2
(x + 1)*(x + 2)
(2 + 3i) * (1 - i)
i^2

Implicit multiplication works for numbers next to symbols (2x), but use an operator or a space between symbols (x*y or x y).

Conversion and assignment

OperatorMeaningExample
toconvert to a unit, number base, or color15 km to miles
percompound-unit divider60 mile per hour
inrender a time in a timezonenow in beijing
=assign a result to a labelsavings = 4500 - 1200
15 kilometers to miles
60 mile per hour to meter/second
savings = 4500 - 1200