Skip to content

Operators

All integer operands to an operator must share a type. Integer results retain that type and its width-limited bit pattern.

FamilyOperationsRules
Arithmeticadd sub mulWrap modulo 2^width
Bitwiseand or xor notResults are masked to the declared width
Unsigned divisionudiv uremRequire unsigned integers
Signed divisionsdiv sremRequire signed integers; quotient truncates toward zero and remainder has the dividend’s sign
Shifts and rotationsshl lshr ashr rotl rotrCount is an unsigned pattern modulo the width
Comparisonseq ne ult ule ugt uge slt sle sgt sgeReturn bool
SelectionselectTakes a bool condition and two equal-typed alternatives

Division and remainder by zero trap. Signed MIN / -1 and MIN % -1 also trap.

ashr sign-extends the top bit even when its integer type is unsigned. Rotations wrap within the declared width.

eq and ne compare equal-typed bit patterns and also accept bool. Unsigned ordering comparisons require unsigned integers; signed ordering comparisons require signed integers.

Arguments are evaluated left-to-right and eagerly. Both alternatives to select are evaluated, so an unchosen expression can still trap.

not has one operand, select has three, and every other operation has two.