Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Operators

[!NOTE] Do not confuse operators with operations

There are several operators which can be used to combine expressions with each other:

OperatorType1st Operand12nd OperandResult TypeDescription
!unaryB-sameInversion
-unaryI Q A T-sameNegation
+binaryI Q A TcompatiblesameAddition
-binaryI Q A TcompatiblesameSubtraction
*binaryI Q A TcompatiblesameMultiplication
/binaryI Q A TcompatiblesameDivision
^binaryI QIntegerlike 1stPower
&binaryBBooleanBooleanLogical AND
|binaryBBooleanBooleanLogical OR
>binaryI QcompatibleBooleanGreater than
>=binaryI QcompatibleBooleanGreater or equal
<binaryI QcompatibleBooleanLess than
<=binaryI QcompatibleBooleanLess or equal
==binaryI Q A TcompatibleBooleanEqual
!=binaryI Q A TcompatibleBooleanNot equal

Here are some examples of each operator:

test

use std::debug::assert_eq; // used for testing

assert_eq([-5, 0 - 5]); // Negation
assert_eq([5 + 6, 11]); // Addition
assert_eq([5 - 6, -1]); // Subtraction
assert_eq([5 * 6, 30]); // Multiplication
assert_eq([5 / 6, 0.83333333333333333]); // Division
assert_eq([5 ^ 6, 15625]); // Power
assert_eq([true & false, false]); // Logical AND
assert_eq([true | false, true]); // Logical OR
assert_eq([5 > 6, false]); // Greater than
assert_eq([5 >= 6, false]); // Greater or equal
assert_eq([5 < 6, true]); // Less than
assert_eq([5 <= 6, true]); // Less or equal
assert_eq([5 == 6, false]); // Equal
assert_eq([5 != 6, true]); // Not equal

Operators & Arrays

Some of the operators listed above can be used with arrays too. There result then is a new array with each value processed with the operator and the second operand.

See Array Operators for more information.


  1. B = Boolean, I = Integer, Q = Quantity, A = Array, T = Tuple