On Sun, Dec 29, 2019 at 10:18 PM Richard Damon <rich...@damon-family.org>
wrote:

> IEEE total_order puts NaN as bigger than infinity, and -NaN as less than
> -inf.
>

You mean like this?

>>> def total_order(x):
...     if math.isnan(x):
...         return (math.copysign(1, x), x)
...     return (0, x)
...
...
>>> nums = [1, 2, float('-inf'), float('nan'), float('inf'), float('-nan')]
>>> nums
[1, 2, -inf, nan, inf, nan]
>>> sorted(nums, key=total_order)
[nan, -inf, 1, 2, inf, nan]

It's a little weird that -nan has a repr of 'nan', but bracketing that, my
implementation is EXACTLY what you describe.


-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YQFFVCGJORK43ET4S7H3DO7HMN5CIKZL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to