You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/elixir/pages/Operators.md
+11-10Lines changed: 11 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,14 +14,15 @@ Operator
14
14
`*``/` | Left to right
15
15
`+``-` | Left to right
16
16
`++``--``..``<>` | Right to left
17
+
`^^^` | Left to right
17
18
`in``not in` | Left to right
18
-
`\|>``<<<``>>>``~>>``<<~``~>``<~``<~>``<\|>` | Left to right
19
+
`\|>``<<<``>>>``<<~``~>>``<~``~>``<~>``<\|>` | Left to right
19
20
`<``>``<=``>=` | Left to right
20
21
`==``!=``=~``===``!==` | Left to right
21
22
`&&``&&&``and` | Left to right
22
23
`\|\|``\|\|\|``or` | Left to right
23
-
`&` | Unary
24
24
`=` | Right to left
25
+
`&` | Unary
25
26
`=>` (valid syntax only inside `%{}`) | Right to left
26
27
`\|` | Right to left
27
28
`::` | Right to left
@@ -36,12 +37,12 @@ Elixir provides the following built-in comparison operators:
36
37
*[`===`](`Kernel.===/2`) - strict equality
37
38
*[`!=`](`Kernel.!=/2`) - inequality
38
39
*[`!==`](`Kernel.!==/2`) - strict inequality
39
-
*[`>`](`Kernel.>/2`) - greater than
40
40
*[`<`](`Kernel.</2`) - less than
41
-
*[`>=`](`Kernel.>=/2`) - greater than or equal
41
+
*[`>`](`Kernel.>/2`) - greater than
42
42
*[`<=`](`Kernel.<=/2`) - less than or equal
43
+
*[`>=`](`Kernel.>=/2`) - greater than or equal
43
44
44
-
The only difference between [`==`](`Kernel.==/2`) and [`===`](`Kernel.===/2`) is that [`===`](`Kernel.===/2`) is stricter when it comes to comparing integers and floats:
45
+
The only difference between [`==`](`Kernel.==/2`) and [`===`](`Kernel.===/2`) is that [`===`](`Kernel.===/2`) is strict when it comes to comparing integers and floats:
45
46
46
47
```elixir
47
48
iex>1==1.0
@@ -67,12 +68,12 @@ The reason we can compare different data types is pragmatism. Sorting algorithms
67
68
number < atom < reference < function < port < pid < tuple < map < list < bitstring
68
69
```
69
70
70
-
When comparing two numbers of different types (a number is either an integer or a float), a conversion to the type with greater precision will always occur, unless the comparison operator used is either `===` or `!==`. A float will be considered more precise than an integer, unless the float is greater/less than +/-9007199254740992.0, at which point all the significant figures of the float are to the left of the decimal point. This behavior exists so that the comparison of large numbers remains transitive.
71
+
When comparing two numbers of different types (a number being either an integer or a float), a conversion to the type with greater precision will always occur, unless the comparison operator used is either [`===`](`===/2`) or [`!==`](`!==/2`). A float will be considered more precise than an integer, unless the float is greater/less than +/-9007199254740992.0 respectively, at which point all the significant figures of the float are to the left of the decimal point. This behavior exists so that the comparison of large numbers remains transitive.
71
72
72
73
The collection types are compared using the following rules:
73
74
74
-
* Tuples are compared by size then element by element.
75
-
* Maps are compared by size then by keys in ascending term order then by values in key order. In the specific case of maps' key ordering, integers are always considered to be less than floats.
75
+
* Tuples are compared by size, then element by element.
76
+
* Maps are compared by size, then by keys in ascending term order, then by values in key order. In the specific case of maps' key ordering, integers are always considered to be less than floats.
76
77
* Lists are compared element by element.
77
78
* Bitstrings are compared byte by byte, incomplete bytes are compared bit by bit.
78
79
@@ -111,10 +112,10 @@ The following is a table of all the operators that Elixir is capable of parsing,
0 commit comments