On Mon, Dec 30, 2019 at 2:58 AM Steven D'Aprano <[email protected]> wrote:
> Can you explain the scenario where somebody using median will want
> negative NANs to sort to the beginning, below -INF, and positive NANs to
> sort to the end, above +INF?
>
I can kinda-sorta provide a case. But overall, despite my whimsical
inclusion of an `ieee_total_order()` option in my sample implementation, I
don't really think this is something we should care about.
def my_results(it):
for x in it:
x_1 = func1_with_asymptotes(x)
x_2 = func2_with_asymptotes(x)
result = x_1 / x_2
yield result
median = statistics.median(my_results(my_iterator))
In concept, if some of my answers "fly off to +inf" and others "fly off to
-inf", then maybe I want to balance those and look at the "sensible" stuff
in the middle. But honestly, this feels more like an 'ignore' case.
I don't know whether 'inf/inf' is less than or greater than 42. The
operation in the Real domain might have a determinate answer (or even just
had I used float128 instead, for example). But as is, ignoring the nans is
the best I can do.
Moreover, it seems like Python does not preserve sign of the nans for these
operations. I would THINK that -inf/inf should be -nan. But nope.
Operations that get nans in Python just don't seem to respect the
"sensible" sign of them.
>>> math.copysign(1, float('nan'))
1.0
>>> math.copysign(1, float('-nan'))
-1.0
>>> math.copysign(1, float('-inf'))
-1.0
>>> math.copysign(1, float('-inf') / float('-inf'))
-1.0
>>> math.copysign(1, float('-inf') / float('inf'))
-1.0
>>> math.copysign(1, float('inf') / float('inf'))
-1.0
--
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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/JW3YEKKTEG66C6XV2DH7S62CDEJUY2UV/
Code of Conduct: http://python.org/psf/codeofconduct/