Sorting NaNs
Ben Bacarisse
ben.usenet at bsb.me.uk
Sat Jun 2 16:51:16 EDT 2018
Paul Rubin <no.email at nospam.invalid> writes:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
>> it too will mess up sorting in unpredictable ways. So don't do that.
>
> Hmm. GHCi 7.4.2:
>
> Prelude> let x = 0.0 / 0.0
> Prelude> x
> NaN
> Prelude> x==x
> False
> Prelude> :m Data.List
> Prelude Data.List> sort [1,2,x,4,5]
> [1.0,2.0,4.0,5.0,NaN]
But
Prelude Data.List> sort [1,x,2,4,5]
[2.0,4.0,5.0,NaN,1.0]
and
Prelude Data.List> sort [1,2,x,4,5,x]
[NaN,1.0,2.0,4.0,5.0,NaN]
and
Prelude Data.List> sort [1,2,x,4,5,x,1/0]
[1.0,2.0,4.0,Infinity,NaN,5.0,NaN]
> Not sure what to make of this but at least sorting seems to give a
> predictable result.
I suspect it is predictable if you know the algorithm, but I doubt it's
specified nor easily guessable from "outside".
(GHCi, version 8.0.2 here)
--
Ben.
More information about the Python-list
mailing list