NaN comparisons - Call For Anecdotes

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jul 8 20:10:09 EDT 2014


On Tue, 08 Jul 2014 21:02:09 +0200, Anders J. Munch wrote:

> Steven D'Aprano wrote:
>> Oh, you've read the IEEE-754 standard, and that's what it says? "We're
>> going to specify this behaviour for NANs just to annoy people" perhaps?
> I was referring to the deliberate choice to enforce IEEE-754 rules in
> Python. There is no force of law that requires Python to do so.

There's no force of law that requires Python to enforce reflexivity on 
values where reflexivity does not apply, any more than Python should 
enforce total order on values which aren't ordered (such as complex 
numbers, or sets).

I'm sorry that you happened to (apparently) have a use-case where you 
simultaneously have to deal with NANs but not in a numeric context. But 
from the description of your problem, it seems to me that the obvious 
solution is not to deal with floats until as late as possible. That is, 
your current work-flow (if I have understood it correctly) is:

* gather unpacked floats from some device, as ints
* pack them into floats
* process them in some way which requires reflexivity
* (maybe) much later perform numeric calculations on them


It seems to me that the trivial work-around is:

* gather packed floats from some device, as ints
* process them *as ints* in some way which requires reflexivity
* unpack back into floats
* (maybe) much later perform numeric calculations on them


Although perhaps I don't understand your use-case.


-- 
Steven



More information about the Python-list mailing list