Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4262
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: NaN |
| Date | 2011-04-28 20:39 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <ipcjan$pv8$1@reader1.panix.com> (permalink) |
| References | <BANLkTine8W15e=SqNnJUStMNdy2GGA9pUA@mail.gmail.com> <mailman.945.1304010112.9059.python-list@python.org> |
On 2011-04-28, Chris Rebert <clp2@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 ...
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar
Re: NaN Chris Rebert <clp2@rebertia.com> - 2011-04-28 10:01 -0700
Re: NaN Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-28 18:59 +0000
Re: NaN Terry Reedy <tjreedy@udel.edu> - 2011-04-28 17:23 -0400
Re: NaN Grant Edwards <invalid@invalid.invalid> - 2011-04-28 21:56 +0000
Re: NaN Grant Edwards <invalid@invalid.invalid> - 2011-04-28 20:39 +0000
csiph-web