1## Operators
2
3An operator is a special symbol or phrase that you use to check, change, or combine values. For example, the addition operator (+) adds two numbers, as in **var i = 1 + 2**, and the logical AND operator (&&) combines two Boolean values, as in **if (flag1 && flag2)**.
4<br><br>
5Gravity supports most standard C operators and improves several capabilities to eliminate common coding errors. The assignment operator (=) does not return a value, to prevent it from being mistakenly used when the equal to operator (==) is intended. Gravity also provides two [range](types.md) operators as a shortcut for expressing a range of values.
6
7### Arithmetic Operators
8* Addition (+)
9* Subtraction (-)
10* Multiplication (*)
11* Division (/)
12* Remainder (%)
13
14```swift
15	var n1 = 1 + 2        // equals 3
16	var n2 = 5 - 3        // equals 2
17	var n3 = 2 * 3        // equals 6
18	var n4 = 10.0 / 2.5   // equals 4.0
19	var n5 = 9 % 4        // equals 1
20```
21
22### Assignment Operator
23The assignment operator = initialize or update a value:
24```swift
25	var a = 50;       // a = 50
26	var b = a;        // b = 50
27	var c = a * b;    // c = 50 * 50
28```
29Please note that contrary to many other programming languages, the assignment operator has no side effect, it means that it does not return any value.
30
31### Comparison Operators
32The comparison operators return a Bool value to indicate whether or not the statement is true:
33
34* Equal (==)
35* Not equal (!=)
36* Less than (<)
37* Less than or equal (<=)
38* Greater than (>)
39* Greater than or equal (>=)
40* Identical (===)
41* Not identical (!==)
42* Type check (is)
43* Pattern match (~=)
44
45```swift
46	1 == 1      // true because 1 is equal to 1
47	1 != 2      // true because 1 is not equal to 2
48	1 < 2       // true because 1 is less than 2
49	1 <= 1      // true because 1 is less than or equal to 1
50	1 > 2       // false because 1 is not greater than 2
51	1 >= 1      // true because 1 is greater than or equal to 1
52	1 === 1     // true because 1 is identical to 1 (same value and same class)
53	1 is Int    // true because 1 is of class Int
54```
55Gravity performs some conversions at runtime, so 1 == "1" but not 1 === '1'.
56
57### Logical Operators
58The comparison operators return a Bool value to indicate whether or not the statement is true:
59
60* Logical NOT (!)
61* Logical AND (&&)
62* Logical OR (||)
63
64
65```swift
66	!1          // false because 1 is true
67	1 && 0      // false because one of the two values is false
68	1 || 0      // true because one of the two values is true
69```
70In order to improve code readability the reserved keywords **not, and, or** has been introduces as an alisas to logical operators.
71
72### Bitwise Operators
73
74
75* Bitwise shift left (<<)
76* Bitwise shift right (>>)
77* Bitwise AND (&)
78* Bitwise OR (|)
79* Bitwise XOR (^)
80* Bitwise NOT or one's complement (~)
81
82
83```swift
84	var n = 0B00110011;
85	var n1 = n << 2             // equals 11001100
86	var n2 = n >> 2             // equals 00001100
87	var n3 = n & 0B00001111     // equals 00000011
88	var n4 = n | 0B00001111     // equals 00111111
89	var n5 = n ^ 0B00001111     // equals 00111100
90	var n6 = ~n;                // equals 11001100
91```
92
93### Compound Assignment Operators
94As a shortcut, assignment and operators can be combined together:
95
96* Multiply and assign (*=)
97* Divide and assign (/=)
98* Remainder and assign (%=)
99* Add and assign (+=)
100* Subtract and assign (-=)
101* Left bit shift and assign (<<=)
102* Right bit shift and assign (>>=)
103* Bitwise AND and assign (&=)
104* Bitwise XOR and assign (^=)
105* Bitwise OR and assign (|=)
106
107