@b0rk Here's an example in Python:

In [1]: sorted([2,4,6,float('NaN'),1,3,5])
Out[1]: [2, 4, 6, nan, 1, 3, 5]

So if you expected that sorting a sequence brings the smallest value to the beginning or the largest value to the end, NaNs will break those expectations. Also it's obvious when you create NaNs explicitly like this, but you can get them as results from some functions.

Some libraries have a "nansort" or similar that puts NaNs either first or last.

Follow

@jks @b0rk why is that?

I tried

In [1]: sorted([4, 3, 2, nan, 1])
Out[1]: [1, 2, 3, 4, nan]

but i also tried your example and I saw the exact behavior you described. what's going on?

@barraponto @b0rk It depends on the exact sequence of comparisons made by the sorting algorithm on the input. Comparing anything to NaN with any operator returns false, but the effect that has on the result depends on the context.

Sign in to participate in the conversation
Computer Fairies

Computer Fairies is a Mastodon instance that aims to be as queer, friendly and furry as possible. We welcome all kinds of computer fairies!