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 than 10, so isless(5, 10) returns true. In the second case, 10 is not less than 5, so isless(10, 5) returns false. When both values are equal, isless returns false.
  • The second set of examples compares strings. "apple" comes before "banana" in lexicographic order, so isless("apple", "banana") returns true. In the second case, "banana" does not come before "apple", so isless("banana", "apple") returns false. When both strings are the same, isless returns false.
  • The third set of examples demonstrates the behavior with NaN. NaN is considered less than any other value, so isless(NaN, 10) returns true. However, 10 is not less than NaN, so isless(10, NaN) returns false.

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.

*Required Field
Details

Checking you are not a robot: