isless
isless(x, y)
Test whether x
is less than y
, according to a canonical total order. Values that are normally unordered, such as NaN
, are ordered in an arbitrary but consistent fashion. This is the default comparison used by sort
. Non-numeric types with a canonical total order should implement this function. Numeric types only need to implement it if they have special values such as NaN
.
Examples
julia> isless(5, 10)
true
julia> isless(10, 5)
false
julia> isless(5, 5)
false
julia> isless("apple", "banana")
true
julia> isless("banana", "apple")
false
julia> isless("apple", "apple")
false
julia> isless(NaN, 10)
true
julia> isless(10, NaN)
false
The isless
function compares two values x
and y
and returns true
if x
is less than y
according to the canonical total order. It is used to determine the relative ordering of values.
In the examples above:
- The first set of examples compares numeric values. In the first case,
5
is less than10
, soisless(5, 10)
returnstrue
. In the second case,10
is not less than5
, soisless(10, 5)
returnsfalse
. When both values are equal,isless
returnsfalse
. - The second set of examples compares strings.
"apple"
comes before"banana"
in lexicographic order, soisless("apple", "banana")
returnstrue
. In the second case,"banana"
does not come before"apple"
, soisless("banana", "apple")
returnsfalse
. When both strings are the same,isless
returnsfalse
. - The third set of examples demonstrates the behavior with
NaN
.NaN
is considered less than any other value, soisless(NaN, 10)
returnstrue
. However,10
is not less thanNaN
, soisless(10, NaN)
returnsfalse
.
Note that the isless
function is the default comparison used by sort
to order values. It is important for non-numeric types with a canonical total order to implement this function. Numeric types only need to implement it if they have special values such as NaN
.
See Also
digits, inf, isdigit, iseven, isfinite, isless, islower, isnumber, isodd, isprime, isqrt, issorted, issubnormal, isxdigit, nan,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.