On 2011-04-28, Chris Rebert <c...@rebertia.com> wrote: >> 2. What are the use cases for NaN? Looks like it gets used a lot as a >> numeric (float?) object with non-value. > > FWICT, it's useful in lower-level languages (which typically lack > exceptions and often lack nice ways of returning multiple values from > a function) as a convenient way of signaling a mathematical error.
When doing stuff involving process control systems, I found it very useful to use NaN to indicate "unknown/invalid". It propogates properly through calculations so that when you have an invalid input, all of the outputs that depend on it also go invalid. The other option is to use a value/status tuple everywhere you would normally use a float. But that falls over every time you need to use a library function that expects a float as an input and returns a float as an output. Since the sensors return a NaN when the value is unkown/invalid it seemed logical to continue with that paradigm in my Python code -- and it pretty much "just works". -- Grant Edwards grant.b.edwards Yow! If elected, Zippy at pledges to each and every gmail.com American a 55-year-old houseboy ... -- http://mail.python.org/mailman/listinfo/python-list