Numeric Operators

Numeric operators generally follow C styles.

Unary Operators

OperatorDescription
+positive
-negative

#![allow(unused)]
fn main() {
let number = -5;

number = -5 - +5;
}

Binary Operators

OperatorDescriptionIntegers only
+plus
-minus
*multiply
/divide (integer division if acting on integer types)
%modulo (remainder)
~power
&bit-wise AndYes
|bit-wise OrYes
^bit-wise XorYes
<<left bit-shiftYes
>>right bit-shiftYes

#![allow(unused)]
fn main() {
let x = (1 + 2) * (6 - 4) / 2;  // arithmetic, with parentheses

let reminder = 42 % 10;         // modulo

let power = 42 ~ 2;             // power (i64 and f64 only)

let left_shifted = 42 << 3;     // left shift

let right_shifted = 42 >> 3;    // right shift

let bit_op = 42 | 99;           // bit masking
}