On Mon, Dec 30, 2019 at 06:55:56PM -0500, David Mertz wrote: > > The order he generates is very close to the IEEE total order, the > difference are: > > > > 1) It doesn't seperate -0 for +0, which shouldn't matter for most > > applications. > > > 2) It doesn't provide an order between NaNs, but unless you are taking > > special measures to distinguish the NaNs anyway, that doesn't really matter. > > > > And it also doesn’t distinguish equal but distinct-bit-pattern subnormal > > values. > > > > This is more in the category of "things that definitely do not matter", but > I had forgotten about subnomal floating-point values. How does IEEE > totalOrder mandate ordering those vs. equivalent normal numbers?
Subnormals (or denormalised numbers) are ordered in ascending order, like norms, and slot in between zero and the normalised numbers. If we enumerate floats in the order of their bitwise representation, every float maps to an integer in the range 0 to 2**64-1 inclusive: 0x0000000000000000 zero 0x0000000000000001...0x000FFFFFFFFFFFFF positive denormalised numbers 0x0010000000000000...0x7FEFFFFFFFFFFFFF positive normalised numbers 0x7FF0000000000000 positive infinity 0x7FF0000000000001...0x7FF7FFFFFFFFFFFF signalling NANs with sign-bit cleared 0x7FF8000000000000...0x7FFFFFFFFFFFFFFF quiet NANs with sign-bit cleared 0x8000000000000000 negative zero 0x8000000000000001...0x800FFFFFFFFFFFFF negative denormalised numbers 0x8010000000000000...0xFFEFFFFFFFFFFFFF negative normalised numbers 0xFFF0000000000000 negative infinity 0xFFF0000000000001...0xFFF7FFFFFFFFFFFF signalling NANs with sign-bit set 0xFFF8000000000000...0xFFFFFFFFFFFFFFFF quiet NANs with sign-bit set The total order reverses the order of the floats from 0x8000000000000000 onwards, giving us the numbers in ascending numeric order (aside from the NANs, which are shoved to the ends): quiet NANs with sign-bit set signalling NANs with sign-bit set negative infinity negative normalised numbers negative denormalised numbers negative zero zero positive denormalised numbers positive normalised numbers positive infinity signalling NANs with sign-bit cleared quiet NANs with sign-bit cleared I have been tediously pedantic in referring to NANs with the sign-bit set or cleared rather than "negative NANs" and "positive NANs", since strictly speaking the standard doesn't offer an interpretation of the sign-bit when applied to NANs. Or at least the original version of the standard didn't. I believe there have been at least two revisions since the original, it is possible they have added an interpretation. Strictly speaking, the order of signalling and quiet NANs is not specified by the original version of the standard. Most platforms follow the order above, but a few may reverse the interpretation of the "signalling bit" (bit 51, counting from 0 on the right). I don't know if Python runs on any of those platforms. -- Steven _______________________________________________ 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/WBRPO5YK7M3QVTSFXB7FWUE36QP2FD4X/ Code of Conduct: http://python.org/psf/codeofconduct/