I am trying to write functions for SortBy. Working example is
SortBy[{1, 2, 3, 4, 5, 6, 7, 8, 9}, (# - 4)^2 &]
The output is
{4, 3, 5, 2, 6, 1, 7, 8, 9}
However, if I try using Sin, Cos or Exp, the sorting fails. Examples are
SortBy[{1, 2, 3, 4, 5, 6, 7, 8, 9}, Sin[#] &]
SortBy[{1, 2, 3, 4, 5, 6, 7, 8, 9}, Cos[#] &]
SortBy[{1, 2, 3, 4, 5, 6, 7, 8, 9}, -Exp[#] &]
All return unsorted list
{1, 2, 3, 4, 5, 6, 7, 8, 9}
I would like to know what is wrong with using Sin, Cos or Exp in sorting.