@@ -88,7 +88,10 @@ should therefore also implement [`hash`](@ref).
88
88
Similar to [`==`](@ref), except for the treatment of floating point numbers
89
89
and of missing values. `isequal` treats all floating-point `NaN` values as equal
90
90
to each other, treats `-0.0` as unequal to `0.0`, and [`missing`](@ref) as equal
91
- to `missing`. Always returns a `Bool` value.
91
+ to `missing`. Always returns a `Bool` value. It can be assumed that two values which
92
+ are `===` are also `isequal`. `isequal` is an equivalance relation - it is reflexive
93
+ (`isequal(a, b)` implies `isequal(a, b)`) and transitive (`isequal(a, b)` and
94
+ `isequal(b, c)` implies `isequal(a, c)`).
92
95
93
96
# Implementation
94
97
The default implementation of `isequal` calls `==`, so a type that does not involve
@@ -98,8 +101,12 @@ floating-point values generally only needs to define `==`.
98
101
that `hash(x) == hash(y)`.
99
102
100
103
This typically means that types for which a custom `==` or `isequal` method exists must
101
- implement a corresponding `hash` method (and vice versa). Collections typically implement
102
- `isequal` by calling `isequal` recursively on all contents.
104
+ implement a corresponding [`hash`](@ref) method (and vice versa). Collections typically
105
+ implement `isequal` by calling `isequal` recursively on all contents.
106
+
107
+ Furthermore, `isequal` is linked with [`isless`](@ref), and they work together to
108
+ define a fixed total ordering, where exactly one of `isequal(x, y)`, `isless(x, y)`, or
109
+ `isless(y, x)` must be `true` (and the other two `false`).
103
110
104
111
Scalar types generally do not need to implement `isequal` separate from `==`, unless they
105
112
represent floating-point numbers amenable to a more efficient implementation than that
@@ -118,6 +125,12 @@ true
118
125
119
126
julia> isequal(0.0, -0.0)
120
127
false
128
+
129
+ julia> missing == missing
130
+ missing
131
+
132
+ julia> isequal(missing, missing)
133
+ true
121
134
```
122
135
"""
123
136
isequal (x, y) = x == y
@@ -132,8 +145,8 @@ isequal(x::AbstractFloat, y::Real ) = (isnan(x) & isnan(y)) | signequal(
132
145
"""
133
146
isless(x, y)
134
147
135
- Test whether `x` is less than `y`, according to a fixed total order.
136
- `isless` is not defined on all pairs of values `(x, y)`. However, if it
148
+ Test whether `x` is less than `y`, according to a fixed total order (defined together with
149
+ [`isequal`](@ref)). `isless` is not defined on all pairs of values `(x, y)`. However, if it
137
150
is defined, it is expected to satisfy the following:
138
151
- If `isless(x, y)` is defined, then so is `isless(y, x)` and `isequal(x, y)`,
139
152
and exactly one of those three yields `true`.
0 commit comments