summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Boyer <fboyer@users.noreply.github.com>2016-09-21 17:07:01 -0400
committerAndrea Leopardi <an.leopardi@gmail.com>2016-09-21 23:07:01 +0200
commit06083a995f882025d03e535781c2c65ea4aa5463 (patch)
treef4d34cd4cb45f67512f41ca37d631dd183ae914f
parenta3e96ee24192ab1aed2c4b4ce7e3e93fd9e7e1a7 (diff)
downloadelixir-06083a995f882025d03e535781c2c65ea4aa5463.tar.gz
Clarify some of the subtleties linked to term ordering in the docs (#5238)
-rw-r--r--lib/elixir/pages/Operators.md10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/elixir/pages/Operators.md b/lib/elixir/pages/Operators.md
index 4d6fa1ecb..47f2370ae 100644
--- a/lib/elixir/pages/Operators.md
+++ b/lib/elixir/pages/Operators.md
@@ -64,9 +64,17 @@ true
The reason we can compare different data types is pragmatism. Sorting algorithms don’t need to worry about different data types in order to sort. For reference, the overall sorting order is defined below:
```
-number < atom < reference < functions < port < pid < tuple < maps < list < bitstring
+number < atom < reference < functions < port < pid < tuple < map < list < bitstring
```
+When comparing two numbers of different types (a number is either an integer or a float), a conversion to the type with lesser 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.
+
+The collection types are compared using the following rules:
+
+* Tuples are compared by size then element by element.
+* 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.
+* Lists are compared element by element.
+
## Custom and overridden operators
### Defining custom operators