# Comparison function

 `<` `≤` `=` `≥` `>` `≠`

A comparison function is one of the six primitive dyadic scalar functions whose result on scalars is a Boolean determined by the numerical ordering of the two arguments. Comparisons are subject to comparison tolerance. The comparison functions can be subdivided into two equalities `=` `≠`, which depend only on whether the arguments are equal and not the ordering of unequal argument, and may be applied to characters, and four inequalities `<` `≤` `≥` `>`, which depend on ordering and may not be applied to characters.

The six comparison functions are Less Than (`<`), Less Than or Equal (`≤`), Equal to (`=`), Greater Than or Equal (`≥`), Greater Than (`>`), and Not Equal to (`≠`).

Because comparison functions have Boolean results on Boolean arguments (they always have Boolean results), they are Boolean functions. In fact, the majority of nontrivial dyadic Boolean functions are comparison functions.

## Classification

The result of a comparison function on real numbers is determined by their ordering, which falls into one of three possible cases: the left argument is smaller (more negative), the arguments are tolerantly equal, or the right argument is larger. A particular comparison function can thus be thought of as a choice of one Boolean value (0 or 1) for each of these three cases, which implies that there are eight total possibilities. Two of the possibilities—all 0 and all 1—are trivial and cannot be said to depend on the ordering of the arguments; they are not considered comparison functions. Every remaining possibility is one of the APL comparisons:

Function Results
< = >
`<` 1 0 0
`≤` 1 1 0
`=` 0 1 0
`≥` 0 1 1
`>` 0 0 1
`≠` 1 0 1

The traditional APL ordering of the comparison functions used above, which was used at least as early as APL\360, resembles a Gray code ordering of the values which define the comparison functions. Adjacent values differ by only a change of one bit, but the list is not a true Gray code because it excludes the all-0 and all-1 combinations.