# Sort does not sort {0, -Pi/2} [duplicate]

Why is this list returned unchanged by Sort?

Sort[{0,-Pi/2}]


{0,-Pi/2}

While this list is returned reversed?

Sort[{0,-1}]

{-1,0}

Mathematica 11.0.0.0 MacOS

## marked as duplicate by J. M. is away♦Dec 10 '16 at 2:52

• also see (2729) – WReach Dec 3 '16 at 20:41

The Wolfram Documentation says:

Sort by default orders integers, rational, and approximate real numbers by their numerical values.

It also says:

Sort usually orders expressions by putting shorter ones first, and then comparing parts in a depth‐first manner.

The phrase -Pi/2 is an expression, so this second definition is applying. i.e. if we convert each expression to 'atomic'/numerical values first...

Sort[{0 // N, -Pi/2 // N}]
> {-1.5708, 0.}


... then it behaves as expected. You can force it to sort by numerical value by explicitly specifying the method used to compare entries for Sorting:

Sort[{0, -Pi/2}, Less]
> {-Pi/2, 0}

• This is no bug; see Sort bug in Mathematica 10?. – corey979 Dec 3 '16 at 20:04
• @corey979 - Thanks, edited my answer accordingly. – Myridium Dec 3 '16 at 20:19
• Thanks to all who replied. I don't personally think Sort ought to treat -Pi/2 as anything but a number by default, but now that I understand what is going on I will just always explicitly specify a sorting method such as Less. – Ralph Dratman Dec 6 '16 at 10:56
• SortBy[list, N] can be used as well. – J. M. is away Dec 10 '16 at 2:51