Operations
Binary Operations
Arithmetic operations are fundamental mathematical operations available in any programming language.
Supported Types: integer types / float types / and structs
(for structures see Structures Implementations)
Table of Supported Binary Operations:
Operator | Name | Description | Limitations |
---|---|---|---|
+ | Add | Adds to constants together | Type Size Limits |
- | Minus | Subtracts one number from another | Type Size Limits |
* | Multiply | Multiplies two numbers | Type Size Limits |
/ | Divide | Divides one number by another | Type Size Limits, Division By Zero |
% | Modulus | Returns the remainder of the division | Type Size Limits, Division By Zero |
Example:
fn main() i32 {
println!("{}", 15 + 7);
println!("{}", 15 - 7);
println!("{}", 15 * 7);
println!("{}", 15 / 7);
println!("{}", 15 % 7);
return 0;
}
22
8
105
2
1
Unary Operations
Unary operations involve a single operand.
Supported Types: integer types / float types / structs
(for structures see Structures Implementations)
Table of Supported Unary Operations:
Operator | Name | Description | Limitations |
---|---|---|---|
- | Negative | Negates provided expression | Type Size Limits |
! | Not | Applies logical NOT to provided expression | Type Size Limits |
fn main() i32 {
println!("{}", -15);
println!("{}", !15);
return 0;
}
-15
-16
Boolean Operations
Comparison and logical operations return a boolean output.
Supported Types: integer types / float types / char / *char / structs
(for structures see Structures Implementations)
Table of Supported Boolean Operations:
Operator | Name | Description |
---|---|---|
> | Bigger Than | Returns true if LHS is bigger than RHS |
< | Less Than | Returns true if LHS is less than RHS |
== | Equals | Returns true if LHS equals RHS |
=> , >= | Equals Or Bigger | Returns true if LHS equals or bigger than RHS |
<= , =< | Equals Or Less | Returns true if LHS equals or less than RHS |
!= | Not Equals | Returns true if LHS not equals RHS |
&& | And | Returns true if LHS and RHS is true |
|| | Or | Returns true if LHS or RHS is true |
fn main() i32 {
println!("{}" 10 > 5);
println!("{}" 10 < 5);
println!("{}" 10 == 5);
println!("{}" 10 => 5);
println!("{}" 10 <= 5);
println!("{}" 10 != 5);
println!("{}" 10 == 0 && 5 == 0);
println!("{}" 10 == 0 || 5 == 0);
return 0;
}
true
false
false
true
false
true
false
false
Bitwise Operations
Bitwise operations manipulate the individual bits of numbers.
Supported Types: integer types
Table Of Supported Bitwise Operations:
Operator | Name | Description |
---|---|---|
& | And | Copies bit to the result if it exists in both operands |
| | Or | Copies bit to the result if it exists in either operand |
^ | Xor | Copies the bit if it set in one operand but not both |
<< | Left Shift | Shifts bits to left by provided index |
>> | Right Shift | Shifts bits to right by provided index |
fn main() i32 {
println!("{}", 100 & 25);
println!("{}", 10 & 100);
println!("{}", 20 ^ 10);
println!("{}", 1 << 2);
println!("{}", 10 >> 2);
return 0;
}
0
0
30
4
2