On 12/29/19 9:42 PM, David Mertz wrote:
On Sun, Dec 29, 2019, 9:23 PM Andrew BarnertHere it is. I could save a line by not using the 'else'. def total_order(x): if is_nan(x): return (math.copysign(1, x), x) else: return (0, x)This doesn’t give you IEEE total order. Under what circumstances would you prefer this to, say, Decimal.compare_total, which does?How does this differ from IEEE? I'm not being rhetorical, I really thought that was their order. But I haven't looked carefully.
IEEE total_order puts NaN as bigger than infinity, and -NaN as less than -inf.
One simple way to implement it is to convert the representaton to a 64 bit signed integer (not its value, but its representation) and if the sign bit is set, complement the bottom 63 bits (because floats are signed-magnitude). For pure python code, I don't know how hard it is to get the representation of a float as a 64 bit integer. In C or Assembly it is fairly easy as you can easily get around the type system, but I don't know python well enough to do it.
-- Richard Damon _______________________________________________ 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/N2RRRF37VSHVBGL35OA5AMBVG2E7IV2Q/ Code of Conduct: http://python.org/psf/codeofconduct/
