-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators.rs
More file actions
44 lines (34 loc) · 1.36 KB
/
Operators.rs
File metadata and controls
44 lines (34 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
Trying Out Different ways of Using Operator and my conclusions in the comments
*/
fn main(){
// normal Addition / Substraction
// Note :
// If data type of number not mention then its taken automatically
// If data type is mentioned as unsigned then operator overflow needs to be taken care by user
// i.e 1u32 - 2 will result in overflow as answer will be
// -1u32 ( Not possible as unsigned data type cant be negative)
println!(" 1 + 2 = {}", 1i32 + 2);
println!(" 1 - 2 = {}", 1i32 - 2);
// Normal Multiplication and Division
// Note :
// Scientific Notation is considered float in nature in Rust
println!(" 1e4 * 29 = {}", 1e4 * 29f32);
println!(" 1 / 2 = {}", 1 / 2);
// Normal Logical Operator
// Note :
// Scientific Notation is considered float in nature in Rust
// Anything which is not a bool givens error when used within logical operators
println!(" true && false = {}", true && false);
println!(" true || false = {}", true || false);
println!(" true ^ false = {}", true ^ false);
println!(" true ^ true = {}", true ^ true);
// Bitwise Operators
println!(" 10 & 2 = {}", 10 & 2);
println!(" 14 | 1 = {}", 14 | 1);
println!(" 24 ^ 13 = {}", 24 ^ 13);
println!(" 1 << 4 = {}", 1 << 4);
println!(" 5 >> 1 = {}", 5 >> 1);
println!(" 43 << 2 = {}", 43 << 2);
println!(" 3 >> 7 = {}", 3 >> 7);
}