[Python-Dev] Mixing float and Decimal -- thread reboot (original) (raw)

Mark Dickinson dickinsm at gmail.com
Wed Mar 24 17:22:29 CET 2010


On Wed, Mar 24, 2010 at 11:47 AM, Nick Coghlan

Interning NaN certainly seems like it should be sufficient to eliminate the set/dict membership weirdness.

That is, make it so that the first two lines of the following return True, while the latter two lines continue to return False:

float("nan") is float("nan") False dec("nan") is dec("nan") False float("nan") == float("nan") False dec("nan") == dec("nan") False

Yes; that could be done. Though as Steven points out, not all NaNs are equivalent (possibility of different payloads and different signs), so float nans with different underlying bit patterns, and Decimal nans with different string representations, would ideally be interned separately. For floats it might be possible to get away with pretending that there's only one nan. For decimal, I don't think that's true, since the payload and sign are part of the standard, and are very visible (e.g. in the repr of the nan).

The obvious way to do this nan interning for floats would be to put the interning code into PyFloat_FromDouble. I'm not sure whether this would be worth the cost in terms of added code (and possibly reduced performance, since the nan check would be done every time a float was returned), but I'd be willing to review a patch.

Mark



More information about the Python-Dev mailing list